开发者

Running Rails tests against seeds.rb?

开发者 https://www.devze.com 2023-02-16 16:23 出处:网络
I want to run tests against the current database instead of whatever is in fixtures/ . Looking at my SQL db, I have a Video (model) with ID 1. However, running

I want to run tests against the current database instead of whatever is in fixtures/ . Looking at my SQL db, I have a Video (model) with ID 1. However, running

ruby functional\videos_cont开发者_运维百科roller_test.rb

gives me the error:

test_check_video_offsets(VideosControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Video with ID=1
app/controllers/videos_controller.rb:16:in `show'

This is all that is in the test right now:

test "check video offsets" do
  get :show, :id => "1"
  Rails::logger.debug @video
end


Got it:

rake db:seed RAILS_ENV=test


Simply set the database name for your test environment to the one of your active environment (development, production.) in your config/database.yml

base: &base
  adapter: mysql2
  encoding: utf8
  username: 
  password: 

development:
  <<: *base
  database: app_development

test: &test
  <<: *base
  database: app_development
0

精彩评论

暂无评论...
验证码 换一张
取 消