Class: MotionSpec::Matcher::RaiseError
- Defined in:
- lib/motion-spec/matcher/raise_error.rb
Instance Method Summary collapse
- #exception_matcher?(error_class) ⇒ Boolean
- #exception_matches(exception) ⇒ 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.
5 6 7 8 |
# File 'lib/motion-spec/matcher/raise_error.rb', line 5 def initialize(error_class = Exception, = '') @error_class = error_class.is_a?(Class) ? error_class : Exception @error_message = exception_matcher?(error_class) ? error_class : end |
Instance Method Details
#exception_matcher?(error_class) ⇒ Boolean
18 19 20 |
# File 'lib/motion-spec/matcher/raise_error.rb', line 18 def exception_matcher?(error_class) error_class.is_a?(String) || error_class.is_a?(Regexp) end |
#exception_matches(exception) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/motion-spec/matcher/raise_error.rb', line 22 def exception_matches(exception) return false unless exception.is_a?(@error_class) is_match = case @error_message when String exception..include?(@error_message) when Regexp @error_message.match(exception.) else false end is_match ? true : false end |
#fail!(_subject, negated) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/motion-spec/matcher/raise_error.rb', line 38 def fail!(_subject, negated) show_class = @error_class != Exception = !@error_message.is_a?(String) || !@error_message.empty? fail FailedExpectation.new( FailMessageRenderer.( negated, show_class, @error_class, , @error_message, @rescued_exception ) ) end |
#matches?(_value, &block) ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/motion-spec/matcher/raise_error.rb', line 10 def matches?(_value, &block) block.call false rescue Exception => e @rescued_exception = e exception_matches(e) end |