Transition to RSpec 3

About 200 Ruby packages are using the RSpec framework to test their functionalities. The version 2 shipped with Jessie is now deprecated. Unfortunately, several used syntax RSpec idioms, already deprecated in version 2.14, are now considered errors in version 3. Some more deprecation warnings appear in version 3. This page aims at listing the common problems and their solutions so that we can provide patches and help upstream upgrade to RSpec3.

An important resource for deprecation and hints for transition is thist RSpec blog post.

Using transpec gem

The gem transpec may be used to convert the RSpec tests to latest syntax. To fix the tests of gem ruby-foo, the steps to follow are

  1. Install the gem transpec
  2. Get a copy of the build directory of ruby-foo from Alioth Git repo
  3. Switch to upstream branch
  4. Run the command transpec (In case it reports any errors, perform a bundle install and again run the transpec command)

  5. Do a git status to see which all tests were fixed (changes not commited)

  6. Make those changes in the master branch (you may copy the changed files to a temporary location, switch back to master branch) using common quilt patch approach and test the build in a chroot environment

Errors

be_true and be_false

be_true and be_false should be replaced by be_truthy and be_falsey respectively, if the tested object do not respond to #true? and #false?.

stub! and mock

stub! and mock should be replaced by stub and double.

the its idiom

It seeds the rspec-its gem, for which there is an ITP.

config.color_enabled

In RSpec config, color_enabled, color_enabled= and color? has been deprecated in favor of color, color= and color_enabled?

New Deprecation Warnings

should and should_not

This old syntax can still be used without warning, if a special configuration option is set. It is recommend to use instead the expect syntax:

foo.should eq something  could be replaced by expect(foo).to eq something.