Read more

Upgrading Ruby from 1.8.7 to 2.3.5

Dominik Schöler
December 21, 2018Software engineer at makandra GmbH

Suggested Workflow

Set the ruby version in .ruby-version to 2.3.5, then perform these steps one by one, fixing errors as they occur:

  1. Update gems as listed below, and bundle
  2. Boot a Rails console - see below for a list of changes you will probably need
  3. Run Specs with --backtrace option
  4. Run Cucumber features (with Geordi's --debug option)
  5. When all tests are green, look through your Gemfile and remove as many version constraints as possible.
  6. Boot the application in different environements to spot further issues, e.g. rails console staging

Gem updates

  • Replace ruby-debug with byebug or pry

  • Replace mysql with mysql2, '< 0.3'

  • Remove oniguruma

  • Remove net-ssh and net-scp

  • Remove fastercsv

  • Remove cucumber_spinner

  • Remove rspec_spinner

  • Update rspec to '< 2'

  • Lock haml to '= 3.1.7'

  • Unlock andand

  • Unlock rake

  • Lock test-unit to '= 1.2.3'

  • Lock database_cleaner to '< 1.3'

  • Lock cucumber to '< 2'

  • Lock launchy to '~> 2.1 '

  • Lock paperclip to '< 2.8'

  • Add capybara-screenshot and require it in Cucumber features. It will simplify debugging failing features.

    require 'capybara-screenshot/cucumber'
    
    Capybara::Screenshot.prune_strategy = { keep: 12 } # parallel_tests
    
  • TODO: Add rspec-patches gem from PH

Code changes

  • Remove UTF8 hints at the top of files
  • Pay tight attention to method privacy. Ruby 2.3 is more whiny about misusage, especially for Methods defined with define_method.
  • Use the spec_label implementation that works in Ruby 2
  • Update require statements in features/support/env.rb. Use more require_relative or require Rails.root.join('...')
  • Fix Float rounding issues with BigDecimal('12.3')
  • Use ' ' for nbsp helper instead of 0xC2.chr + 0xA0.chr
  • Remove /s regex modifier (your files are UTF8 anyway
  • Remove rcov
  • In Rakefile, replace require 'rake/rdoctask' with require 'rdoc/task'
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Error: wrong number of arguments (given 1, expected 0)
: Use procs instead of lambdas where they are called with variable arguments. Look for named_scopes.

Error: Attempt to call private method, NoMethodError
: Fix tests by replacing thing.private_method with thing.send :private_method

will_paginate errors
: If you get pagination errors, make sure a collection isn't silently replaced after pagination:

# does not work
@contracts = @contracts.reject {...}

# works
@contracts.reject! {...}

YAML fixes

  • Change

    # old 
    date:
      order: [ :day, :month, :year ]
    
    # new
    date:
      order:
        - :year
        - :month
        - :day
    

Also see Upgrade from Ruby 1.8.7 to 2.1.5 – an incomplete guide.

Dominik Schöler
December 21, 2018Software engineer at makandra GmbH
Posted by Dominik Schöler to makandra dev (2018-12-21 13:18)