黄瓜+ capybara = has_content?(cucumber + capybara = has_content? returns true everytime)
我正在使用以下内容:
minitest 5.3.5 cucumber 1.3.15 capybara 2.3.0 capybara_minitest_spec 1.0.2 rails 4.1.1 cucumber-rails 1.4.1和我的黄瓜/水豚代码
Then(/^I should see "(.*?)"$/) do |string| page.has_content?(string) end使用任何字符串,它在页面上是独立的还是不返回true。 我试过使用capybara_minitest_spec gem,我的代码变成了
Then(/^I should see "(.*?)"$/) do |string| page.must_have_content(string) end然后我有错误
Then I should see "Test" # features/step_definitions/pages_steps.rb:9 undefined method `assert_page_has_content' for nil:NilClass (NoMethodError) (eval):4:in `must_have_content' ./features/step_definitions/pages_steps.rb:10:in `/^I should see "(.*?)"$/' features/can_access_home.feature:7:in `Then I should see "Test"'这么奇怪。 使用save_and_open_page,我看到我的页面没有任何问题。 你能帮我解决一下吗?
PS:我使用minitest而不是rspec
i'm using following:
minitest 5.3.5 cucumber 1.3.15 capybara 2.3.0 capybara_minitest_spec 1.0.2 rails 4.1.1 cucumber-rails 1.4.1and my cucumber/capybara code
Then(/^I should see "(.*?)"$/) do |string| page.has_content?(string) endwith any string, independent is it on the page or not returns true. I've tried to use capybara_minitest_spec gem and my code becomes
Then(/^I should see "(.*?)"$/) do |string| page.must_have_content(string) endthen i've got error
Then I should see "Test" # features/step_definitions/pages_steps.rb:9 undefined method `assert_page_has_content' for nil:NilClass (NoMethodError) (eval):4:in `must_have_content' ./features/step_definitions/pages_steps.rb:10:in `/^I should see "(.*?)"$/' features/can_access_home.feature:7:in `Then I should see "Test"'So strange. With save_and_open_page i see my page without any problems. Could you help me please to fix it?
PS: i'm using minitest but not rspec
最满意答案
Then(/^I should see "(.*?)"$/) do |string| page.has_content?(string) end这不是断言,这是一个返回布尔值的方法。 断言抛出异常,这是导致测试失败的原因。
如果要断言字符串的存在,则必须使用:
Then(/^I should see "(.*?)"$/) do |string| assert page.has_content?("Home#index") endpage.must_have_content实际上做同样的事情,除了你的错误说page是零。
I've fixed problem with following
Then(/^I should see "(.*?)"$/) do |string| assert page.has_content?(string) end更多推荐
发布评论