Class: Mustard::CloseMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mustard/matchers/close_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(subject, expected, delta = 0.001) ⇒ CloseMatcher

Returns a new instance of CloseMatcher.



3
4
5
6
7
# File 'lib/mustard/matchers/close_matcher.rb', line 3

def initialize(subject, expected, delta = 0.001)
  @subject = subject
  @expected = expected
  @delta = delta
end

Instance Method Details

#failure_messageObject



13
14
15
# File 'lib/mustard/matchers/close_matcher.rb', line 13

def failure_message
  "expected #{@subject.inspect} to #{message_expected}"
end

#match?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/mustard/matchers/close_matcher.rb', line 9

def match?
  @delta >= (@subject - @expected).abs
end

#message_expectedObject



21
22
23
# File 'lib/mustard/matchers/close_matcher.rb', line 21

def message_expected
  "be within #{@delta.inspect} of #{@expected.inspect}"
end

#negative_failure_messageObject



17
18
19
# File 'lib/mustard/matchers/close_matcher.rb', line 17

def negative_failure_message
  "expected #{@subject.inspect} to not #{message_expected}"
end