【发布时间】:2023-04-05 14:58:02
【问题描述】:
不能调用“dummy = create(:user)”来创建用户。来回走了几个小时。
/home/parreirat/backend-clone/Passworks/spec/models/user_spec.rb:15:in `block (2 levels) in <top (required)>': undefined method `create' for #<Class:0xbcdc1d8> (NoMethodError)"
这是工厂,users.rb:
FactoryGirl.define do
factory :user do
email 'heheheheheheh@gmail.com'
password 'chucknorris'
name 'luis mendes'
end
end
这就是我在 user_spec.rb 中调用 FactoryGirl 的方式:
require 'spec_helper'
describe 'User system:' do
context 'registration/login:' do
it 'should have no users registered initially.' do
expect(User.count).to eq(0)
end
it 'should not be logged on initially.' do
expect(@current_user).to eq(nil)
end
dummy = create(:user)
it 'should have a single registered user.' do
expect(User.count).to eq(1)
end
end
end
我按照说明将其添加到 spec_helper.rb 中:
RSpec.configure do |config|
# Include FactoryGirl so we can use 'create' instead of 'FactoryGirl.create'
config.include FactoryGirl::Syntax::Methods
end
【问题讨论】:
标签: ruby-on-rails ruby rspec factory-bot