23

Cucumber と Capybara を使用して、文字列がページに存在しないことを確認する方法はありますか?

たとえば、このステップの反対をどのように記述しますか。

Then /^I should see "(.*?)"$/ do |arg1|
  page.should have_content(arg1)
end

が存在する場合、これは合格ですarg1

が見つかった場合に失敗するステップをどのように記述しますか?arg1

4

5 に答える 5

34

http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers#has_no_text%3F-instance_method

カピバラにはhas_no_contentマッチャーがあります。だからあなたは書くことができます

  Then /^I should not see "(.*?)"$/ do |arg1|
    page.should have_no_content(arg1)
  end
于 2012-08-16T03:20:02.920 に答える
16

Rspec 3.4 では現在 (2016 年)、これはコンテンツがないことをテストするための推奨される方法です。

expect(page).not_to have_content(arg1)
于 2016-02-25T23:43:45.480 に答える
8

もう少し読みやすくしたい場合は、should_notを使用することもできます。

Then /^I should not see "(.*?)"$/ do |arg1|
  page.should_not have_content(arg1)
end

詳細情報: https://www.relishapp.com/rspec/rspec-expectations/docs

于 2012-10-26T18:34:06.543 に答える
4

現在、次を使用できます。

Then /^I not see "(.*?)"$/ do |arg1|
  expect(page).to have_no_content(arg1)
end

ページ内にコンテンツが見つかった場合、テストは赤色になります。

于 2014-12-19T13:44:30.857 に答える
-4

ああ、待って、私はそれを理解しました。これは機能します:

Then /^I should see "(.*?)"$/ do |arg1|
  page.has_content?(arg1) == false
end
于 2012-08-16T02:59:25.013 に答える