-
-
Save ArthurZheng/21c608001b09d8171b9942dd0115308d to your computer and use it in GitHub Desktop.
How to stub raising exceptions in rspec
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 Foo | |
class << self | |
def exec | |
something | |
rescue => ex | |
ex.message | |
end | |
def something | |
"something" | |
end | |
end | |
end | |
describe Foo do | |
describe ".exec()" do | |
context "when error occured" do | |
before do | |
Foo.stub(:something).and_raise(StandardError.new("error")) | |
end | |
subject(:msg) { Foo.exec } | |
it "returns its error message" do | |
expect(msg).to eq("error") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment