Geminstaller C0 Coverage Information - RCov

/Users/woolley/.rvm/gems/ruby-1.8.7-p174@geminstaller/gems/rspec-1.3.0/lib/spec/mocks/error_generator.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/mocks/error_generator.rb 92 74
45.65%
33.78%

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 Mocks
3     class ErrorGenerator
4       attr_writer :opts
5       
6       def initialize(target, name, options={})
7         @declared_as = options[:__declared_as] || 'Mock'
8         @target = target
9         @name = name
10       end
11       
12       def opts
13         @opts ||= {}
14       end
15 
16       def raise_unexpected_message_error(sym, *args)
17         __raise "#{intro} received unexpected message :#{sym}#{arg_message(*args)}"
18       end
19       
20       def raise_unexpected_message_args_error(expectation, *args)
21         expected_args = format_args(*expectation.expected_args)
22         actual_args = args.empty? ? "(no args)" : format_args(*args)
23         __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
24       end
25       
26       def raise_expectation_error(sym, expected_received_count, actual_received_count, *args)
27         __raise "#{intro} expected :#{sym}#{arg_message(*args)} #{count_message(expected_received_count)}, but received it #{count_message(actual_received_count)}"
28       end
29       
30       def raise_out_of_order_error(sym)
31         __raise "#{intro} received :#{sym} out of order"
32       end
33       
34       def raise_block_failed_error(sym, detail)
35         __raise "#{intro} received :#{sym} but passed block failed with: #{detail}"
36       end
37       
38       def raise_missing_block_error(args_to_yield)
39         __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
40       end
41       
42       def raise_wrong_arity_error(args_to_yield, arity)
43         __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
44       end
45       
46     private
47 
48       def intro
49         if @name
50           "#{@declared_as} #{@name.inspect}"
51         elsif Mock === @target
52           @declared_as
53         elsif Class === @target
54           "<#{@target.inspect} (class)>"
55         elsif @target
56           @target
57         else
58           "nil"
59         end
60       end
61       
62       def __raise(message)
63         message = opts[:message] unless opts[:message].nil?
64         Kernel::raise(Spec::Mocks::MockExpectationError, message)
65       end
66       
67       def arg_message(*args)
68         " with " + format_args(*args)
69       end
70       
71       def format_args(*args)
72         args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
73       end
74 
75       def arg_list(*args)
76         args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
77       end
78       
79       def count_message(count)
80         return "at least #{pretty_print(count.abs)}" if count < 0
81         return pretty_print(count)
82       end
83 
84       def pretty_print(count)
85         return "once" if count == 1
86         return "twice" if count == 2
87         return "#{count} times"
88       end
89 
90     end
91   end
92 end

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