找不到水豚元素 haml 按钮
Capybara element not found haml button
我有一个诊断规范,我认为我在使用规范和视图文件之间的语言时存在一些不一致。但是我无法解决问题。测试如下
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button "Save"
page.should have_content("Saved")
page.should have_content("test notes")
结束
观点是
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag @diagnostic.data["Save"], method: :put, data: { confirm: "Are you sure?" }
失败是
1) /admin/diagnostics updates a diagnostic report
Failure/Error: click_button "Save"
Capybara::ElementNotFound:
Unable to find button "Save"
我一直在尝试更改视图文件中的语法,以便提交标签成为一个按钮。这是因为我认为问题是使用标签而不是按钮。但是,我无法使用 haml 语法成功完成此操作。
Rails 有 built in support 用于本地化和国际化。无需自己滚动。
# app/views/diagnostics/edit.haml.erb
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag I18n.t('.save'), method: :put, data: { confirm: "Are you sure?" }
翻译存储在位于 config/locales
的 YAML 文件中。
# config/locales/en.yml
en:
diagnostics:
edit:
save: 'Save'
您还可以在规范中使用您的翻译:
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button I18n.t('diagnostics.edit.save') # Note that we need full path
page.should have_content(I18n.t('diagnostics.edit.save'))
page.should have_content("test notes")
end
我有一个诊断规范,我认为我在使用规范和视图文件之间的语言时存在一些不一致。但是我无法解决问题。测试如下
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button "Save"
page.should have_content("Saved")
page.should have_content("test notes")
结束
观点是
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag @diagnostic.data["Save"], method: :put, data: { confirm: "Are you sure?" }
失败是
1) /admin/diagnostics updates a diagnostic report
Failure/Error: click_button "Save"
Capybara::ElementNotFound:
Unable to find button "Save"
我一直在尝试更改视图文件中的语法,以便提交标签成为一个按钮。这是因为我认为问题是使用标签而不是按钮。但是,我无法使用 haml 语法成功完成此操作。
Rails 有 built in support 用于本地化和国际化。无需自己滚动。
# app/views/diagnostics/edit.haml.erb
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag I18n.t('.save'), method: :put, data: { confirm: "Are you sure?" }
翻译存储在位于 config/locales
的 YAML 文件中。
# config/locales/en.yml
en:
diagnostics:
edit:
save: 'Save'
您还可以在规范中使用您的翻译:
it "updates a diagnostic report" do
diagnostic_info = FG.create(:diagnostic_info)
diagnostic_info.save!
visit edit_admin_diagnostic_path(diagnostic_info)
fill_in 'diagnostic_info_notes', with: "test notes"
click_button I18n.t('diagnostics.edit.save') # Note that we need full path
page.should have_content(I18n.t('diagnostics.edit.save'))
page.should have_content("test notes")
end