Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Record invocations for stubs with stub_everything = true #6

Merged
merged 1 commit into from

2 participants

@opsb

Allows invocations to be recorded for stubs created using stub_everything e.g.

describe "mock" do
  context "with stub_everything = true" do
    before do
      @person = stub_everything
      @person.welcome
    end

    it "should record all invocations" do
      @person.should have_received(:welcome)
    end
  end
end
@mike-burns mike-burns merged commit a4149be into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2011
  1. @opsb
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +8 −0 lib/bourne/mock.rb
  2. +16 −0 test/acceptance/spy_test.rb
View
8 lib/bourne/mock.rb
@@ -16,6 +16,14 @@ def method_missing(symbol, *arguments, &block)
message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
message << Mockery.instance.mocha_inspect
raise ExpectationError.new(message, caller)
+ else
+ target = if self.respond_to? :mocha
+ self.mocha
+ else
+ mocha
+ end
+ Mockery.instance.invocation(target, symbol, arguments)
+ nil
end
end
end
View
16 test/acceptance/spy_test.rb
@@ -142,3 +142,19 @@ def new_instance
stub
end
end
+
+class StubEverythingSpyTest < Test::Unit::TestCase
+ include AcceptanceTest
+ def setup
+ setup_acceptance_test
+ end
+
+ def teardown
+ teardown_acceptance_test
+ end
+ def test_should_match_invocations_with_no_explicit_stubbing
+ instance = stub_everything
+ instance.surprise!
+ assert_received(instance, :surprise!)
+ end
+end
Something went wrong with that request. Please try again.