Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/respond_to.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/respond_to.rb 85 59
48.24%
30.51%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module RSpec
2   module Matchers
3     
4     class RespondTo #:nodoc:
5       def initialize(*names)
6         @names = names
7         @expected_arity = nil
8       end
9       
10       def matches?(actual)
11         find_failing_method_names(actual, :reject).empty?
12       end
13 
14       def does_not_match?(actual)
15         find_failing_method_names(actual, :select).empty?
16       end
17       
18       def failure_message_for_should
19         "expected #{@actual.inspect} to respond to #{@failing_method_names.collect {|name| name.inspect }.join(', ')}#{with_arity}"
20       end
21       
22       def failure_message_for_should_not
23         failure_message_for_should.sub(/to respond to/, 'not to respond to')
24       end
25       
26       def description
27         "respond to #{pp_names}#{with_arity}"
28       end
29       
30       def with(n)
31         @expected_arity = n
32         self
33       end
34       
35       def argument
36         self
37       end
38       alias :arguments :argument
39       
40     private
41 
42       def find_failing_method_names(actual, filter_method)
43         @actual = actual
44         @failing_method_names = @names.send(filter_method) do |name|
45           @actual.respond_to?(name) && matches_arity?(actual, name)
46         end
47       end
48       
49       def matches_arity?(actual, name)
50         return true unless @expected_arity
51 
52         actual_arity = actual.method(name).arity
53         if actual_arity < 0
54           # ~ inverts the one's complement and gives us the number of required args
55           ~actual_arity <= @expected_arity
56         else
57           actual_arity == @expected_arity
58         end
59       end
60       
61       def with_arity
62         @expected_arity.nil?? "" :
63           " with #{@expected_arity} argument#{@expected_arity == 1 ? '' : 's'}"
64       end
65       
66       def pp_names
67         # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
68         @names.length == 1 ? "##{@names.first}" : @names.inspect
69       end
70     end
71     
72     # :call-seq:
73     #   should respond_to(*names)
74     #   should_not respond_to(*names)
75     #
76     # Matches if the target object responds to all of the names
77     # provided. Names can be Strings or Symbols.
78     #
79     # == Examples
80     # 
81     def respond_to(*names)
82       Matchers::RespondTo.new(*names)
83     end
84   end
85 end

Generated on Fri Apr 22 17:22:41 -0700 2011 with rcov 0.9.8