Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
rcov/ruby/1.8/gems/rspec-mocks-2.5.0/lib/rspec/mocks/error_generator.rb | 97 | 77 | 42.27%
|
28.57%
|
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.
1 module RSpec |
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 = 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_similar_message_args_error(expectation, *args) |
27 expected_args = format_args(*expectation.expected_args) |
28 actual_args = args.collect {|a| format_args(*a)}.join(", ") |
29 __raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}" |
30 end |
31 |
32 def raise_expectation_error(sym, expected_received_count, actual_received_count, *args) |
33 __raise "(#{intro}).#{sym}#{format_args(*args)}\n expected: #{count_message(expected_received_count)}\n received: #{count_message(actual_received_count)}" |
34 end |
35 |
36 def raise_out_of_order_error(sym) |
37 __raise "#{intro} received :#{sym} out of order" |
38 end |
39 |
40 def raise_block_failed_error(sym, detail) |
41 __raise "#{intro} received :#{sym} but passed block failed with: #{detail}" |
42 end |
43 |
44 def raise_missing_block_error(args_to_yield) |
45 __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed" |
46 end |
47 |
48 def raise_wrong_arity_error(args_to_yield, arity) |
49 __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}" |
50 end |
51 |
52 private |
53 |
54 def intro |
55 if @name |
56 "#{@declared_as} #{@name.inspect}" |
57 elsif Mock === @target |
58 @declared_as |
59 elsif Class === @target |
60 "<#{@target.inspect} (class)>" |
61 elsif @target |
62 @target |
63 else |
64 "nil" |
65 end |
66 end |
67 |
68 def __raise(message) |
69 message = opts[:message] unless opts[:message].nil? |
70 Kernel::raise(RSpec::Mocks::MockExpectationError, message) |
71 end |
72 |
73 def arg_message(*args) |
74 " with " + format_args(*args) |
75 end |
76 |
77 def format_args(*args) |
78 args.empty? ? "(no args)" : "(" + arg_list(*args) + ")" |
79 end |
80 |
81 def arg_list(*args) |
82 args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ") |
83 end |
84 |
85 def count_message(count) |
86 return "at least #{pretty_print(count.abs)}" if count < 0 |
87 return pretty_print(count) |
88 end |
89 |
90 def pretty_print(count) |
91 "#{count} time#{count == 1 ? '' : 's'}" |
92 end |
93 |
94 end |
95 end |
96 end |
97 |
Generated on Fri Apr 22 17:22:41 -0700 2011 with rcov 0.9.8