starting rails in test environment

我的未来我决定 提交于 2019-12-03 03:10:02

You know you can run your unit, functional and integration tests from Rake, right ? Check out the output of rake -T test to see how.

In case you need something more custom, you can create your own Rake task. Put something like this in a file in lib/tasks:

namespace :custom_tests do
  desc "Run my custom tests"
  task :run => :environment do
    puts "RAILS_ENV is #{RAILS_ENV}"
    system "execute mysql script here"
    # Do whatever you need to do
  end
end

The => :environment loads the current environment for you. Then, you can run your task in the test environment like this: RAILS_ENV=test rake custom_tests:run

This command did it for me. I was able to load up the test env aloong with it's Database.

$rails s -e test

to start test environment you should run script/server with -e param:

ruby script/server -e test

and in your config/database.yml must be defenition of test env database, i.e.:

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!