Skip to content

Fixing Issue #10 #46

Closed
wants to merge 13 commits into from

3 participants

@kaiwren
kaiwren commented Mar 23, 2011

This fixes #10 by adding support for any_instance

@kaiwren
kaiwren commented Mar 24, 2011

Add support for any_instance:

  • MyClass.any_instance.stub(:m)
  • MyClass.any_instance.should_receive(:m)
  • includes stub and mock APIs including

    • and_return, and_raise, and_yield
    • once, twice, exactly, any_number_of_times, never, at_least, at_most
  • Closed by 8e68513.

  • Closed by 8e68513.
@dchelimsky dchelimsky closed this Mar 24, 2011
@dchelimsky dchelimsky reopened this Mar 24, 2011
@dchelimsky
RSpec member

Great work! I squashed your commits into two commits (one for Andy Lindeman as well) on the any_instance branch.

In reviewing the specs, I disagreed with two of them and reversed the expectations in a subsequent commit: cb0475b:

context "with #should_receive" do

  context "when an expectation is set on a method does not exist" do
    it "fails if no instance is created" do
      expect do
        klass.any_instance.should_receive(:foo).and_return(1)
        klass.rspec_verify
      end.to raise_error(RSpec::Mocks::MockExpectationError)
    end
  end

  context "when an expectation is set on a method that exists" do
    it "fails if no instance is created" do
      expect do
        klass.any_instance.should_receive(:existing_method).and_return(1)
        klass.rspec_verify
      end.to raise_error(RSpec::Mocks::MockExpectationError)
    end
  end

end

Do you agree w/ the change? If so, please go ahead and fork off this branch and get them to pass. If not, let's talk.

@kaiwren
kaiwren commented Mar 24, 2011

Agreed. I hadn't considered the (rather obvious) point that if someone invokes any_instance then they expect instances to be created. I'll fork this, get it green and submit another pull request.

All the other changes make sense to me, but I do have one question - why replace all the == with eq?

@dchelimsky
RSpec member

Ruby raises a warning on ==, so I'm moving towards using eq instead. More consistent with be that way IMO.

@kaiwren
kaiwren commented Mar 31, 2011

Add support for any_instance:

  • MyClass.any_instance.stub(:m)
  • MyClass.any_instance.should_receive(:m)
  • includes stub and mock APIs including

    • and_return, and_raise, and_yield
    • once, twice, exactly, any_number_of_times, never, at_least, at_most
  • Closed by 699a5c2.

  • Closed by 699a5c2.
@dchelimsky dchelimsky closed this Mar 31, 2011
@myronmarston myronmarston pushed a commit to myronmarston/rspec-mocks that referenced this pull request Oct 21, 2012
@kaiwren kaiwren Add support for any_instance:
- MyClass.any_instance.stub(:m)
- MyClass.any_instance.should_receive(:m)
- includes stub and mock APIs including
  - and_return, and_raise, and_yield
  - once, twice, exactly, any_number_of_times, never, at_least, at_most

- Closes #46.
- Closes #10.
699a5c2
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.