Class: BaconExpect::Matcher::RaiseError
- Inherits:
-
Object
- Object
- BaconExpect::Matcher::RaiseError
- Defined in:
- lib/bacon-expect/matchers/raise_error.rb
Instance Method Summary collapse
- #exception_matches(e) ⇒ Object
- #fail!(subject, negated) ⇒ Object
-
#initialize(error_class = Exception, message = "") ⇒ RaiseError
constructor
A new instance of RaiseError.
- #matches?(value, &block) ⇒ Boolean
Constructor Details
#initialize(error_class = Exception, message = "") ⇒ RaiseError
Returns a new instance of RaiseError.
3 4 5 6 |
# File 'lib/bacon-expect/matchers/raise_error.rb', line 3 def initialize(error_class = Exception, = "") @error_class = error_class.is_a?(Class) ? error_class : Exception @error_message = (error_class.is_a?(String) || error_class.is_a?(Regexp)) ? error_class : end |
Instance Method Details
#exception_matches(e) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/bacon-expect/matchers/raise_error.rb', line 18 def exception_matches(e) e.is_a?(@error_class) && ( (@error_message.is_a?(String) && e..include?(@error_message)) || (@error_message.is_a?(Regexp) && @error_message.match(e.)) ) end |
#fail!(subject, negated) ⇒ Object
25 26 27 28 29 |
# File 'lib/bacon-expect/matchers/raise_error.rb', line 25 def fail!(subject, negated) show_class = @error_class != Exception = !@error_message.is_a?(String) || !@error_message.empty? raise FailedExpectation.new(FailMessageRenderer.(negated, show_class, @error_class, , @error_message, @rescued_exception)) end |
#matches?(value, &block) ⇒ Boolean
8 9 10 11 12 13 14 15 16 |
# File 'lib/bacon-expect/matchers/raise_error.rb', line 8 def matches?(value, &block) begin block.call false rescue Exception => e @rescued_exception = e exception_matches(e) end end |