When you run tests you are always in the test environment since RAILS_ENV
is hardcoded in test_helper.rb
. Setting RAILS_ENV=production
means the schema will be cloned from the production database rather than the development database. I could of course set up a development database on the production servers, but that doesn't seem to make sense.
Given all the differences there are between my development and production server - operating system, web server, database, gems etc. - I can't really feel comfortable deploying my application unless I have first run my test suite not only in development but also in production. Thanks to the beautiful and powerful API of Capistrano this is a walk in the park to accomplish:
Here goes the example how it seems to be done -
desc "Run the full tests on the deployed app."
task :run_tests do
run "cd #{release_path} && RAILS_ENV=production rake && cat /dev/null > log/test.log"
end
desc "Copy in server specific configuration files"
task :copy_shared do
run <<-CMD
cp #{shared_path}/system/voxway.rb #{release_path}/config &&
cp #{shared_path}/system/database.yml #{release_path}/config
CMD
end
desc "Run pre-symlink tasks"
task :before_symlink, :roles => :web do
copy_shared
run_tests
end