我知道这是可能的使用黄瓜通过捕获可选组(见tip 3这里),我有它在萝卜工作,但我不喜欢的解决方案。DRY向上萝卜步骤定义
我想消除多个步骤,只是彼此的积极/消极。
因此,而不是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
有没有更好的方法来做到这一点?