Upgrading to Rails 4.2.0.beta2 ( aka upgrading to rspec-rails 3.1.x )

October 21, 2014

Here is the process we went through to get our tests passing after upgrading our Rails app from Rails 4.1 to Rails 4.2.0.beta2.

  1. We updated the rails gem version and ran bundle update, and found these

    gems needed to be upgraded to resolve dependencies:
    gem 'rspec-rails', '~> 2.14.1' upgraded to '~> 3.1.0'
    gem 'rspec', '~> 2.14.1' upgraded to '~> 3.1.0'
    gem 'sass-rails', '>= 3.2' upgraded to '>= 5.0.0.beta1'
    gem 'bootstrap-sass', '~> 3.1.1' upgraded to ''
    gem 'uglifier', '>= 1.3.0' upgraded to '~> 2.5.3'
  2. We ran rake rails:update to add the new files we didnt yet have, such as :

  3. When running the app in development, we got errors: One or more change appeared to cause the application.js and or application.cs to throw a 500 server error on web page load. So commenting out the contents of each of the newly added files in 2) appears to have helped in the short term.

    Icons were missing on the webpages. The GET route for the glyphicons failed. So as a workaround we moved these assets to a new folder “public/fonts/bootstrap/”

  4. We got test failures:

    We updated spec_helper:

    config.include RSpec::Rails::ViewRendering

    Then per recommendation for rspec-rails - we did the one off upgrade tests syntax from 2.x to 3.x using the transpec gem This mainly updated the “should” rspec-expectation syntax to “expect”. Great! we didnt want to do that by hand. ( But it turns out we could have kept the shoulds )

    25% of the tests were still failing, and there were two deprecation warnings repeated multiple times. Half failures were like this:

    Failure/Error: expect(get("/emails/1")).to route_to("emails#show", :id => "1") ActionController::UrlGenerationError: No route matches {:action=>"/emails/1", :controller=>"emails"}


    => easily fixed the syntax from expect(get(“/foo”)).to route_to(“foo#index”)

    => expect(get: “/foo”).to route_to(“foo#index”) The other half were like this:

    NoMethodError: undefined method `visit' for #<RSpec::ExampleGroups::foo...
    • we were using gem ‘webrat’, ‘0.7.3’

    => On updating the “integration_signin” helper method, this became “NoMethodError: undefined method `original_path_set’ for nil:NilClass”

    => So added “config.include SessionsHelper, :type => :request” to spec_helper.rb

  5. We then Rake updated the rspec files : this renamed spec_helper as rails_helper, then we ran “rails generate rspec:install”

    => still many test failures. Fix expect(response).to have_selector(“title”, :text =>” with “expect(response.body).to have_selector” We moved to using to using Capybara instead of webrat. All tests involving filling in fields were moved to a new “features” folder and “describe/it” format changed to “feature/scenario”. This took a long time. But now everything is passing!

  6. Finally we reinstated these files:


Publish to production, and everything is working fine.

© 2018 Keith P | Follow on Twitter | Git