Tôi có một cái gì đó điều khiển đặc tả như thế nàyFactory Girl phương pháp xác định cho nil: NilClass
describe :bizzaro_controller do
let(:credit_card_account) { FactoryGirl.build :credit_card_account }
it "doesn't blow up with just the stub" do
CreditCardAccount.stub(:new).and_return(credit_card_account)
end
it "doesn't blow up" do
credit_card_account
CreditCardAccount.stub(:new).and_return(credit_card_account)
end
end
nào dẫn đến điều này:
bizzaro_controller
doesn't blow up with just the stub (FAILED - 1)
doesn't blow up
Failures:
1) bizzaro_controller doesn't blow up
Failure/Error: let(:credit_card_account) { FactoryGirl.build :credit_card_account }
NoMethodError:
undefined method `exp_month=' for nil:NilClass
# ./spec/controllers/user/bizzareo_controller_spec.rb:5:in `block (2 levels) in <top (required)>'
# ./spec/controllers/user/bizzareo_controller_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.23631 seconds
2 examples, 1 failure
nhà máy thẻ tín dụng của tôi trông như thế này:
FactoryGirl.define do
factory :credit_card_account do
exp_month 10
exp_year 2075
number '3'
end
end
Tài khoản thẻ tín dụng của tôi là một mô hình ActiveRecord :: Base trống
=> CreditCardAccount(id: integer, exp_month: integer, exp_year: integer, number: string)
phiên bản
0 HAL:0 work/complex_finance % bundle show rails rspec-rails factory_girl
/home/brundage/.rvm/gems/[email protected]_finance/gems/rails-4.0.0
/home/brundage/.rvm/gems/[email protected]_finance/gems/rspec-rails-2.14.0
/home/brundage/.rvm/gems/[email protected]_finance/gems/factory_girl-4.2.0
tất cả đều hợp pháp với tôi. Bạn đã chuẩn bị cơ sở dữ liệu thử nghiệm của mình đúng chưa, tức là. 'rake db: test: preparation'? – sevenseacat
Vâng. Đã làm một 'RAILS_ENV = kiểm tra rake db: wipe db: di chuyển db: seed' trước đây. (db: wipe là một nhiệm vụ tùy chỉnh mà chỉ cần giảm tất cả các bảng) –
bạn có thể thử thực sự chạy một 'rake db: test: preparation'? – sevenseacat