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

1 に答える 1

4

「私が訪問する」または「ユーザーが訪問する」または「彼が訪問する」と書くべきかどうか問題があります基本的に何が好ましいですか?

「ユーザーがアクセスしたとき」のようなものを使用すると、「彼は誰ですか?」と考え続ける必要がないため、より一般的で読みやすくなると思います。テストを読んでいる場合、本当に重要なのは、混乱しないように、すべてのファイルで何らかの規則に従うことです。

@second_userの作成に関する2番目の質問については、このユーザーはデータ設定であるほどシナリオの一部ではないため、そうすべきではないと思います。データ設定を処理する最善の方法は、を使用することだと思います。きゅうりのピクルス、それは基本的にあなたがあなたと一緒にそれらを変数として保持する必要なしにあなたのきゅうりでモデルを作成することを可能にします、多くを説明するRailsCastの素晴らしいキャストがあります。

だから私はピクルスを使ってこれをします

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'

次に、定義することができます

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
于 2012-11-22T22:26:37.357 に答える