【问题标题】:Completing Capybara page should have content test完成 Capybara 页面应该有内容测试
【发布时间】:2015-04-10 14:45:47
【问题描述】:

我在理解我需要遵循什么流程才能通过此测试时遇到了一点问题。我知道该页面应该有内容,并且我在规范中有相应的数据。我现在不确定我需要遵循哪些步骤才能通过测试。那么如何将测试笔记传递到页面来完成这个测试呢?我在 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" 

【问题讨论】:

    标签: ruby-on-rails capybara haml


    【解决方案1】:

    提交表单后,您会被重定向到编辑页面还是显示页面?在显示页面中,我没有看到您在任何地方显示注释。

    在这些情况下,我通常会打电话给 Capybara's

    save_and_open_page
    

    如果这样做,您可以查看页面上实际包含的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多