我使用rails g model User
生成了一個模型的裸導軌3應用程序。RSpec失敗:遷移後無法找到表...?
我(使用factory_girl_rails
)增加了一個工廠:
Factory.define :user do |f|
f.email "[email protected]"
f.password "blah"
f.password_confirmation "blah"
f.display_name "neezer"
end
然後我添加了一個試驗:
require 'spec_helper'
describe User do
subject { Factory :user }
it "can be created from a factory" do
subject.should_not be_nil
subject.should be_kind_of User
end
end
然後我使用rake db:migrate
遷移我的數據庫。
然後我跑使用rspec spec
測試,測試失敗,出現以下:
Failures:
1) User can be created from a factory
Failure/Error: subject { Factory :user }
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/user_spec.rb:5:in `block (2 levels) in <top (required)>'
# ./spec/models/user_spec.rb:8:in `block (2 levels) in <top (required)>'
我很困惑,因爲我所做的僅僅是遷移我的數據庫,我schema.db
文件反映的則是一個用戶表禮物,所以給了什麼?
我知道這是一個初學者的問題,但敲我的頭靠在牆上是不工作...
factory_girl (1.3.3)
factory_girl_rails (1.0.1)
rails (3.0.5)
rspec-rails (2.5.0)
sqlite3 (1.3.3)
我需要運行,每當我做出新的遷移,或者只是它只是「引導」的測試數據庫? – neezer 2011-03-10 19:00:41
只是一次,這就像db:migrate,我實際上總是把它放在一個自定義的任務中,我將它遷移,加載裝置,測試數據庫等等。 – Spyros 2011-03-10 19:49:59
rake db如何處理的任何想法:test:prepare * does not * fix the problem? :( – Raphael 2012-01-27 19:10:16