私は現在、キュウリとそれを適切に活用する方法を学びたいと考えています。ベストプラクティスを検索する際には、古い方法のほとんどが記述されており、実際には良いガイドが見つかりませんでした。 私はそれを行う新しい方法について読んだが、ベストプラクティスにはいくつかの問題がある。キュウリをレールに書き込む方法(ベストプラクティス)。機能と手順
以下は私が取り組んでいる基本的なキュウリのシナリオです。
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
私を助けてくれてありがとう!
感謝を定義することができピクルス
を使用してこれを行うだろう。モデルとキュウリの特徴の間にいくつかの結合を追加する方法はないようです。私の希望は、usernameのような情報を持っていないということでした。私の機能では、周りに良い方法はないようです。 –
あなたは歓迎ですが、結合があれば間違っているとは思えません。それがテストを書く理由です。たとえば、ユーザーモデルを変更してユーザー名フィールドを持たないと、このシナリオは失敗するでしょうモデルを修正するか、シナリオを変更します。 – Khaled