Read more

How to remove RSpec "old syntax" deprecation warnings

Dominik Schöler
June 03, 2014Software engineer at makandra GmbH

RSpec 3.0 deprecates the :should way of writing specs for expecting things to happen Show archive.org snapshot .

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

However, if you have tests you cannot change (e.g. because they are inside a gem, spanning multiple versions of Rails and RSpec), you can explicitly allow the deprecated syntax.

Fix

Inside spec/spec_helpber.rb, set rspec-expectations’ and/or rspec-mocks’ syntax as following:

RSpec.configure do |config|
  # ...
  config.mock_with :rspec do |c|
    c.syntax = [:should, :expect]
  end
  config.expect_with :rspec do |c|
    c.syntax = [:should, :expect]
  end
end

Note that you may set it to only one of the syntax options, too. The above code is for maximum compatibility.

Posted by Dominik Schöler to makandra dev (2014-06-03 16:56)