Reputation: 101
I am trying to upgrade my test suite to RSpec 3. After reading the documentation of how to do it I followed all the steps... I have upgraded to 2.99.2 and ran the transpec gem(awesome!) I am left with one deprecation... this:
`require 'rspec-expectations'` is deprecated. Use `require'rspec/expectations'` instead. Called from /Users/kierancormack/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/bundler-1.8.3/lib/bundler/runtime.rb:76:in `require'.
I don't understand what i am supposed to do. I have changed my Gemfile to look like this but it just throws an error. I have required it in my spec_helper.rb but i just can't seem to make it disappear!
Anyone have any suggestions of how to deal with this deprecation?
Thanks
Upvotes: 0
Views: 43
Reputation: 21800
RSpec 2.x provided an rspec/expectations
file which simply delegates to require 'rspec/expectations'
. However, the general convention in the ruby community is for dashes in gem names to correspond to a /
in the top-level file name -- so most ruby programmers would know that gem x-y
should be required using x/y
. As part of our 3.0 spring cleaning we removed the rspec-expectations
file as it's an unneeded layer of indirection. So, you need to require rspec/expectations
instead of rspec-expectations
.
In your case, the stack trace makes it look like the require
is happening inside Bundler. When you use Bundler.require
it tries to require a file matching the gem name for each gem in the Gemfile
. There are good reasons to avoid Bundler.require
but if you're going to use it, the fix here is to add :require => "rspec/expectations"
to the gem 'rspec-expectations'
line in your Gemfile
.
Actually, if you're using rspec-core
(on its own, or via rspec-rails
), you don't need to require rspec/expectations
at all; rspec-core
will load it at the appropriate time for you, so you can use :require => false
to prevent bundler from trying to require it.
In fact, we can take this a step forward: rspec-core
and rspec-rails
both depend upon rspec-expectations
so you generally don't need to put rspec-expectations
in your Gemfile
at all unless you are doing something special (e.g. trying to use a fork or HEAD from github) or you are using it on its own w/o rspec-core
or rspec-rails
. So unless you have a specific reason to list rspec-expectations
in your Gemfile
, I recommend you remove it.
Upvotes: 2