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
.
- First remove all RSpec gems except
rspec-rails
(all therspec-*
gems). - Then update
rspec-rails
gem to version2.99.0
. - 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_true
s to be_truthy
s and all the be_false
s to be_falsey
s. 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 methodstravel
andtravel_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 exampletranspec
) or manually.