views:

186

answers:

3

Hi there, 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

+1  A: 

Avoid using the ID, instead list the name of the group as that will never change.

Ryan Bigg
+1  A: 

I would exchange the ID for 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"
Jonas Söderström
A: 

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

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

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!!!

VinTem