Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't auto-configure global concepts when rspec-mocks is required #7

Closed
dchelimsky opened this Issue · 9 comments

2 participants

@dchelimsky
Owner

Background: http://github.com/rspec/rspec-rails/issues#issue/114

require 'rspec-mocks' should not do any of:

  • add should_receive to Object
  • add should_not_receive to Object
  • add stub to Object
  • add double, mock, or stub methods to ExampleGroup or any the test-case class of other consuming framework
@dchelimsky
Owner

This should only happen when RSpec::Mocks::setup is called explicitly.

@wincent

Looking at the code now, looks like you've done a great job of compartmentalizing the "extensions to the Object namespace" and all the rest, so hopefully this won't be too painful to implement.

@wincent

I'm wondering if something as simple as this will be close to what's need:

http://gist.github.com/462638

Breaks 4 examples, though, so currently looking into that.

@dchelimsky
Owner

I'm about to push the fix.

@dchelimsky
Owner

It's not quite that simple :)

@dchelimsky
Owner

require 'rspec/mocks' does not add methods to Object or ExampleGroup

  • call RSpec::Mocks::setup(self) from an example to add double(), mock(), and stub() methods to self, and should_receive(), should_not_receive(), and stub() methods to Object.
  • NOTE the stub() on self is an alias for double(), whereas the stub() on every other object is a method stub declaration.

Closed by e8b3fde.

@wincent

Er, if you say so ;-)

Funnily enough, I found that my "simple" solution actually does pass all specs if I remove the config.include(RSpec::Mocks::Methods) from the spec_helper.

Nice work anyway.

Cheers,
Wincent

@dchelimsky
Owner

There was another step to this, which is that I wanted to simplify the API for the consuming framework. With the changes I made, rspec-core doesn't need to include RSpec::Mocks::ExampleMethods.

FWIW, I wasn't clear that you were working on a solution until I your comment with the gist above, at which point I was pretty much done with the work I was doing. I appreciate your efforts to contribute and don't want to waste your time when doing so, so I apologize for not making it more clear that this was in progress on my end.

Cheers,
David

@wincent

Don't worry about it, it's not like it took me long to do my 2-line patch + feature. The only thing that matters is that the project moves forward, one way or another.

Cheers,
Wincent

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.