题
我是铁杆和黄瓜的新手,我正在尝试测试以下场景
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中的所有用户,但我不知道如何使用黄瓜进行测试,因为每次运行测试时,我的组名为Group 1都有所不同标识。
有谁知道如何解决这个问题?
感谢名单
解决方案 3
所以我发现了一种测试关联的简单方法。
如果我说我在场景中只有一个小组,当我在这一步时,我可以创建具有特定ID的小组
g = Group.create(:name => "Group 1", :id => 1)
然后我只需要测试我的页面显示具有group_id = 1的用户,并且不显示具有group_id的用户<!> lt; <!> gt; 1。
这很容易!!!
其他提示
避免使用ID,而是列出组永远不会改变的名称。
我会为 group_name
交换 IDBackground:
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