完成 Capybara 页面应该有内容测试
Completing Capybara page should have content test
我在理解要通过此测试需要遵循什么流程时遇到了一些问题。我知道该页面应该有内容,并且我在规范中有相应的数据。我现在不确定我需要遵循哪些步骤才能让我的测试通过。那么如何将测试笔记传递到页面来完成这个测试呢?我在 HAML 工作。
测试:
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("Successfully updated")
page.should have_content("test notes")
end
编辑视图
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag 'Save', method: :put, data: { confirm: "Are you sure?" }
.field
= link_to 'show', admin_diagnostics_path
显示视图
.field
= label_tag :message
= label_tag @diagnostic.data["message"] || :none
.field
= label_tag :appVersion
= label_tag @diagnostic.data["appVersion"] || :none
.field
= label_tag :device
= label_tag do
%pre= JSON.pretty_generate(@diagnostic.data["device"])
.field
= label_tag :screenshot
- if @diagnostic.data["screenshot"]
= image_tag @diagnostic.data["screenshot"]
- else
= label_tag :none
.field
= label_tag :localStorage
-if @diagnostic.data["localStorage"]
= label_tag do
%pre= JSON.pretty_generate(@diagnostic.data["localStorage"])
= link_to 'Delete', admin_diagnostic_path(@diagnostic), method: :delete, data: { confirm: 'really?' }
= link_to 'Edit', edit_admin_diagnostic_path
错误
Failure/Error: page.should have_content("test notes")
expected to find text "test notes"
提交表单后,您是被重定向到编辑页面还是显示页面?在显示页面中,我没有看到您在任何地方显示注释。
在这些情况下,我通常会调用 Capybara 的
save_and_open_page
如果这样做,您可以看到页面上的实际内容。
我在理解要通过此测试需要遵循什么流程时遇到了一些问题。我知道该页面应该有内容,并且我在规范中有相应的数据。我现在不确定我需要遵循哪些步骤才能让我的测试通过。那么如何将测试笔记传递到页面来完成这个测试呢?我在 HAML 工作。
测试:
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("Successfully updated")
page.should have_content("test notes")
end
编辑视图
.field
= label_tag :notes
= f.text_field "notes"
= submit_tag 'Save', method: :put, data: { confirm: "Are you sure?" }
.field
= link_to 'show', admin_diagnostics_path
显示视图
.field
= label_tag :message
= label_tag @diagnostic.data["message"] || :none
.field
= label_tag :appVersion
= label_tag @diagnostic.data["appVersion"] || :none
.field
= label_tag :device
= label_tag do
%pre= JSON.pretty_generate(@diagnostic.data["device"])
.field
= label_tag :screenshot
- if @diagnostic.data["screenshot"]
= image_tag @diagnostic.data["screenshot"]
- else
= label_tag :none
.field
= label_tag :localStorage
-if @diagnostic.data["localStorage"]
= label_tag do
%pre= JSON.pretty_generate(@diagnostic.data["localStorage"])
= link_to 'Delete', admin_diagnostic_path(@diagnostic), method: :delete, data: { confirm: 'really?' }
= link_to 'Edit', edit_admin_diagnostic_path
错误
Failure/Error: page.should have_content("test notes")
expected to find text "test notes"
提交表单后,您是被重定向到编辑页面还是显示页面?在显示页面中,我没有看到您在任何地方显示注释。
在这些情况下,我通常会调用 Capybara 的
save_and_open_page
如果这样做,您可以看到页面上的实际内容。