测试与黄瓜的关联
我是 Rails 和 Cucumber 的新手,我正在尝试测试以下场景
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 中的所有用户,但我不知道如何使用 Cucumber 进行测试,因为每次运行测试时,名为 Group 1 的组都有不同的 ID。
有谁知道如何解决这个问题?
谢谢
I'm new to rails and cucumber and I'm trying to test the following scenario
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"
So, in the index action of my users controller I list all the users from the group_id, but I don't know how to test this using cucumber, because every time I run the test my group named Group 1 has a different id.
Does anyone know how to solve this?
Thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以我找到了一种简单的方法来测试关联。
如果我说我在场景中只有一个组,那么当我执行该步骤时,我可以创建具有特定 id 的组,如下所示
然后我只需测试我的页面显示具有 group_id = 1 的用户并且不要不显示具有 group_id <> 的用户1.
就这么简单!!!
So I found out an easy way to test associations.
If I say that a I have only one group in scenario, when I am on that step I can create the group with the specific id like this
Then I just have to test the my page shows the users that has a group_id = 1 and don't show the users that has the group_id <> 1.
Easy as that!!!
我会将 ID 换成 group_name
I would exchange the ID for group_name
避免使用 ID,而是列出组的名称,因为它永远不会改变。
Avoid using the ID, instead list the name of the group as that will never change.