質問
レールとキュウリは初めてで、次のシナリオをテストしようとしています
Background:
Given I have a Group named Group 1
And I go to the list of groups
And I have the following users records
| name | description | group_id |
| user 1 | | 1 |
| user 2 | | 1 |
When I follow Details for Group 1
Scenario: List users from group
Then I should see "user 1"
And I should see "user 2"
したがって、ユーザーコントローラーのインデックスアクションでは、group_idからすべてのユーザーを一覧表示しますが、テストを実行するたびにグループ1という名前のグループは異なるため、キュウリを使用してこれをテストする方法がわかりませんid。
これを解決する方法を知っている人はいますか?
ありがとう
解決 3
だから、関連付けをテストする簡単な方法を見つけました。
「シナリオにグループが1つしかない」と言った場合、そのステップにいるとき、このような特定のIDでグループを作成できます
g = Group.create(:name => "Group 1", :id => 1)
その後、ページをテストするだけで、group_id = 1のユーザーが表示され、group_idのユーザーは表示されません<!> lt; <!> gt; 1。
そのように簡単!!!
他のヒント
IDの使用を避け、代わりにグループの名前をリストします。変更されないためです。
ID を group_name と交換します
Background:
Given I have a group called "Ruby users"
And I go to the list of groups
And I have the following users records
| name | description | group_name |
| "user 1" | | "Ruby users" |
| "user 2" | | "Ruby users" |
When I follow Details for Group "Ruby users"
Scenario: List users from group "Ruby users"
Then I should see "user 1"
And I should see "user 2"
所属していません StackOverflow