레일 컨트롤러의 테스트를 실행 중이고 이상한 동작이 있습니다. FactoryGirl (build, create)의 두 메서드가 다른 컨트롤러의 rspec 테스트 파일 중 하나에서 예상대로 작동하는 동안 create 메서드를 호출 할 때마다이 새로운 테스트 파일이 ArgumentError를 올립니다. 인수가 잘못되었습니다 (1, 예상 0). . 다른에FactoryGirl ArgumentError : 잘못된 인수 수 (주어진 1, 예상 된 0)
require 'faker'
FactoryGirl.define do
factory :user do
email { Faker::Internet.email }
password "password"
password_confirmation "password"
end
end
같은 라인 :이이 FactoryGirl 정의가 같은 모습입니다
BTW 고안 사용하고
describe DoctorsController, type: :controller do
let(:user) { create(:user) }
: 파일이 같이 방법
이입니다 컨트롤러는 매력처럼 작동합니다.
describe ClinicsController, type: :controller do
context 'when signed in' do
let(:clinic) { build(:clinic) }
let(:user) { create(:user) }
before(:each) { sign_in user }
왜 이런 일이 발생하는지 알고 싶습니다. 사전에 감사
전체 예제 :
require 'rails_helper'
describe DoctorsController, type: :controller do
let(:doctor) { build(:doctor) }
let(:params) { doctor.attributes }
let(:user) { create(:user) }
it 'should be an instance of a secure controller' do
expect(DoctorsController.new).to be_a(SecureApplicationController)
end
describe '#create' do
subject(:create) { post :create, doctor: params }
context 'when signed in' do
before(:each) { sign_in user }
context 'on success' do
it 'should redirect with notification' do
expect(create).to redirect_to(doctors_path)
expect(flash[:notice]).to eq('Doctor creado satisfactoriamente')
end
it 'should create a new doctor' do
expect{ create }.to change { Doctor.count }.by(1)
end
it 'should assign existing clinics when creating a doctor' do
clinics = [create(:clinic), create(:clinic)]
post :create, doctor: params, clinics: clinics.map(&:id)
end
end
context 'on failure' do
subject(:create) { post :create,
doctor: attributes_for(:doctor, name: nil) }
it 'should redirect with notification' do
expect(create).to redirect_to(new_doctor_path)
expect(flash[:notice]).to eq('Error creando el doctor')
end
end
end
end
end
스택 트레이스 : 당신이
subject(:create)
와 create
을 덮어 쓸 것 같은
Failures:
1) DoctorsController#create when signed in on success should redirect with notification
Failure/Error: let(:user) { create(:user) }
ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/controllers/doctors_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
# ./spec/controllers/doctors_controller_spec.rb:17:in `block (4 levels) in <top (required)>'
2) DoctorsController#create when signed in on success should create a new doctor
Failure/Error: let(:user) { create(:user) }
ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/controllers/doctors_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
# ./spec/controllers/doctors_controller_spec.rb:17:in `block (4 levels) in <top (required)>'
3) DoctorsController#create when signed in on success should assign existing clinics when creating a doctor
Failure/Error: let(:user) { create(:user) }
ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/controllers/doctors_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
# ./spec/controllers/doctors_controller_spec.rb:17:in `block (4 levels) in <top (required)>'
4) DoctorsController#create when signed in on failure should redirect with notification
Failure/Error: let(:user) { create(:user) }
ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/controllers/doctors_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
# ./spec/controllers/doctors_controller_spec.rb:17:in `block (4 levels) in <top (required)>'
Finished in 0.0092 seconds (files took 5.95 seconds to load)
5 examples, 4 failures
가 실패한 예와 전체 오류를 보여줄 수 있습니까? – EJ2015
'let (: user) {FactoryGirl.create (: user)}'와 시도하십시오. – Babar
@Babar 이미 그랬다 : ( –