‹ jan0sch.de

RSpec mocha warning with rails

2013-06-10

Since some time you probably noticed ugly deprecation warning made by mocha if using rspec and rails. Usually they look like this:

*** Mocha deprecation warning: Change require 'mocha' to require 'mocha/setup'. *** Mocha deprecation warning: Test::Unit or MiniTest must be loaded before Mocha. *** Mocha deprecation warning: If you’re integrating with a test library other than Test::Unit or MiniTest, you should use require 'mocha/api' instead of require 'mocha'.

There are several workarounds for this but there is also a clean solution. ;-) Just modify your Gemfile accordingly:

group :development, :test do
  ...
  gem 'mocha', :require => 'mocha/api'
  ...
end