「一致しません」を返すページがあります。またはモデル オブジェクト名の 1 つ。
Cucumber でテストする最良の方法は何ですか? rand をGiven
ステップでスタブする必要がありますか、それとも次のようなものを提供する必要がありますpage has either a or b
か? またはrand
、シナリオ アウトライン パラメーターにパラメーターを指定し、このパラメーターをGiven
ステップで使用し、2 番目のアウトライン列を使用して結果を確認する必要がありますか?
更新: cookies
クッキー モンスターの最高の伝統におけるコントローラーの例:
cookie_controller.rb
def random_cookie
if rand(5) == 0 do
cookie = Cookie.offset(rand(Cookie.count)).first
response = "You got 10 free #{cookie.type} cookies for your purchase!"
else
response = "Sorry, no cookies left :'("
end
respond_to do |format|
format.json { render json: { response: response } }
end
find_cookie.feature
Scenario: Looking for cookie
When I click "find"
Then I should see "You got 10 free" or "Sorry, no cookies left :'("
ステップはどのようにThen I should see "You got 10 free" or "Sorry, no cookies left :'("
見えますか?私は次のようなものを試しました
(page.should have_content "You got 10 free") || (page.should have_content "Sorry, no cookies left :'("
しかし、うまくいきませんでした。