Created
June 25, 2012 20:45
-
-
Save marcinbunsch/2991112 to your computer and use it in GitHub Desktop.
expecting an error once
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
class Wat | |
attr_accessor :collaborator, :credentials | |
def foo(arg) | |
@collaborator.foo(arg) | |
rescue | |
@collaborator.set_auth_credentials(credentials) | |
@collaborator.foo(arg) | |
end | |
end | |
describe Wat do | |
describe "#foo" do | |
let(:arg) { mock } | |
let(:credentials) { mock } | |
let(:result) { mock } | |
before do | |
subject.collaborator = mock | |
end | |
it "delegates foo to collaborator" do | |
subject.collaborator.should_receive(:foo).with(arg).and_return(result) | |
subject.foo(arg).should eq(result) | |
end | |
it "handles the exception" do | |
subject.credentials = credentials | |
subject.collaborator.should_receive(:foo).once.with(arg).and_raise(StandardError.new) | |
subject.collaborator.should_receive(:set_auth_credentials).once.with(credentials) | |
subject.collaborator.should_receive(:foo).with(arg).and_return(result) | |
subject.foo(arg).should eq(result) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment