Skip to content

Instantly share code, notes, and snippets.

@marcinbunsch
Created June 25, 2012 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcinbunsch/2991112 to your computer and use it in GitHub Desktop.
Save marcinbunsch/2991112 to your computer and use it in GitHub Desktop.
expecting an error once
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