Spies in #241 don't reset message received count when spying on class methods #248

Closed
agrobbin opened this Issue Mar 23, 2013 · 0 comments

1 participant

@agrobbin

As mentioned in #241 (comment):

class TestClass; end

describe TestClass do
  before { TestClass.stub(:blah) }

  it "should call TestClass twice" do
    TestClass.blah
    TestClass.blah
    expect(TestClass).to have_received(:blah).exactly(2).times
  end

  it "should call TestClass once" do
    expect(TestClass).to_not have_received(:blah)
  end
end

The result when running rspec test_class_spec.rb is this:

.F

Failures:

  1) TestClass should call TestClass once
     Failure/Error: expect(TestClass).to_not have_received(:blah)
       (<TestClass (class)>).blah(any args)
           expected: 0 times
           received: 2 times
     # ./test_class_spec.rb:13:in `block (2 levels) in <top (required)>'

Finished in 0.00109 seconds
2 examples, 1 failure

Failed examples:

rspec ./test_class_spec.rb:12 # TestClass should call TestClass once

It looks like the same kind of issue that technicalpickles/rspec-spies#18 fixes, if that helps at all.

As a note, this is for the thoughtbot-jf-jq-spies branch

@agrobbin agrobbin referenced this issue Mar 26, 2013
Merged

Add test spies #241

@myronmarston myronmarston pushed a commit that closed this issue Mar 29, 2013
@jferris jferris Clear messages received when mocks reset
* Proxy objects for class methods/global objects persist between test runs

Fixes #248.
3cb4ccc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment