Class: Given::FailureMatcher
- Inherits:
-
Object
- Object
- Given::FailureMatcher
- Defined in:
- lib/given/failure_matcher.rb
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #==(other) ⇒ Object
- #does_not_match?(possible_failure) ⇒ Boolean
-
#initialize(exception_class, message_pattern) ⇒ FailureMatcher
constructor
A new instance of FailureMatcher.
- #inspect ⇒ Object
- #matches?(possible_failure) ⇒ Boolean
Constructor Details
#initialize(exception_class, message_pattern) ⇒ FailureMatcher
Returns a new instance of FailureMatcher.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/given/failure_matcher.rb', line 4 def initialize(exception_class, ) @no_pattern = false @expected_exception_class = exception_class @expected_message_pattern = if @expected_message_pattern.nil? @expected_message_pattern = // @no_pattern = true elsif @expected_message_pattern.is_a?(String) @expected_message_pattern = Regexp.new("\\A" + Regexp.quote(@expected_message_pattern) + "\\z") end end |
Instance Method Details
#!=(other) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/given/failure_matcher.rb', line 25 def !=(other) if other.respond_to?(:call) does_not_match?(other) else super end end |
#==(other) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/given/failure_matcher.rb', line 17 def ==(other) if other.respond_to?(:call) matches?(other) else super end end |
#does_not_match?(possible_failure) ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/given/failure_matcher.rb', line 41 def does_not_match?(possible_failure) if possible_failure.respond_to?(:call) mismatch_or_fail(possible_failure) else true end end |
#inspect ⇒ Object
49 50 51 52 53 |
# File 'lib/given/failure_matcher.rb', line 49 def inspect result = "<Failure on #{@expected_exception_class}" result << " matching #{@expected_message_pattern.inspect}" unless @no_pattern result << ">" end |