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
RSpec 2.x provided an
rspec/expectations
file which simply delegates torequire '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 gemx-y
should be required usingx/y
. As part of our 3.0 spring cleaning we removed therspec-expectations
file as it's an unneeded layer of indirection. So, you need to requirerspec/expectations
instead ofrspec-expectations
.In your case, the stack trace makes it look like the
require
is happening inside Bundler. When you useBundler.require
it tries to require a file matching the gem name for each gem in theGemfile
. There are good reasons to avoidBundler.require
but if you're going to use it, the fix here is to add:require => "rspec/expectations"
to thegem 'rspec-expectations'
line in yourGemfile
.Actually, if you're using
rspec-core
(on its own, or viarspec-rails
), you don't need to requirerspec/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
andrspec-rails
both depend uponrspec-expectations
so you generally don't need to putrspec-expectations
in yourGemfile
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/orspec-core
orrspec-rails
. So unless you have a specific reason to listrspec-expectations
in yourGemfile
, I recommend you remove it.