Skip to content

Instantly share code, notes, and snippets.

@dlchet
Created February 16, 2012 20:44
Show Gist options
  • Save dlchet/1847708 to your computer and use it in GitHub Desktop.
Save dlchet/1847708 to your computer and use it in GitHub Desktop.
how to use rspec stubbing to first raise, then return
module Test
def catcher
begin
pp Foo.bar
rescue Exception
pp "errored"
end
end
end
include Test
class Foo; end
describe "testing" do
it "should work" do
@counter = 0
Foo.stub(:bar) do
@counter += 1
pp @counter
raise Exception if @counter < 2
"hello"
end
catcher
catcher
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment