オプションのグループをキャプチャすることでキュウリを使用してこれが可能であることは知っています (ヒント 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
これを行うより良い方法はありますか?