RSpec 失败:迁移后找不到表...? [英] RSpec failure: could not find table after migration...?
问题描述
我有一个带有一个模型的裸 Rails 3 应用程序,使用 rails g 模型用户
生成.
I have a naked rails 3 app with one model, generated using rails g model User
.
我添加了一个工厂(使用 factory_girl_rails
):
I've added a factory (using factory_girl_rails
):
Factory.define :user do |f|
f.email "test@test.com"
f.password "blah"
f.password_confirmation "blah"
f.display_name "neezer"
end
然后我添加了一个测试:
Then I've added one test:
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
运行测试,测试失败并显示以下内容:
Then I run the test using rspec spec
, and the test fails with the following:
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
文件反映存在一个 users 表,那么是什么给出的?
I'm confused, because I did just migrate my database, and my schema.db
file reflects that there is a users table present, so what gives?
我知道这是一个初学者的问题,但是用头撞墙是行不通的...
I know this is a beginner question, but banging my head against a wall isn't working...
factory_girl (1.3.3)
factory_girl_rails (1.0.1)
rails (3.0.5)
rspec-rails (2.5.0)
sqlite3 (1.3.3)
推荐答案
尝试执行
rake db:test:prepare
这应该可以修复您的测试数据库.
This should fix your tests db.
这篇关于RSpec 失败:迁移后找不到表...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!