Rspec Steps C0 Coverage Information - RCov

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

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/rspec-expectations-2.5.0/lib/rspec/matchers/include.rb 54 32
92.59%
87.50%

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     # :call-seq:
4     #   should include(expected)
5     #   should_not include(expected)
6     #
7     # Passes if actual includes expected. This works for
8     # collections and Strings. You can also pass in multiple args
9     # and it will only pass if all args are found in collection.
10     #
11     # == Examples
12     #
13     #   [1,2,3].should include(3)
14     #   [1,2,3].should include(2,3) #would pass
15     #   [1,2,3].should include(2,3,4) #would fail
16     #   [1,2,3].should_not include(4)
17     #   "spread".should include("read")
18     #   "spread".should_not include("red")
19     def include(*expected)
20       Matcher.new :include, *expected do |*_expected|
21 
22         diffable
23 
24         match_for_should do |actual|
25           perform_match(:all?, :all?, actual, _expected)
26         end
27 
28         match_for_should_not do |actual|
29           perform_match(:none?, :any?, actual, _expected)
30         end
31 
32         def perform_match(predicate, hash_predicate, actual, _expected)
33           _expected.send(predicate) do |expected|
34             if comparing_hash_values?(actual, expected)
35               expected.send(hash_predicate) {|k,v| actual[k] == v}
36             elsif comparing_hash_keys?(actual, expected)
37               actual.has_key?(expected)
38             else
39               actual.include?(expected)
40             end
41           end
42         end
43 
44         def comparing_hash_keys?(actual, expected) # :nodoc:
45           actual.is_a?(Hash) && !expected.is_a?(Hash)
46         end
47 
48         def comparing_hash_values?(actual, expected) # :nodoc:
49           actual.is_a?(Hash) && expected.is_a?(Hash)
50         end
51       end
52     end
53   end
54 end

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