"dummy = create (: user)"를 호출하여 사용자를 작성할 수 없습니다. 몇 시간 동안 앞뒤로 갔다. 내가 같이 spec_helper.rb에이 추가Factory_Girl + RSpec : 작성시 정의되지 않은 메소드 (: 사용자)
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
: 나는 user_spec.rb에 FactoryGirl를 호출하는 방법을
FactoryGirl.define do
factory :user do
email '[email protected]'
password 'chucknorris'
name 'luis mendes'
end
end
이것은 :
/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입니다 지시 :RSpec.configure do |config|
# Include FactoryGirl so we can use 'create' instead of 'FactoryGirl.create'
config.include FactoryGirl::Syntax::Methods
end
와우, 그게 효과가있어. 하지만 왜? 이유가 뭐야? 그것이 내부와 외부의 차이점은 무엇입니까? 감사! – GigaBass
@GigaBass : FactoryGirl 소스 코드를 너무 가깝게 보지는 않았지만 테스트 (spec) 내에서만 해당 메소드 ('create','attributes_for' 등)가 노출되어 있다고 추측합니다. 테스트 파일에 어디에 두 었는지 알 수 없으므로 그 방법을 사용할 수 없습니다. 이해가 되니? 대답이 맞다면 동의하십시오. –