I work with a simple (or so I thought) Sinatra application that uses several stones at different stages of the application development / deployment cycle:
- Dependency management bundler
- Rake for assembly tasks
- Asterisks for precompiling assets
- RSpec 2 for tests
- Capistrano for deployment
Gemfile includes rspec in the test group.
The Rakefile defines the assets:compile task to translate Sass to CSS and CoffeeScript to JavaScript and concatenate the resulting files.
Capistrano runs bundle install --without development test so that only the gems needed for production (and compilation of assets) are installed on the production server. It also runs the Cap task, which ultimately runs bundle exec rake assets:compile on the server.
Everything is fine so far, but I would like to add the RSpec Rake task to my Rakefile and that where everything goes wrong. It works fine when I run locally, but when I run cap deploy , I get an error on the server: no such file to load -- rspec/core/rake_task .
This makes sense: RSpec is not installed on the server when we install the package, and the spec task will never work there. The error occurs only because of an attempt to determine the task.
I can come up with several options to handle this, but none of them seem to me completely correct:
- Wrap
require 'rspec/core/rake_task' in a begin...rescue block and ignore the errors - Take
rspec from the test group or otherwise force it to install on the server - Use another rakefile during deployment, which includes only the
assets:compile task - Define my own
spec task, which only requires RSpec when called - Run the precompilation locally and not on the server (my favorite of these options)
What are the best practices here?
source share