Parent

Class Index [+]

Quicksearch

Spec::Mocks::ErrorGenerator

Attributes

opts[W]

Public Class Methods

new(target, name, options={}) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 6
 6:       def initialize(target, name, options={})
 7:         @declared_as = options[:__declared_as] || 'Mock'
 8:         @target = target
 9:         @name = name
10:       end

Public Instance Methods

opts() click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 12
12:       def opts
13:         @opts ||= {}
14:       end
raise_block_failed_error(sym, detail) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 34
34:       def raise_block_failed_error(sym, detail)
35:         __raise "#{intro} received :#{sym} but passed block failed with: #{detail}"
36:       end
raise_expectation_error(sym, expected_received_count, actual_received_count, *args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 26
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
raise_missing_block_error(args_to_yield) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 38
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
raise_out_of_order_error(sym) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 30
30:       def raise_out_of_order_error(sym)
31:         __raise "#{intro} received :#{sym} out of order"
32:       end
raise_unexpected_message_args_error(expectation, *args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 20
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
raise_unexpected_message_error(sym, *args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 16
16:       def raise_unexpected_message_error(sym, *args)
17:         __raise "#{intro} received unexpected message :#{sym}#{arg_message(*args)}"
18:       end
raise_wrong_arity_error(args_to_yield, arity) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 42
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

Private Instance Methods

__raise(message) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 62
62:       def __raise(message)
63:         message = opts[:message] unless opts[:message].nil?
64:         Kernel::raise(Spec::Mocks::MockExpectationError, message)
65:       end
arg_list(*args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 75
75:       def arg_list(*args)
76:         args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
77:       end
arg_message(*args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 67
67:       def arg_message(*args)
68:         " with " + format_args(*args)
69:       end
count_message(count) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 79
79:       def count_message(count)
80:         return "at least #{pretty_print(count.abs)}" if count < 0
81:         return pretty_print(count)
82:       end
format_args(*args) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 71
71:       def format_args(*args)
72:         args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
73:       end
intro() click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 48
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
pretty_print(count) click to toggle source
    # File lib/spec/mocks/error_generator.rb, line 84
84:       def pretty_print(count)
85:         return "once" if count == 1
86:         return "twice" if count == 2
87:         return "#{count} times"
88:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.