모의 order
을 생성하는 Factory
이 있습니다. 공장에서 order
을 만들 때 after_create
콜백에 필요한 3 가지 모델을 만들기 위해 공장에서 before_create
이 있습니다. 다음 공장 코드 (I이 조금 지저분 실현,하지만 내가 현재 가지고 내 문제를 해결하기 위해 시도) 다음과 같습니다rspec에서 테스트에서 생성 된 팩터를 찾을 수 없습니다.
FactoryGirl.define do
factory :order, :class => Spree::Order do
# associations:
association(:user, :factory => :user)
association(:bill_address, :factory => :address)
association(:ship_address, :factory => :address)
completed_at nil
bill_address_id nil
ship_address_id nil
email '[email protected]'
before(:create) do |order|
country = Spree::Country.find_by_id(214).blank? ? create(:country, :id => 214) : Spree::Country.find_by_id(214)
state = create(:state, :country => country, :country_id => country.id)
country.states = [state]
FactoryGirl.create(:address, :id => 1072978592,:state => state, :country => country) if Spree::Address.find_by_id(1072978592).blank?
end
end
end
을하지만, 난 내 테스트를 실행할 때, 내가 점점 계속 다음과 같은 오류가 발생했습니다.
1) Spree::Calculator::DefaultTax#compute when given an order when no line items match the tax category should be 0
Failure/Error: let!(:order) { create(:order) }
ActiveRecord::RecordInvalid:
Validation failed: Country can't be blank
# ./spec/models/calculator/default_tax_spec.rb:8:in `block (2 levels) in <top (required)>'
국가를 비워 둘 수없는 유효성 검사 오류가 발생했습니다. 내가 뭘 잘못하고 있는지 모르겠다. 저는 주소와 주에서 국가를 적절하게 할당하려고합니다.
rspec 2.13.0,
factory_girl_rails 4.2.1 (factory _girl 4.2.0),
ruby 1.9.3,
rails 3.2.13
spree 1.2.4
'let (: order) {Spree :: Order.create}'가 느리게로드되어서 문제가 아닌지 확인하기 위해 let let (: order) {Spree :: Order.create }. 또한 이것이 작동하지 않으면 전체 spec 파일과 주소 팩토리를 게시 할 수 있습니다. – fontno
느낌표를 추가하려고 시도했지만 아무 것도하지 않았습니다. – Zyren
네, 죄송합니다. 테스트 환경에서 rails 콘솔을 사용하여 연결을 수동으로 수행하고 재생할 수 있습니다. 어쩌면 당신은 잘못 된 것을 찾을 수 있습니다. 'rails console test' – fontno