我将以两种方式改变这种状况。 第一,网络步骤已用更新的库克文加以解释。 诸如“我以“真主党”填满“真主党”等步骤现在被阻止。 其次,对数据库中的用户数量进行测试,说明全貌。 你们要知道,用户是你创造的用户,意思是你最终添加的同一名称和任何其他特性。 为了处理这些步骤,我发现自己撰写的情景如下:
Scenario: Creating a user
When I create the following users:
| name |
| Chandler Bing |
| Some Other Guy |
Then I should have the following users:
| name |
| Chandler Bing |
| Some Other Guy |
Then in your step definitions, you would do what the web steps were doing:
Given /^I create the following users:$/ do |table|
table.hashes.each do |row|
visit new_user_path
fill_in Name , with: row[ name ]
click_button Create User
end
end
Then /^I should have the following users:$/ do |table|
# Ensure users with same name are taken into account
table.hashes.size.should == User.count
table.hashes.each do |row|
user = User.find_by_name(row[ name ])
user.should_not be_nil
end
end
有几个关于这种做法的说明:
- It allows your steps to be reusable. If you want to test the negative path and try adding an invalid user you wouldn t have to write a new step.
- Less boilerplate code in the feature file. If you have a stakeholder, it should be easier for them to read the steps.
- You will actually be learning capybara, which I know I personally took for granted with the web steps.
- You can add a bunch of users with much less code.