If you develop a gem which integrates with Rails you may want to test against multiple versions of it. My solution to this to use one page Rails applications with the appraisals gem and load the applications based on the actual gem version. Let me show you an example:
We generated a gem skeleton. Let's prepare the gem for testing. We need to add some dependencies to the gemspec:
Create the test folder with the test helper:
Setup rake to run the tests:
Create an `Appraisal` file:
Than run `bundle install` and `rake appraisal:install` to generate the gemfile.
The official Rails guide advises to use a `dummy` Rails app for testing but in their guide it is a structured setup and I think it is better to keep everything in one file in this scenario so we will create a one file Rails application:
Than write an integration test which uses this controller:
If we run `rake appraisal` now it will run this test and it will pass. Next step is to create a Rails 3 test app. First we need to setup the appraisal for that:
Run `rake appraisal:install`. We need to change our test helper to switch beetween the Rails apps based on the Rails version:
Than we need to create the test application:
Now if you ru `rake appraisal` your test suite will be run against both versions of Rails'.
The repo for the source of this example: [multiple-rails-test-example](https://github.com/gregmolnar/multiple-rails-test-example)
Did you enjoy reading this?Follow me on Twitter for more content like this!