【发布时间】:2012-06-27 21:55:14
【问题描述】:
我知道这可以通过捕获可选组来使用 cucumber(请参阅此处的 tip 3),并且我可以在萝卜中使用它,但我不喜欢这个解决方案。
我正在尝试消除只是彼此正面/负面的多个步骤。
所以不是像这样的 2 个步骤:
step "I should see :content in the footer" do |content|
within(".footer-main") do
page.should(have_selector("h3", text: content))
end
end
step "I should not see :content in the footer" do |content|
within(".footer-main") do
page.should_not(have_selector("h3", text: content))
end
end
我可以这样做:
step "I should :not_text see :content in the footer" do |not_text, content|
within(".footer-main") do
not_text.blank? ? page.should(have_selector("h3", text: content)) : page.should_not(have_selector("h3", text: content))
end
end
这很好用,但我真正不喜欢的是我必须在积极的情况下放空括号,如下所示:
Scenario: User should see Company in the footer
When I visit the "root page"
Then I should "" see "Company" in the footer
有没有更好的方法来做到这一点?
【问题讨论】:
标签: ruby-on-rails testing rspec cucumber dry