我目前正在重构整个黄瓜测试负载以使用“页面对象”模式,但是使用 RSpec 匹配器时我遇到了很多问题。
我现有的步骤如下:
Then /^I should (not )?see the following alerts:$/ do |negate, alerts|
expectation = negate ? :should_not : :should
within(ALERT_TABLE_ID) do
alerts.hashes.each do |alert|
page.send(expectation, have_content(alert["Original ID"]))
end
end
end
我重构的步骤是:
Then /^I should (not )?see the following alerts:$/ do |negate, alerts|
expectation = negate ? :should_not : :should
@alert_reporting_panel = AlertReportingPanel.new(Capybara.current_session)
@alert_reporting_panel.verify_contents expectation, alerts
end
我的面板对象是:
class AlertReportingPanel
def initialize(session)
@session = session
end
def verify_contents(expectation, alerts)
@session.within(ALERT_TABLE_ID) do
alerts.hashes.each do |alert|
@session.send(expectation, have_content(alert["Original ID"]))
end
end
end
end
不幸的是,我得到undefined method 'have_contents' for #<AlertReportingPanel:0x3f0faf8> (NoMethodError)
.
我尝试添加require 'rspec'
到类的顶部,并尝试完全限定该have-content
方法: Capybara::RSpecMatchers::HaveMatcher.have_content
,但我只是得到uninitialized constant Capybara::RSpecMatchers (NameError)
.
我对 Ruby 还是很陌生,我确信这很容易解决……但我似乎无法为自己解决这个问题。
请帮忙。谢谢你。