7

In the rails project I'm working on I inserted support for rspec, cucumber and autotest with this Gemfile (partial)

gem 'rspec-rails'
gem 'cucumber-rails'
gem 'autotest-standalone'
gem 'autotest-rails-pure'
gem 'zentest-without-autotest'

however in order to run tests with autotest i need to execute bundle exec autotest otherwise it fails with this message

$ autotest 
loading autotest/cucumber_rails_rspec_rspec2
Error loading Autotest style autotest/cucumber_rails_rspec_rspec2 (no such file to load -- autotest/cucumber_rails_rspec_rspec2). Aborting.

Now I'm developing on a Mac and I'd like to enable autotest-growl and autotest-fsevents gem, but if I insert those lines in my ~/.autotest

require 'autotest/growl'
require 'autotest/fsevent'

then I need to insert the corresponding gems in the Gemfile and everything works, but it breaks builds on my CI server (which is on Linux)

How to solve this without maintaining a different Gemfile for local and CI environments?

EDIT:

For the moment I solved with these lines in Gemfile

if RUBY_PLATFORM.downcase.include?("darwin") # I'm on Mac
  gem 'autotest-fsevent'
  gem 'autotest-growl'
end

It works both locally and on the CI server, I don't know if it mess something, for the moment it seems to work flawlessly.

Any cleaner way to do that is still welcome.

EDIT2:

I switched to groups solutions. While the previous monkeypatch works pretty well both in development and for continuous integration, it will gives you an error in production if you use capistrano bundler tasks for deployments or if you use bundle install --deployment option (which is advised in production)

When using the if RUBY_PLATFORM.downcase.include?("darwin") line you'll get this error on deploy.

# bundle install --deployment --without development test
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.

You have deleted from the Gemfile:
* autotest-fsevent
* autotest-growl

So my final solution to this problem is to include platform specific gems in a given group, say osx, and then in production and on CI server exclude it using bundle.

If you use capistrano to deploy put this in your config.rb

set :bundle_without,  [:development, :test, :osx]
# capistrano bundler task
require "bundler/capistrano"
Fabio
  • 18,856
  • 9
  • 82
  • 114

2 Answers2

0

You can handle this by taking advantage of the different Gemfile environments (testing, development, production).

Your local box can be development while the CI server is your "production" environment.

With this in mind you can edit your Gemfile to use the appropriate gems depending on the environment.

Edit: Sorry, I think I scanned your post too quickly. But you can add your ~/.autotest to .gitignore so it wont be included on your CI server.

Dty
  • 12,253
  • 6
  • 43
  • 61
  • The `~/.autotest` file is not a problem, because it is in my home directory, not in project root. The problem is that it requires two gems that are not listed in Gemfile, so in bundle context requiring those gems raises a load error. I'd like to avoid the other approach (managing different environments in Gemfile) to avoid configuration duplication across them. – Fabio Apr 12 '11 at 12:20
  • Ok, I understand your problem better. But are you saying you don't like the idea of having different "testing, development, production" groups in your Gemfile? Because that's exactly what those groups are there for; diff configs for diff environments. Also, the fact is that your CI and development server are quite different (linux vs osx). Rather than worry about this I think you should focus on creating a reproducible way to setup your CI correctly. And you can do just that by writing your own rake task. – Dty Apr 12 '11 at 13:14
  • I agree with what you're saying, the only thing I'd like to avoid is to put platform dependent gems (autotest-growl) in a common environment (i.e. development), because if I need to run the app on a staging server with development environment (to show a demo or a proof of concept) it wont work on Linux. – Fabio Apr 12 '11 at 13:29
0

You might want to use groups in your gemfile, something like:

group :development do
  gem "autotest-growl"
  gem "autotest-fsevents"
end

and on the server you use: $ bundle install --without development

JHurrah
  • 1,988
  • 16
  • 12
  • I use [this configuration](https://github.com/fabn/rails-jenkins-template) on my ci, and I'd like to keep it simple, so I would like to keep my run steps on ci as simple as `bundle install; rake spec; rake cucumber`. – Fabio Apr 12 '11 at 13:00
  • I make a lot of searches for this issue and there is no solution at the moment. So I'm gonna accept your answer as correct. – Fabio May 28 '11 at 00:42