【发布时间】:2014-09-17 23:44:37
【问题描述】:
我刚刚开始使用 RSpec(和 Capybara)进行功能规范。我正在测试我的 ActiveAdmin 仪表板,我想检查所有面板是否都有一个订单表,如此 sn-p 所示:
feature 'admin dashboard', type: :feature do
def panels
page.all('.column .panel')
end
describe 'all panels' do
it 'have an orders table' do
expect(panels).to all(have_css('table.orders tbody'))
end
end
end
我在单元测试中经常使用 all 匹配器,但在包装 Capybara 的 have_css 匹配器时它似乎不起作用,因为我收到以下错误:
Failure/Error: expect(panels).to all(have_css('table.orders tbody'))
TypeError:
no implicit conversion of Capybara::RackTest::CSSHandlers into String
我的假设是否正确,即 RSpec 的内置 all 匹配器也应该与其他匹配器一起使用?
注意:在这种情况下,我使用 describe 和 it 而不是 feature 和 scenario,因为我正在测试输出而不是用户交互场景(请参阅我的 other question)。
【问题讨论】:
-
不幸的是,RSpec 的
all和 Capybara 的all之间存在冲突,请参阅 Capybara Issue 1396。你打电话的all实际上是Capybara的all。 -
哦,你是对的@JustinKo。你有什么解决方法可以推荐吗?
标签: ruby-on-rails rspec capybara rspec-rails