2

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

これを行うより良い方法はありますか?

4

3 に答える 3

0

AFAIK - これはうまくいくはずです:

step "I should (not )? 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

Scenario: User should not see City in the footer
    When I visit the "root page"
    Then I should not see "City" in the footer
于 2014-03-07T12:04:19.263 に答える
0

次のステップ定義を使用してはどうでしょうか。

step "I :should_or_not_text see :content in the footer" do |should_or_not_text, content|
  within(".footer-main") do
    should_or_not_text == "should" ? 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
于 2012-10-27T17:59:28.923 に答える