Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't explicitly require mocks and expectations upfront.

rspec-core will require them at the appropriate time as
long as the user hasn't configured a different mocking
or expectation library. We don't want to load them
unnecessarily.
  • Loading branch information...
commit f10bedd498dff2961d4be9cce793fa152c4a0bbe 1 parent a3daf2b
@myronmarston myronmarston authored
Showing with 1 addition and 2 deletions.
  1. +1 −2  lib/rspec.rb
View
3  lib/rspec.rb
@@ -1,4 +1,3 @@
require 'rspec/core'
-require 'rspec/expectations'
-require 'rspec/mocks'
require 'rspec/version'
+

7 comments on commit f10bedd

@jimmycuadra

This change caused the build in one of my projects to break, because it was assuming require "rspec" would load RSpec::Mocks. Isn't the point of the "rspec" meta gem to load the full suite? If someone wants to use only the core, they would install rspec-core and require "rspec/core".

@JonRowe
Owner

The point of the rspec gem is to provide the rspec tool. RSpec::Mocks is automatically loaded by rspec-core when needed. If you need RSpec::Mocks outside of rspec you should probably be explicitly requiring it.

@jimmycuadra

With this change, rspec is now just an alias for rspec-core. That is very different from its prior behavior. :-1:

@JonRowe
Owner

No, it's a package of the three gems to provide the rspec tool. Which is the same as it's prior behaviour.

Previously we were actually automatically loading mocks, even if somebody changed the configured mocking framework, which led to some problems. Can I ask what you were doing with the require 'rspec' as this change does not affect running spec's with rspec.

@myronmarston

Isn't the point of the "rspec" meta gem to load the full suite?

No. The point of the rspec gem is to be able to get all of rspec's components with a single gem install rspec command (and/or by just specifying gem rspec in your Gemfile).

If we didn't provide the rspec gem, users would have to install rspec-core, rspec-mocks and rspec-expectations individually.

When you run rspec, it will load rspec-mocks and rspec-expectations at the right time as needed. As @JonRowe, said, if you want to use RSpec::Mocks you should either require it explicitly, or (even better!) use the explicit configuration APIs provided by rspec-core:

RSpec.configure do |rspec|
  rspec.mock_with :rspec
end

To give more context for this change, checkout rspec/rspec-mocks#359. It's an example of where a user was explicitly configuring rspec to not use rspec-mocks (opting for mocha instead) but rspec-mocks was still being (wrongly) loaded, due to the fact they had a require "rspec". I would recommend not doing require "rspec" anywhere (the rspec command will take care of that for you) but given that we have explicit configuration APIs or pulling in rspec-mocks and rspec-expectations, it was an unintended bug for require "rspec" to load those gems.

@jimmycuadra

Thanks for the explanation – I understand now. I suppose I made an assumption I shouldn't have. For context, this is what broke (the first begin block):

https://github.com/jimmycuadra/lita/blob/259e0cf9047cad8416959e82a03a7f2beefd09e2/lib/lita/rspec.rb

I changed it to this:

https://github.com/jimmycuadra/lita/blob/61434d730992a049548e9f631085d9453fb9c2ff/lib/lita/rspec.rb

Now it's all good. Plus, it's more clear what the dependencies are on my end.

@myronmarston

@jimmycuadra Glad you worked things out, and thanks for taking the time to understand. 2.14 wasn't meant to break anyone's use of rspec, but there have been subtle edge cases and places where users have used things in a different way than we intended and thus didn't consider. While we strive to follow semver and keep all minor releases fully backwards compatibile, in practice that's more difficult than one would normally think :(.

Please sign in to comment.
Something went wrong with that request. Please try again.