私は、コントローラの仕様にこの、その結果、この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
のようなものを持っている:
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
私のクレジットカードの工場は次のようになります。
FactoryGirl.define do
factory :credit_card_account do
exp_month 10
exp_year 2075
number '3'
end
end
私のCreditCardAccountは空のActiveRecord :: Baseモデル
ですの=> CreditCardAccount(id: integer, exp_month: integer, exp_year: integer, number: string)
バージョン
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
すべてが正式に見えます。テストデータベースを適切に準備しましたか? 'rake db:test:prepare'? – sevenseacat
うん。前に 'RAILS_ENV = rake db:wipe db:migrate db:seed'を実行しました。 (db:wipeはすべてのテーブルを削除するカスタムタスクです) –
実際に 'rake db:test:prepare'を実行できますか? – sevenseacat