Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/matchers/change.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/change.rb 151 79
60.93%
27.85%

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     
4     #Based on patch from Wilson Bilkovich
5     class Change #:nodoc:
6       def initialize(receiver=nil, message=nil, &block)
7         @message = message || "result"
8         @value_proc = block || lambda {receiver.__send__(message)}
9         @to = @from = @minimum = @maximum = @amount = nil
10       end
11       
12       def matches?(event_proc)
13         raise_block_syntax_error if block_given?
14         
15         @before = evaluate_value_proc
16         event_proc.call
17         @after = evaluate_value_proc
18         
19         return (@to = false) if @from unless @from == @before
20         return false if @to unless @to == @after
21         return (@before + @amount == @after) if @amount
22         return ((@after - @before) >= @minimum) if @minimum
23         return ((@after - @before) <= @maximum) if @maximum        
24         return @before != @after
25       end
26       
27       def raise_block_syntax_error
28         raise MatcherError.new(<<-MESSAGE
29 block passed to should or should_not change must use {} instead of do/end
30 MESSAGE
31         )
32       end
33       
34       def evaluate_value_proc
35         @value_proc.call
36       end
37       
38       def failure_message_for_should
39         if @to
40           "#{@message} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
41         elsif @from
42           "#{@message} should have initially been #{@from.inspect}, but was #{@before.inspect}"
43         elsif @amount
44           "#{@message} should have been changed by #{@amount.inspect}, but was changed by #{actual_delta.inspect}"
45         elsif @minimum
46           "#{@message} should have been changed by at least #{@minimum.inspect}, but was changed by #{actual_delta.inspect}"
47         elsif @maximum
48           "#{@message} should have been changed by at most #{@maximum.inspect}, but was changed by #{actual_delta.inspect}"
49         else
50           "#{@message} should have changed, but is still #{@before.inspect}"
51         end
52       end
53       
54       def actual_delta
55         @after - @before
56       end
57       
58       def failure_message_for_should_not
59         "#{@message} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
60       end
61       
62       def by(amount)
63         @amount = amount
64         self
65       end
66       
67       def by_at_least(minimum)
68         @minimum = minimum
69         self
70       end
71       
72       def by_at_most(maximum)
73         @maximum = maximum
74         self
75       end      
76       
77       def to(to)
78         @to = to
79         self
80       end
81       
82       def from (from)
83         @from = from
84         self
85       end
86       
87       def description
88         "change ##{@message}"
89       end
90     end
91     
92     # :call-seq:
93     #   should change(receiver, message, &block)
94     #   should change(receiver, message, &block).by(value)
95     #   should change(receiver, message, &block).from(old).to(new)
96     #   should_not change(receiver, message, &block)
97     #
98     # Allows you to specify that a Proc will cause some value to change.
99     #
100     # == Examples
101     #
102     #   lambda {
103     #     team.add_player(player) 
104     #   }.should change(roster, :count)
105     #
106     #   lambda {
107     #     team.add_player(player) 
108     #   }.should change(roster, :count).by(1)
109     #
110     #   lambda {
111     #     team.add_player(player) 
112     #   }.should change(roster, :count).by_at_least(1)
113     #
114     #   lambda {
115     #     team.add_player(player)
116     #   }.should change(roster, :count).by_at_most(1)    
117     #
118     #   string = "string"
119     #   lambda {
120     #     string.reverse!
121     #   }.should change { string }.from("string").to("gnirts")
122     #
123     #   lambda {
124     #     person.happy_birthday
125     #   }.should change(person, :birthday).from(32).to(33)
126     #       
127     #   lambda {
128     #     employee.develop_great_new_social_networking_app
129     #   }.should change(employee, :title).from("Mail Clerk").to("CEO")
130     #
131     # Evaluates <tt>receiver.message</tt> or <tt>block</tt> before and after
132     # it evaluates the c object (generated by the lambdas in the examples
133     # above).
134     #
135     # Then compares the values before and after the <tt>receiver.message</tt>
136     # and evaluates the difference compared to the expected difference.
137     #
138     # == WARNING
139     # <tt>should_not change</tt> only supports the form with no
140     # subsequent calls to <tt>by</tt>, <tt>by_at_least</tt>,
141     # <tt>by_at_most</tt>, <tt>to</tt> or <tt>from</tt>.
142     #
143     # blocks passed to <tt>should</tt> <tt>change</tt> and <tt>should_not</tt>
144     # <tt>change</tt> must use the <tt>{}</tt> form (<tt>do/end</tt> is not
145     # supported).
146     #
147     def change(receiver=nil, message=nil, &block)
148       Matchers::Change.new(receiver, message, &block)
149     end
150   end
151 end

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