I have the following .travis.yml file:
language: ruby
rvm:
- "2.0.0"
# uncomment this line if your project needs to run something other than `rake`:
before_script:
- psql -c "create database dummy_test;" -U postgres
- psql -c "CREATE USER dummy WITH PASSWORD 'dummy';" -U postgres
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- bundle exec rspec spec
When I try running it in Travis CI, I get this error message:
$ RAILS_ENV=test bundle exec rake db:migrate --trace
rake aborted!
Don't know how to build task 'db:migrate'
I've been trying different approaches for hours. What am I doing wrong?
Finally got it working.
The issue was that the application was a dummy application buried within spec/dummy, so running rake db:migrate wouldn't work from the root directory. In order to fix this, I followed the advice given here. Edit the Rakefile to point to spec/dummy and then run rspec tests:
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
require "rspec/core/rake_task"
task :default => :spec
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
# spec.rspec_opts = ['-cfs --backtrace']
end
Related
I'm trying to run my seed file on a remote server using capistrano. My deploy is OK, so there is no issue there. Here is the code for running the seed file in config/deploy.rb
namespace :seed do
desc "Run a task on a remote server."
# run like: cap staging rake:invoke task=a_certain_task
task :default do
run("cd #{deploy_to}/current; /usr/bin/env bundle exec rake #{ENV['db:seed']} RAILS_ENV=#{rails_env}")
end
end
I am evoking this task by running 'cap seed'.
Whats weird is it looks like tests are running when I run this..HERE is a snippet.
Maybe the problem is with #{ENV['db:seed']} part. Isn't it should be just db:seed. The eniviroment variable db:seed doesn't exist so You are calling a pure rake command.
Try this:
run("cd #{deploy_to}/current; /usr/bin/env bundle exec rake db:seed RAILS_ENV=#{rails_env}")
What's the difference between adding a RAILS_ENV before or after a rake task? Here are samples from my staging environments:
Adding RAILS_ENV after rake task.
This raised an error, and the reason for this is accepting development environment as by default and not taking devutility as the environment.
$bundle exec rake -T RAILS_ENV=devutility
$rake aborted!
$cannot load such file -- rack/bug
Adding RAILS_ENV before rake task
This works and lists all the rake task available.
$RAILS_ENV=devutility bundle exec rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake bourbon:install[sass_path] # Move files to the Rails assets directory
rake ci # Continuous Integration build (simplecov-rcov and deploy)
rake cucumber # Alias for cucumber:ok
rake cucumber:all # Run all features
rake cucumber:ok # Run features that should pass
rake cucumber:rerun # Record failing features and run only them if any exist
rake cucumber:wip # Run features that are being worked on
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:data:dump ....................
..............
RAILS_ENV is an environment variable that needs to be available before running your rake task.
When you do:
RAILS_ENV=devutility bundle exec rake -T
It has the same affect as:
export RAILS_ENV=devutility
bundle exec rake -T
RAILS_ENV is not an argument to rake as it may appear, it's part of the environment available to Ruby though it's ENV constant.
I'm trying to do integration testing on travis-ci. I want to be able to run an inclusion filter on travis. in a gist, I want to be able to run fast tests locally while travis-ci tests the fast tests and slow tests including internet dependent tests. I have tried using --tag ~slow_tests under .travis.yml but it gives me an error. here is my .yml file.
language: ruby
rvm:
- 1.9.3
env:
- DB=sqlite
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate spec --tag ~slow_tests
services:
- redis-server
invalid option: --tag
129
130The command "RAILS_ENV=test bundle exec rake --trace db:migrate spec --tag ~slow_tests" exited with 1.
The problem you have is that the --tag option is being interpreted by rake which has no such option. So you need a way to pass the command line options through to RSpec. You can do that with the SPEC_OPTS environment variable:
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate spec SPEC_OPTS="--tag ~slow_tests"
I can run all models with rake:models
Any option to do that that for cucumber tests instead of just rake and running all tests at all levels?
I tried:
$ rake spec:cucumber
rake aborted!
Don't know how to build task 'spec:cucumber'
You should be able to just run rake cucumber
A quick output of rake -T shows:
rake cucumber # Alias for cucumber:ok
rake cucumber:all # Run all features
rake cucumber:ok # Run features that should pass
rake cucumber:rerun # Record failing features and run only them if any exist
rake cucumber:wip # Run features that are being worked on
How to write a rake task that will bundle install then rake db:migrate then rake db:seed.
namespace 'install' do
'bundle install'
'rake db:migrate'
end
This should work but consider using Capistrano/Chef for deployment:
namespace :install do
task :db_reset do
# bundle install - I do not believe attempting this in a rake file
# is recommended as one would need to ensure it is run in your application
# directory and rvm has loaded correct version of ruby/gemsets (.rvmrc required)
Rake::Task['db:migrate'].invoke
end
end
alternatively, you can setup a shell alias to do
bundle install && bundle exec rake db:migrate && bundle exec rake db:seed