Module: Ward::Spec::MatcherMatcher

Defined in:
lib/ward/spec/matcher_matcher.rb

Overview

Since Ward matchers are permitted to return either false, or an Array whose first member is false, to indicate a failure, determining the status of a match attempt relies in you knowing this in advance:

result, error = matcher.matches?(value)
result.should be_false

The helpers within the MatcherMatcher module simplify this situation:

matcher.should pass_matcher_with(value)
matcher.should fail_matcher_with(value)

The fail_matcher_with helper also provides the ability to check the error message returned by the matcher:

matcher.should fail_matcher_with(value, :too_short)

Class Method Summary collapse

Class Method Details

.error_message(result, matcher, value) ⇒ String

Formats error messages for spec failures.

Parameters:

  • result (String, Symbol)

    Did you expect a :pass or :fail?

  • matcher (Ward::Matchers::Matcher)

    The matcher instance which was used for the expectation.

  • value (Object)

    The actual value which was supplied to the Ward matcher.

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
# File 'lib/ward/spec/matcher_matcher.rb', line 33

def self.error_message(result, matcher, value)
  status = if result.to_sym == :pass then 'failed' else 'passed' end

  expected = unless matcher.expected.nil?
    "expected: #{matcher.expected.inspect}, "
  end

  "expected #{matcher.class.inspect} matcher to #{result}, but it " \
  "#{status} (#{expected}actual: #{value.inspect})"
end