changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/expectations/handler.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module Spec
2 module Expectations
3 class InvalidMatcherError < ArgumentError; end
4
5 module MatcherHandlerHelper
6 def describe_matcher(matcher)
7 matcher.respond_to?(:description) ? matcher.description : "[#{matcher.class.name} does not provide a description]"
8 end
9 end
10
11 class ExpectationMatcherHandler
12 class << self
13 include MatcherHandlerHelper
14 def handle_matcher(actual, matcher, &block)
15 unless matcher.respond_to?(:matches?)
16 raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
17 end
18
19 match = matcher.matches?(actual, &block)
20 ::Spec::Matchers.generated_description = "should #{describe_matcher(matcher)}"
21 Spec::Expectations.fail_with(matcher.failure_message) unless match
22 end
23 end
24 end
25
26 class NegativeExpectationMatcherHandler
27 class << self
28 include MatcherHandlerHelper
29 def handle_matcher(actual, matcher, &block)
30 unless matcher.respond_to?(:matches?)
31 raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
32 end
33
34 unless matcher.respond_to?(:negative_failure_message)
35 Spec::Expectations.fail_with(
36<<-EOF
37Matcher does not support should_not.
38See Spec::Matchers for more information
39about matchers.
40EOF
41)
42 end
43 match = matcher.matches?(actual, &block)
44 ::Spec::Matchers.generated_description = "should not #{describe_matcher(matcher)}"
45 Spec::Expectations.fail_with(matcher.negative_failure_message) if match
46 end
47 end
48 end
49
50 end
51end
52