无法调用“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