Created
July 3, 2015 11:21
-
-
Save erwanlr/60c3d7ceee600e88ba96 to your computer and use it in GitHub Desktop.
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
require 'rspec' | |
require 'optparse' | |
module Test | |
class Error < StandardError | |
end | |
class AnotherError < Error | |
def to_s | |
'this message exactly' | |
end | |
end | |
end | |
RSpec.describe 'matching error message with string' do | |
it 'matches the error message' do | |
expect { raise StandardError, 'this message exactly'}. | |
to raise_error(StandardError, 'this message exactly') | |
end | |
it 'matches the error message' do | |
expect { raise Test::Error, 'this message exactly' }. | |
to raise_error(Test::Error, 'this message exactly') | |
end | |
it 'matches the error message' do | |
expect { raise Test::AnotherError }. | |
to raise_error(Test::AnotherError, 'this message exactly') | |
end | |
it 'matches the error message, but does not :x' do | |
expect { raise OptionParser::InvalidArgument, 'this message exactly'}. | |
to raise_error(OptionParser::InvalidArgument, 'this message exactly') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reason of the fail:
The @Reason (freezed string) is added to the message but the inspect don't have it, resulting in the error below when running spec:
Which is a WTF situation and should be (if #inspect was displaying the #message instead of just the args):
So the spec should be
.to raise_error(OptionParser::InvalidArgument, 'invalid argument: this message exactly')
which is not really that good :x