1

我是 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。

有谁知道如何解决这个问题?

谢谢

4

3 回答 3

2

避免使用 ID,而是列出组的名称,因为它永远不会改变。

于 2009-10-21T20:34:08.013 回答
2

我会用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"
于 2009-10-27T14:57:07.650 回答
0

所以我找到了一种简单的方法来测试关联。

如果我说我在场景中只有一个组,那么当我在该步骤中时,我可以创建具有特定 ID 的组,如下所示

g = Group.create(:name => "Group 1", :id => 1)

然后我只需要测试我的页面显示具有 group_id = 1 的用户并且不显示具有 group_id <> 1 的用户。

就这么简单!!!

于 2009-11-02T00:28:37.783 回答