I have a gem with a subdirectory (test) containing a Rails 3.1.1 application used to test the project. I'm trying to setup Travis-CI for continuous integration, however I cannot figure out how to setup my .travis.yml configuration. I have:
gemfile: test/Gemfile
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
- ree
script: sh -e 'cd test' && bundle exec rake db:drop db:create db:migrate test
Which causes:
sh: Can't open cd test
Any ideas?
Found it was an issue with some of the documentation. The script call should have been:
script: sh -c 'cd test && bundle exec rake db:drop db:create db:migrate test'
Related
I built a new rails app and when I have configured the .travis.yml file it exits with one all the time.
Here is my travis configuration:
language: ruby
node_js:
- 12
cache:
bundler: true
yarn: true
services:
- redis-server
sudo: required
before_install:
- sudo apt-get update
- sudo apt-get install google-chrome-stable
addons:
postgresql: '9.6'
before_script:
- psql -c 'create database product_hunt_clone_test;' -U postgres
script:
- bundle install
- bundle exec rake db:schema:load
- bundle exec rake db:test:prepare
- SECRET_KEY_BASE=a RAILS_ENV=production bundle exec rake assets:precompile
- bundle exec rake test
- bundle exec rake test:system
and here are the errors travis is giving me:
screenshot from travis console
You have apparently create the initial application using the --skip-sprockets parameter. As such, you have disable the use of the assets pipeline in your application and with that have disable the need (and possibility) to run rake assets:precompile.
If you do need assets pipeline (and thus the rails-sprockets gem), you can re-enable it by adding
gem "sprockets-rails"
to your Gemfile and uncommenting the line
# require "sprockets/railtie"
in your config/application.rb file. You would also need to create the asset files as necessary. Please refer to the documentation for the assets pipeline for details.
If you actually want to skip the assets pipeline, you can just remove the call to the assets:precompile task from your .travis.yml.
Are you correctly installing your gems (with bundle install) before executing your rake commands? Seems like you would need sprockets before compiling the assets.
The protractor configuration and scripts work as expected both on our local development environment and in a continuous integration environment (similar to Codeship).
The project structure is the following (I'm describing the Codeship env. status below):
The AngularJS app requests data from the REST API build with the Ruby on rails app, using AJAX requests.
In our Codeship configuration we set up the rails app, migrate and seed the database so that all necessary data is available.
The AngularJS app is also configured correctly since the login page is rendered as expected (I'm doing a print screen, and the main page is loaded correctly).
The usename and password are filled in by protractor using valid credentials (available in the mysql DB).
But when clicking the 'Log In' button the returned response from the AJAX call is a 405 Method Not Allowed.
As we never encountered this response in our other environments we believe it has something to do with the specific codeship setup.
Any thoughts why the API would return 405 only on Codeship?
The setup is below:
rvm use 2.2.0 --install
cp config/database.codeship.yml config/database.yml
bundle install
export RAILS_ENV="test"
bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:test:prepare
bundle exec rake db:migrate RAILS_ENV=test
bundle exec rake seed:migrate RAILS_ENV=test
cd frontend && npm install && cd ..
npm install -g grunt-cli
npm install -g http-server
cd frontend && npm install bower && cd ..
cd frontend && bower install && cd ..
cd frontend && grunt build && cd ..
cd frontend && webdriver-manager update --standalone && cd ..
export RAILS_ENV="development"
rake db:structure:load
rake seed:migrate
http-server public -a 127.0.0.1 -p 9000 > /dev/null &
http-server app > /dev/null &
bundle exec rake
cd frontend && grunt test && cd ..
Here is the part of the screenshot that shows the API response:
In the end, the solution for us was to use protractor-rails
- basically using the base url of the rails server instead of trying to run the app on a different URL through grunt. Our setup now looks like this:
rvm use 2.2.0 --install
cp config/database.codeship.yml config/database.yml
bundle install
# protractor tests
export RAILS_ENV="development"
rake db:structure:load
rake seed:migrate
npm install
webdriver-manager update
bundle exec rake protractor:init RAILS_ENV=development
bundle exec rake protractor:spec RAILS_ENV=development
# rails tests
bundle exec rake db:test:prepare
bundle exec rake db:migrate RAILS_ENV=test
bundle exec rake seed:migrate RAILS_ENV=test
bundle exec rake
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
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"
So I am attempting to get a capistrano deployment setup with an nginx/unicorn server, using RVM.
The deploy works, but when I attempt to interact with unicorn via capistrano i get an error like:
[~/source/quibbler/config]
$ cap unicorn:start
* executing `unicorn:start'
* executing "cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D"
servers: ["wwwtestvm.whf.app"]
[wwwtestvm.whf.app] executing command
** [out :: wwwtestvm.whf.app] Could not find rake-0.9.2 in any of the sources
command finished in 553ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.2-p290#quibbler' -c 'cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D'" on wwwtestvm.whf.app
I have searched the interwebs all night and can not find the solution. If I copy paste the command into my shell it works so I am 99% sure it has to do with the RVM environment not being correct.
I have created a gist of my deploy and unicorn configs:
https://gist.github.com/1375736#file_deploy.rb
https://gist.github.com/1375736#file_unicorn_production.rb
Any help or guidance would be appreciated.
Thanks to sannankhalid answer on this other question i was able to resolve it.
Short answer: add rake to your Gemfile, make sure you run bundle install so your Gemfile.lock gets updated, then deploy to your server, ayay!