未定义的方法'create'规范. [英] undefined method `create' rails spec.
本文介绍了未定义的方法'create'规范.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了factory girl并尝试将其用于规格.
I have installed factory girl and trying to use it with spec.
scenario 'User signs in' do
create :user, email: 'test@example.com', password: 'testpassword'
visit '/users/sign_in'
fill_in 'Email', with: 'test@example.com'
fill_in 'Password', with: 'testpassword'
end
,并且出现以下错误.
and I am getting the following error.
Failure/Error: create :user, email: 'test@example.com', password: 'testpassword'
NoMethodError:
undefined method `create' for #<RSpec::ExampleGroups::UserSignIn:0x007fe6324816b8>
推荐答案
我们可以在 factory_bot的文档:
1)创建文件/spec/support/factory_bot.rb :
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
2)编辑/spec/rails_helper.rb 以加载 support 目录中的所有文件:
2) Edit /spec/rails_helper.rb to load all files in support directory:
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
这篇关于未定义的方法'create'规范.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文