Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Last active August 29, 2015 14:13
Show Gist options
  • Save myronmarston/9032b943b2f2bc181034 to your computer and use it in GitHub Desktop.
Save myronmarston/9032b943b2f2bc181034 to your computer and use it in GitHub Desktop.
Using `an_error_other_than` as an argument to `raise_error`
failing (FAILED - 1)
passing
Failures:
1) Using `an_error_other_than` as an argument to `raise_error` failing
Failure/Error: expect {
expected an error other than SyntaxError, got #<SyntaxError: SyntaxError> with backtrace:
# ./spec/raise_error_spec.rb:12:in `block (3 levels) in <top (required)>'
# ./spec/raise_error_spec.rb:11:in `block (2 levels) in <top (required)>'
# ./spec/raise_error_spec.rb:11:in `block (2 levels) in <top (required)>'
Finished in 0.00248 seconds (files took 0.11564 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/raise_error_spec.rb:10 # Using `an_error_other_than` as an argument to `raise_error` failing
RSpec::Matchers.define_negated_matcher :an_error_other_than, :an_instance_of
RSpec.describe "Using `an_error_other_than` as an argument to `raise_error`" do
example "passing" do
expect {
raise ArgumentError
}.to raise_error(an_error_other_than(SyntaxError))
end
example "failing" do
expect {
raise SyntaxError
}.to raise_error(an_error_other_than(SyntaxError))
end
end
@rkh
Copy link

rkh commented Jan 23, 2015

Is there a reason you can't write an expectation about what will happen (e.g. that a specific error is raised) rather than what won't happen?

Yes, it's raising a GH::Error but should not raise a GH::TokenInvalid, which is a subclass of GH::Error so just checking for that wouldn't really work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment