呼唤 RSpec 睡觉

Calling RSpec sleep

我现在正在编写一个功能测试,它正在尝试测试一个编辑操作。这对我来说有点奇怪,因为当我正常使用 运行 RSpec 时,它没有看到我期望的内容,但是当我使用 save_and_open_page 命令时,它表明我所期望的实际上存在于浏览器中.我认为这是一个硒问题,但我是 rspec 的新手,我不确定。有人建议我使用 "Sleep" 或 "Pause",但我不确定如何使用这些方法,而且我找不到任何好的文档。我想知道是否有人可以告诉我在我当前的代码中使用它的有效方法?

测试

require "rails_helper"

RSpec.feature "Edit 'Bounce Back' Message", :type => :feature do
given!(:group) { Group.create!(name: "Group A", response: "You are now    subscribed for updates") }

scenario "Staff can see the response messages" do
visit "/groups"

  user = FactoryGirl.create(:user)
  fill_in "Email", with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in"

  expect(page).to have_content("You are now subscribed for updates")
  expect(page).to have_content("Group a")
 end
scenario "Staff can edit the response messages" do
  visit "/groups/#{group.id}/edit"

  user = FactoryGirl.create(:user)
  fill_in "Email", with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in"

  expect(page).to have_content("You have now subscribed for updates")
 end
end 

我希望这些信息足够了,如果您需要更多信息,请告诉我。谢谢你! 我也试过使用 rspec_wait 但它仍然发送错误。在这里

 <div class="container text-center">
  <div class="row">
  <div class="col-lg-8 col-lg-offset-2 well">
     <%= form_for @group do |form| %>
       <div class="form-group">
         <%= form.label :body, "Edit The Response:", class: "message_label"%>
         <%= form.text_field :response, class: "form-control", placeholder: "New things are happening!" %>
       </div>
       <%= form.submit "Update", class: "btn btn-primary" %>
    <% end %>
  </div>
 </div>
</div>

这个问题目前接受的答案是错误的。不需要将 rspec-wait 与 Capybara 匹配器一起使用,因为它们已经内置了 waiting/retrying 行为。您可以调整它们 wait/rety 使用 Capybara.default_max_wait_time 或传递 wait/rety 的时间长度=14=] 匹配器的选项。

通过阅读问题和所附图片,我认为 "Staff can see the response messages" 测试通过了,但 "Staff can edit the response messages" 测试失败了。如果是这样,那很可能是因为在编辑页面上 "You have now subscribed for updates" 字符串实际上是字段(文本框等)的内容,而不是页面的文本内容。 have_content 用于检查页面上的文本节点内容,要测试具有给定值的字段,您可以使用类似

的内容
expect(page).to have_field('Response', with: 'You have now subscribed for updates')

假设有一个标签与文本为 "Response" 的字段关联,如果没有,您可以传递字段的 ID、名称等,或者从 Capybara 2.7 开始,您可以传递 nil 和它将只查找具有给定值的任何字段 - 完全取决于您需要测试的内容。

expect(page).to have_field(nil, with: 'You have now subscribed for updates')