changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/matchers/respond_to.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 Matchers
3
4 class RespondTo #:nodoc:
5 def initialize(*names)
6 @names = names
7 @names_not_responded_to = []
8 end
9
10 def matches?(target)
11 @names.each do |name|
12 unless target.respond_to?(name)
13 @names_not_responded_to << name
14 end
15 end
16 return @names_not_responded_to.empty?
17 end
18
19 def failure_message
20 "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
21 end
22
23 def negative_failure_message
24 "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
25 end
26
27 def description
28 "respond to ##{@names.to_s}"
29 end
30 end
31
32 # :call-seq:
33 # should respond_to(*names)
34 # should_not respond_to(*names)
35 #
36 # Matches if the target object responds to all of the names
37 # provided. Names can be Strings or Symbols.
38 #
39 # == Examples
40 #
41 def respond_to(*names)
42 Matchers::RespondTo.new(*names)
43 end
44 end
45end