Upgrading from rspec-rails 2.x to rspec-rails 3.x

Problem

You would like to upgrade your rails project from using rspec-rails 2.x to the latest rspec-rails 3.x version. According to the rspec-rails documentation the new 3.x includes many breaking changes.

Solution

The full instructions for upgrading from rspec-rails 2.x to rspec-rails 3.x are here, but you may not need to complete all the steps described in there.
So you could try with the following shorter steps:

  • Run your rspec tests and make sure that they all pass
  • Upgrade your rspec-rails to the version 2.99 provided by the rspec-rails team
  • Run your rspec tests again, and you should have deprecation warnings. Usually that would consist of:
    spec-rails 3 will no longer automatically infer an 
    example group's spec type from the file location. 
    You can explicitly opt-in to this feature using 
    this snippet:
    
    RSpec.configure do |config|
      config.infer_spec_type_from_file_location!
    end

    which you could add to your spec/spec_helper.rb file

  • Run your rspec tests again and this time they should have no deprecation warnings
  • If they all pass then upgrade to the latest rspec-rails (ie 3.0.1).
  • Run your rspec tests again, and this time you should normally have one deprecation warning:
    Requiring `rspec/autorun` when running RSpec via the `rspec` 
    command is deprecated. 
    Called from /xxx/xx/lib/active_support/dependencies.rb:247:
    in `require'.
  • Delete the line require ‘rspec/autorun’ from your spec/spec_helper.rb file
  • Rerun your tests and they should all be passing in rspec-rails 3.x now