Skip to content

Instantly share code, notes, and snippets.

@kostia
Last active August 29, 2015 14:13
Show Gist options
  • Save kostia/f896d21628d750b94ced to your computer and use it in GitHub Desktop.
Save kostia/f896d21628d750b94ced to your computer and use it in GitHub Desktop.
Upgrading Rails 4.1 to 4.2 with RSpec 2

Upgrading Rails 4.1 to 4.2 with RSpec 2

Upgrading Rails is normally a simple task, especially if the difference between the versions is not very large. But in the case of 4.1 to 4.2 upgrade of an application (or a library) using RSpec 2, it can get messy, because RSpec 2 is not fully compatible with Rails 4.2. So in order to upgrade Rails, you have to upgrade RSpec first. Here how we did that:

In order to upgrade to RSpec 3 we first upgrade to RSpec 2.99.0, run the specs to see the deprecations, fix the deprecations and then upgrade to 3.1.0.

  1. First remove all RSpec gems except rspec-rails (all the rspec-* gems).
  2. Then update rspec-rails gem to version 2.99.0.
  3. Now run the specs and fix the deprecations. Here some helpfull libraries to workaround the deprecations, while not changing the actual spec code:
  • rspec-activemodel-mocks
  • rspec-its
  • rspec-collection_matchers

If you see no deprecations (and the specs are green), then commit the changes. You could also have to change all the be_trues to be_truthys and all the be_falses to be_falseys. We did that in a separate commit, to provide a better overview of the steps in Git.

Next update to RSpec 3.1.0 and run the specs again. If there are deprecations, fix them. There should be no new errors or failures. Commit the changes.

Now update the Rails version to 4.2.0 and re-run the specs. The few failures we had were easy to fix.

Optionally you can also:

  • Replace Timecop calls with new test helper methods travel and travel_to.
  • Remove Spork / Drb integration, since Rails 4.2 ships with Spring, which does the same, but better.
  • If you feel funny, then try to remove the compatibility gems (rspec-activemodel-mocks and others), by refactoring the spec code. You can do than either using a special tool (for example transpec) or manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment