Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created April 10, 2015 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/457b08f4de08a59e3eba to your computer and use it in GitHub Desktop.
Save myronmarston/457b08f4de08a59e3eba to your computer and use it in GitHub Desktop.
Demonstration of using matcher for the first argument to `raise_error`
RSpec::Matchers.define :an_exception_caused_by do |cause|
match do |exception|
cause === exception.cause
end
end
expect {
begin
"foo".gsub # requires 2 args
rescue ArgumentError
raise "failed to gsub"
end
}.to raise_error( an_exception_caused_by(ArgumentError) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment