Class: Riot::RaisesMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::RaisesMacro
- Defined in:
- lib/riot/assertion_macros/raises.rb
Overview
Asserts that the test raises the expected Exception
asserts("test") { raise My::Exception }.raises(My::Exception)
should("test") { raise My::Exception }.raises(My::Exception)
You can also check to see if the provided message equals or matches your expectations. The message from the actual raised exception will be converted to a string before any comparison is executed.
asserts("test") { raise My::Exception, "Foo" }.raises(My::Exception, "Foo")
asserts("test") { raise My::Exception, "Foo Bar" }.raises(My::Exception, /Bar/)
Instance Attribute Summary
Attributes inherited from AssertionMacro
Instance Method Summary collapse
Methods inherited from AssertionMacro
default, #error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message
Instance Method Details
#evaluate(actual_exception, expected_class, expected_message = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/riot/assertion_macros/raises.rb', line 14 def evaluate(actual_exception, expected_class, =nil) = actual_exception && actual_exception. if actual_exception.nil? fail .raised(expected_class).but.raised_nothing elsif expected_class != actual_exception.class fail .raised(expected_class).not(actual_exception.class) elsif && !(.to_s =~ %r[#{expected_message}]) fail ()..not() else = .raises(expected_class) pass( ? .() : ) end end |