【发布时间】:2013-08-02 07:20:18
【问题描述】:
我收到以下错误,即使在执行rake db:test:prepare 之后也是如此。我正在运行 rails 4.0。
1) Core::PostsController GET index assigns all posts as @posts
Failure/Error: post = Post.create! valid_attributes
ActiveRecord::StatementInvalid:
Could not find table 'core_posts'
# ./spec/controllers/core/posts_controller_spec.rb:36:in `block (3 levels) in <module:Core>'
我在引擎中运行这个测试,所以它可能是相关的吗?我的测试如下所示:
module Core
describe PostsController do
# This should return the minimal set of attributes required to create a valid
# Post. As you add validations to Post, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { { } }
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# PostsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET index" do
it "assigns all posts as @posts" do
post = Post.create! valid_attributes
get :index, {}, valid_session
assigns(:posts).should eq([post])
end
end
end
end
有什么想法吗?谢谢!
【问题讨论】:
-
你真的创建了表吗?
-
我认为 rake db:test:prepare 创建了它...
-
仅当它存在于您的开发数据库和架构文件中时。 Rails 不是通灵的。
-
是的,所以我先做了 rails db:migrate,然后是 rails db:test:prepare。架构确实有:create_table "core_posts", force: true do |t| t.datetime "created_at" t.datetime "updated_at" 结束
-
我刚刚意识到我的主应用程序中的 development.sqlite3 有数据,但是我的引擎中的 development.sqlite3 是空的。我正在从我的引擎内部运行 rspec。我猜是因为这个?
标签: ruby-on-rails rspec ruby-on-rails-4