私は現在、キュウリとそれを適切に利用する方法を学ぼうとしています。ベストプラクティスを検索するときは、古い方法のほとんどが説明されていますが、良いガイドは見つかりませんでした。新しい方法について読みましたが、ベストプラクティスにいくつか問題があります。
以下は私が取り組んできたいくつかの基本的なキュウリのシナリオです。
Scenario: Unsuccessful login
Given a user has an account
When the user tries to log in with invalid information
Then the user should see an log in error message
Scenario: Successful login
Given a user has an account
When the user logs in
Then the user should see an log in success message
And the user should see a sign out link
Scenario: Successful logout
Given a signed in user
Then the user logs out
And the user should see an log out success message
これでいいのかな?「私が訪問する」または「ユーザーが訪問する」または「彼が訪問する」と書くべきかどうか問題があります基本的に何が好ましいですか?
第二に、私は次のことをどのように定式化すべきか疑問に思います。
Scenario: Visit profile of user
Given a user
And a second user
When the user visit the user profile
Then the user should see the name of the user
Scenario: Visit profile of another user
Given a user
And a second user
When the user visit the second users profile
Then the user should see the name of the second user
これは私がまとめたものですが、最善の方法ではないと感じています。ステップ定義ファイルで問題が発生しました。シナリオを処理するためのステップをどのように定義しますか?もっと一般的なものを書きたかったのですが、それは本当に不可能なのかもしれません。@second_user属性が必要ですか、それとも何を提案しますか?
def user
@user ||= FactoryGirl.create :user
end
Given /^a signed in user$/ do
user
sign_in(@user.email, @user.password)
end
Given /^a user has an account$/ do
user
end
When /^the user logs in$/ do
sign_in(@user.email, @user.password)
end
When /^the user logs out$/ do
click_link ('Sign out')
end
When /^the user tries to log in with invalid information$/ do
sign_in("incorrect-email", "incorrect-password")
end
Then /^the user should see a sign out link$/ do
page.should have_link('Sign out')
end
Then /^the user should see an log in success message$/ do
should have_success_message('Signed in successfully.')
end
When /^the user should see an log out success message$/ do
should have_success_message('Signed out successfully.')
end
Then /^the user should see an log in error message$/ do
should have_error_message('Invalid email or password.')
end
手伝ってくれてありがとう!