Skip to content

Instantly share code, notes, and snippets.

@kerryb
Created May 27, 2009 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerryb/118581 to your computer and use it in GitHub Desktop.
Save kerryb/118581 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'spec'
class Foo
def self.foo
Bar.bar
rescue StandardError
end
def self.foo2
Bar.bar
Bar.bar
end
end
class Bar
def self.bar
end
end
# All mocks will pass regardless, because Spec::Mocks::MockExpectationError
# is a subclass of StandardError, and is caught in the method under test.
describe 'Calling a method that catches StandardError' do
it 'calls Bar.bar' do
Bar.should_receive :bar
Foo.foo
end
it 'does not call Bar.bar' do
Bar.should_not_receive :bar
Foo.foo
end
end
describe 'Checking call counts for a stubbed method' do
before do
Bar.stub! :bar
end
it 'ignores the count' do
Bar.should_receive(:bar).exactly(1).times
Foo.foo2
end
it 'can be hacked to not ignore the count' do
Bar.send(:__mock_proxy).reset
Bar.should_receive(:bar).exactly(1).times
Foo.foo2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment