Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb 133 36
81.20%
30.56%

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 Spec
2   module Matchers
3     class SimpleMatcher
4       attr_writer :failure_message, :negative_failure_message, :description
5       
6       def initialize(description, &match_block)
7         @description = description
8         @match_block = match_block
9         @failure_message = @negative_failure_message = nil
10       end
11 
12       def matches?(given)
13         @given = given
14         case @match_block.arity
15         when 2
16           @match_block.call(@given, self)
17         else
18           @match_block.call(@given)
19         end
20       end
21       
22       def description
23         @description || explanation
24       end
25 
26       def failure_message_for_should
27         @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
28       end
29 
30       def failure_message_for_should_not
31         @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
32       end
33 
34       def explanation
35         "No description provided. See RDoc for simple_matcher()"
36       end
37     end
38   
39     # simple_matcher makes it easy for you to create your own custom matchers
40     # in just a few lines of code when you don't need all the power of a
41     # completely custom matcher object.
42     #
43     # The <tt>description</tt> argument will appear as part of any failure
44     # message, and is also the source for auto-generated descriptions.
45     #
46     # The <tt>match_block</tt> can have an arity of 1 or 2. The first block
47     # argument will be the given value. The second, if the block accepts it
48     # will be the matcher itself, giving you access to set custom failure
49     # messages in favor of the defaults.
50     #
51     # The <tt>match_block</tt> should return a boolean: <tt>true</tt>
52     # indicates a match, which will pass if you use <tt>should</tt> and fail
53     # if you use <tt>should_not</tt>. false (or nil) indicates no match,
54     # which will do the reverse: fail if you use <tt>should</tt> and pass if
55     # you use <tt>should_not</tt>.
56     #
57     # An error in the <tt>match_block</tt> will bubble up, resulting in a
58     # failure.
59     #
60     # == Example with default messages
61     #
62     #   def be_even
63     #     simple_matcher("an even number") { |given| given % 2 == 0 }
64     #   end
65     #                    
66     #   describe 2 do
67     #     it "should be even" do
68     #       2.should be_even
69     #     end
70     #   end
71     #
72     # Given an odd number, this example would produce an error message stating:
73     # expected "an even number", got 3.
74     #
75     # Unfortunately, if you're a fan of auto-generated descriptions, this will
76     # produce "should an even number." Not the most desirable result. You can
77     # control that using custom messages:
78     #
79     # == Example with custom messages
80     #
81     #   def rhyme_with(expected)
82     #     simple_matcher("rhyme with #{expected.inspect}") do |given, matcher|
83     #       matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
84     #       matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
85     #       given.rhymes_with? expected
86     #     end
87     #   end
88     #
89     #   # OR
90     #
91     #   def rhyme_with(expected)
92     #     simple_matcher do |given, matcher|
93     #       matcher.description = "rhyme with #{expected.inspect}"
94     #       matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
95     #       matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
96     #       given.rhymes_with? expected
97     #     end
98     #   end
99     #
100     #   describe "pecan" do
101     #     it "should rhyme with 'be gone'" do
102     #       nut = "pecan"
103     #       nut.extend Rhymer
104     #       nut.should rhyme_with("be gone")
105     #     end
106     #   end
107     #
108     # The resulting messages would be:
109     #   description:              rhyme with "be gone"
110     #   failure_message:          expected "pecan" to rhyme with "be gone"
111     #   negative failure_message: expected "pecan" not to rhyme with "be gone"
112     #
113     # == Wrapped Expectations
114     #
115     # Because errors will bubble up, it is possible to wrap other expectations
116     # in a SimpleMatcher.
117     #
118     #   def be_even
119     #     simple_matcher("an even number") { |given| (given % 2).should == 0 }
120     #   end
121     #
122     # BE VERY CAREFUL when you do this. Only use wrapped expectations for
123     # matchers that will always be used in only the positive
124     # (<tt>should</tt>) or negative (<tt>should_not</tt>), but not both.
125     # The reason is that is you wrap a <tt>should</tt> and call the wrapper
126     # with <tt>should_not</tt>, the correct result (the <tt>should</tt>
127     # failing), will fail when you want it to pass.
128     #
129     def simple_matcher(description=nil, &match_block)
130       SimpleMatcher.new(description, &match_block)
131     end
132   end
133 end

Generated on Mon May 10 23:40:27 -0700 2010 with rcov 0.9.8