问题描述
根据水豚的自述文件:
page.should_not have_xpath('a')
page.should have_no_xpath('a')
但是,当尝试这种方法时,这似乎并不正确。当使用capybara-webkit时,这似乎很好用:
However, when trying this out, that does not appear to be true. This seems to work fine when using capybara-webkit:
visit dashboard_accounting_reports_path
click_link 'Delete'
page.should_not have_css('#reports .report')
但是使用poltergeist时,通常会失败,这似乎是在使用 #has_css?
,实际上并不会等待给定的元素消失:
But when using poltergeist, it often fails with this, which seems to say it's using #has_css?
under the covers, which won't actually wait for the given element to disappear:
Failure/Error: page.should_not have_css('#reports .report')
expected #has_css?("#reports .report") to return false, got true
如果我将断言更改为这样,似乎每次都成功:
If I change the assertion to read like this instead, it seems to succeed every time:
page.should have_no_css('#reports .report')
我疯了吗,或者这是Poltergeist中的错误吗?我正在使用PhantomJS 1.8.2,poltergeist 1.1.0和capybara 2.0.2。
Am I crazy, or is this a bug in poltergeist? I'm using PhantomJS 1.8.2, poltergeist 1.1.0, and capybara 2.0.2.
这是 should_not have_css 示例:
这是应该有的一个
示例:
推荐答案
我认为我发现了问题-我一直在要求我的spec_helper.rb中的 capybara / dsl而不是 capybara / rspec,因此该规格中未包含Capybara :: RSpecMatchers发出的正确的 should_not
行为和错误消息
I think I found the problem - I had been requiring 'capybara/dsl' in my spec_helper.rb instead of 'capybara/rspec', so the proper should_not
behavior and error messages from Capybara::RSpecMatchers were not included in that spec.
编辑:原来,如果您需要 rspec / rails,它将自动为您带来正确的水豚东西。但是,如果您使用的是一些非标准的RSpec内容,例如在请求规范中使用Capybara,则仍然需要在其中手动添加Capybara :: DSL和Capybara :: RSpecMatchers。另请参阅:
It turns out if you're requiring 'rspec/rails', it will automatically bring in the correct capybara stuff for you. But if you're using some non-standard RSpec stuff, like using Capybara in request specs, you'll still need to manually include Capybara::DSL and Capybara::RSpecMatchers there. See also: https://github.com/rspec/rspec-rails/blob/master/Capybara.md
这篇关于Poltergeist是否正确支持水豚的Should_not RSpec匹配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!