代码之家  ›  专栏  ›  技术社区  ›  thitemple

测试与黄瓜的相关性

  •  1
  • thitemple  · 技术社区  · 16 年前

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

    因此,在我的用户控制器的索引操作中,我列出了组_id中的所有用户,但我不知道如何使用cucumber来测试,因为每次运行测试时,我的组group1都有一个不同的id。

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

    塔克斯

    3 回复  |  直到 16 年前
        1
  •  2
  •   Ryan Bigg Andrés Bonilla    16 年前

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

        2
  •  2
  •   Jonas Söderström    16 年前

    我会把钱换掉 对于

    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"
    
        3
  •  0
  •   thitemple    16 年前

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

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

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

    就这么简单!!!