对于两种不同的情况,我几乎都有类似的步骤。只有一个步骤是不同的。有没有任何优选的方式来重复使用步骤。如何在黄瓜测试中重复使用步骤
@no-database-cleaner
Feature: Managing users parent child relationships
In order to use Login portal
I want to create parent child relationships
Scenario: Creating a child user with new ar_id
Given I am on the homepage
When I attempt to sign in with following user account:
| email address | password |
| [email protected] | password |
Then I should see "[email protected]" message on page
When I follow "All Child Users"
Then I should see "Add Sub Child"
When I click "Add Sub Child"
Then I should see "Child Sub User"
And I fill in "Email" with "[email protected]"
And I select "Medium" from "filter_level"
And I choose "abc_id_yes"
When I press "Create Child User"
Then I should see "Child User is successfully created."
And appropriate records should get created for the child user for new abc_id
Scenario: Creating a child user with abc_id with value zero
Given I am on the homepage
When I attempt to sign in with following user account:
| email address | password |
| [email protected] | password |
Then I should see "[email protected]" message on page
When I follow "All Child Users"
Then I should see "Add Sub Child"
When I click "Add Sub Child"
Then I should see "Child Sub User"
And I fill in "Email" with "[email protected]"
And I select "Medium" from "filter_level"
And I choose "abc_id_no"
When I press "Create Child User"
Then I should see "Child User is successfully created."
And appropriate records should get created for the child user for default abc_id
一个步骤是在这里改变是
而且我选择 “abc_id_yes” 和其余的都是一样的。我如何在不同的场景中重现这些步骤。
以下是步骤定义。同样的问题,我在两个不同的步骤中使用相同的代码,除了一行。
Then(/^appropriate records should get created for the child user for new abc_id$/) do
parent_user = User.find_by_email("[email protected]")
user = User.find_by_email("[email protected]")
user.default_filter_level.should be_true
user.abc_id.should be_true
user.parent_id.should == parent_user.id
filter = Filter.find_by_user_id(user.id)
filter.user_id.should == user.id
filter.abc_id.should be_true
filter.account_id.should == user.account.id
end
Then(/^appropriate records should get created for the child user for default abc_id$/) do
parent_user = User.find_by_email("[email protected]")
user = User.find_by_email("[email protected]")
user.default_filter_level.should be_true
user.abc_id.should == 0 ##this is different
user.parent_id.should == parent_user.id
filter = Filter.find_by_user_id(user.id)
filter.user_id.should == user.id
filter.abc_id.should == 0 ##this is different
filter.account_id.should == user.account.id
end
太好了。 :)我怎么能做到这一点user.abc_id.should == 0?我geting错误说不能比较零。 – user588324
没问题。刚开始另一个问题,我会尽力帮助你。更多的人会看到它,你会得到更好的帮助,它不会改变当前的问题。 – fontno