2012-11-21 8 views
8

私は現在、キュウリとそれを適切に活用する方法を学びたいと考えています。ベストプラクティスを検索する際には、古い方法のほとんどが記述されており、実際には良いガイドが見つかりませんでした。 私はそれを行う新しい方法について読んだが、ベストプラクティスにはいくつかの問題がある。キュウリをレールに書き込む方法(ベストプラクティス)。機能と手順

以下は私が取り組んでいる基本的なキュウリのシナリオです。

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 

私を助けてくれてありがとう!

答えて

4

私は「私が訪れる」または「ユーザーの訪問」または「彼が訪れた」と書くべきである場合、問題があります。

私は「ユーザーが訪問したとき」のようなものを使用すると、「彼は誰ですか」と考え続ける必要がないので、より一般的になり、読みやすくなります。テストを読んでいるなら、本当に重要なことは、あなたが混乱しないように、すべてのファイルのコンベンションに固執することです。

@second_userの作成に関する2番目の質問については、データ設定と同じくらいこのシナリオの一部ではないため、データを処理する最良の方法だと思いますセットアップはpickle with cucumberを使用することですが、基本的には変数を変数として保持しなくても、キュウリのモデルを作成することができます。great cast on RailsCastが多く説明しています。

ので、私は、あなたが

When /^the user visits the profile of (.+)$/ do |username| 
    visit("/#{username}") # I am assuming here usernames are unique and the profile url is "/:username" 
end 
+0

感謝を定義することができピクルス

Scenario: Visit profile of another user Given a user exists with name: "Mike", username: "mike" And a signed in user When the user visits the profile of "mike" Then the user should see 'Mike' 

を使用してこれを行うだろう。モデルとキュウリの特徴の間にいくつかの結合を追加する方法はないようです。私の希望は、usernameのような情報を持っていないということでした。私の機能では、周りに良い方法はないようです。 –

+1

あなたは歓迎ですが、結合があれば間違っているとは思えません。それがテストを書く理由です。たとえば、ユーザーモデルを変更してユーザー名フィールドを持たないと、このシナリオは失敗するでしょうモデルを修正するか、シナリオを変更します。 – Khaled

関連する問題