黄瓜+ capybara = has

编程入门 行业动态 更新时间:2024-10-26 22:28:26
黄瓜+ 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.1

and my cucumber/capybara code

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

with 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) end

then 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") end

page.must_have_content实际上做同样的事情,除了你的错误说page是零。

I've fixed problem with following

Then(/^I should see "(.*?)"$/) do |string| assert page.has_content?(string) end

更多推荐

本文发布于:2023-07-05 14:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038485.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:黄瓜   capybara

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!