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
-
.error_message(result, matcher, value) ⇒ String
Formats error messages for spec failures.
Class Method Details
.error_message(result, matcher, value) ⇒ String
Formats error messages for spec failures.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ward/spec/matcher_matcher.rb', line 33 def self.(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 |