Ruby on rails 如何在步骤定义中访问创建的factory bot值?

Ruby on rails 如何在步骤定义中访问创建的factory bot值?,ruby-on-rails,ruby,ruby-on-rails-3,cucumber,factory-bot,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)

我不熟悉工厂机器人和黄瓜, 如何在步骤定义中使用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

您需要在
给定的
块中创建用户

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

谢谢你,伙计,但是“找不到可见字段”signuser\u email“未被禁用(Capybara::ElementNotFound)”会显示上述错误。请帮助任何人我是女孩,而不是男孩:)您是否在您的视图中有一个带有姓名、id或标签文本“signuser\u email”的输入字段
fill_in
方法通过字段名称、id或标签文本工作,因此您需要使用正确的方法。对不起,在view/registration/new.html.erb中使用fill_in“email”时,Vasilisa会显示:Signuser.last.email,上面显示相同的错误