This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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