使用Factory_girl学习黄瓜测试,我有一个公认的n00b问题:
如何在Cucumber中使用Factory_Girl步骤定义?
例如,我对用户控制器“显示”视图进行了以下测试:
Scenario: View Profile Page
Given a user exists
When I am on the user show page #NOT SURE HOW TO MAKE THIS WORK
Then I should see "Your Profile" in the selector "h2"
And I should see "Edit Profile" in a link
And I should see "Delete Account" in a link
和'用户'工厂设置如下:
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "UserNumber#{n}" }
email { "#{:name}@fakemail.com" }
phone 8457975800
end
end
我已确保将require "factory_girl/step_definitions"
行添加到我的env.rb文件中,该文件正常。
问题在于我不知道如何为使用'user'Factory的When I am on the user show page
部分编写步骤定义?我在这里缺少什么?
答案 0 :(得分:1)
知道了,抱歉n00bness
When /^I am on the user show page$/ do
user = Factory.create(:user)
visit "/users/#{user.id}"
end
答案 1 :(得分:0)
http://robots.thoughtbot.com/post/10983530140/getting-sequential-a-look-into-a-factory-girl 看看这个工厂女孩反模式。看来甚至工厂女作家对你的问题都没有更好的答案。