-
-
Notifications
You must be signed in to change notification settings - Fork 760
Access the current mocking adapter / Cucumber compatibility #1480
Comments
You can access the adapter for the currently configured mock framework using Anyhow, why does cucumber even load rspec-core? rspec-core is the test runner and isn't intended to be loaded by other test runners. rspec-expectations and rspec-mocks are both pieces that an alternate test runner like cucumber can load and use on their own. @mattwynne -- do you know why cucumber loads rspec-core? |
That file https://github.com/cucumber/cucumber/blob/master/lib/cucumber/rspec/doubles.rb#L4 was added before my time and I wasn't actually aware it was there. It would need to be explicitly required by a client project, as in this example I believe the purpose of this file is to allow people to use RSpec mocks in their Cucumber step defs, and have the mock assertions get checked at the end of the scenario. That's not a practice I would use myself, but I guess it's a facility someone must have asked for. Is there a way to do that 'properly' via RSpec's API? Would it make more sense for this code to move into rspec-mocks, so people have to require |
Yep. It's what the rest of the file is already doing. (At least, the rest of the file is using the RSpec 2.x API for it). Specifically, this is what was needed in RSpec 2: require 'rspec/mocks'
# This line may actually not be needed, depending on what `self` is in the `Before` hook,
# as in rspec 2, `RSpec::Mocks.setup` would auto-include the module in the singleton class
# of the passed arg.
World(RSpec::Mocks::ExampleMethods)
Before do
RSpec::Mocks::setup(self)
end
After do
begin
RSpec::Mocks::verify
ensure
RSpec::Mocks::teardown
end
end In RSpec 3, this has changed very slightly: you're responsible for including require 'rspec/mocks'
World(RSpec::Mocks::ExampleMethods)
Before do
RSpec::Mocks.setup
end
After do
begin
RSpec::Mocks.verify
ensure
RSpec::Mocks.teardown
end
end
Maybe. Currently rspec-mocks doesn't have any logic in it to auto-integrate with any frameworks (not even with rspec-core -- it's rspec-core that takes care of that). The API I've shown above for RSpec 3 will be in place for a long time to come -- at least until RSpec 4 (as per semver) and we have no plans to ever change it further so potentially for much longer after that. |
I don't think there's anything for us to change in rspec for this so I'm going to close it. Let me know if there are further questions. |
@lime would you please create a ticket on Cucumber's issue tracker for this? |
Sure! I'm not entirely sure how to phrase it, but I'll give it a shot. ;) |
RSpec::Core::MockFrameworkAdapter is not intended to be used outside rspec-core itself, RSpec::Mocks::ExampleMethods should fulfil the same purpose. See rspec/rspec-core#1480
The documented solution for including rspec here https://github.com/cucumber/cucumber/wiki/RSpec-Expectations does not seem to apply. This solution however seems to work: rspec/rspec-core#1480
In #1188 @myronmarston switched from using
RSpec::Core::MockFrameworkAdapter
to separateRSpec::Core::MockingAdapters
for each mocking framework.Is there / should there be a way to access the currently used adapter?
I ask particularly because I'm anticipating an incompatibility with Cucumber, since they currently access
RSpec::Core::MockFrameworkAdapter
directly in lib/cucumber/rspec.doubles.rb:4. As it stands now, Cucumber 1.3.14 will not work with RSpec 3.0.0.beta2.I'm new to the RSpec codebase, so forgive me if I missed something.
The text was updated successfully, but these errors were encountered: