如何在黄瓜步骤定义中访问创建的工厂机器人值?

时间:2018-01-31 10:30:38

标签: ruby-on-rails ruby ruby-on-rails-3 cucumber factory-bot

我是工厂机器人和黄瓜的新手, 如何在步骤定义中使用factory_bot访问创建的记录? test / factories.rb

FactoryBot.define do
  factory :signuser do
    email  'abcd1123@test.xyz'
    password   'test123'
    password_confirmation 'test123'
  end
end


#In console
FactoryBot.create(:signuser)

#features/test_step.rb

When (/^enter exists details for Register$/)do
#I want to access email "abcd1123@test.xyz" and password "test123" here in textfield
end

1 个答案:

答案 0 :(得分:0)

您需要在Given

中创建用户
Given /^a user with email "(.+)"$/ do |email|
  FactoryBot.create(:user, email: 'user')
end

之后,您可以在步骤中使用此用户

When (/^enter exists details for Register$/)do
  fill_in 'user_email', with: User.last.email
end