Parent

RSpec::Mocks::ErrorGenerator

@private

Attributes

opts[W]

Public Class Methods

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

Public Instance Methods

opts() click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 14
14:       def opts
15:         @opts ||= {}
16:       end
raise_block_failed_error(message, detail) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 48
48:       def raise_block_failed_error(message, detail)
49:         __raise "#{intro} received :#{message} but passed block failed with: #{detail}"
50:       end
raise_expectation_error(message, expected_received_count, actual_received_count, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 38
38:       def raise_expectation_error(message, expected_received_count, actual_received_count, *args)
39:         __raise "(#{intro}).#{message}#{format_args(*args)}\n    expected: #{count_message(expected_received_count)}\n    received: #{count_message(actual_received_count)}"
40:       end
raise_missing_block_error(args_to_yield) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 53
53:       def raise_missing_block_error(args_to_yield)
54:         __raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
55:       end
raise_out_of_order_error(message) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 43
43:       def raise_out_of_order_error(message)
44:         __raise "#{intro} received :#{message} out of order"
45:       end
raise_similar_message_args_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 31
31:       def raise_similar_message_args_error(expectation, *args)
32:         expected_args = format_args(*expectation.expected_args)
33:         actual_args = args.collect {|a| format_args(*a)}.join(", ")
34:         __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
35:       end
raise_unexpected_message_args_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 24
24:       def raise_unexpected_message_args_error(expectation, *args)
25:         expected_args = format_args(*expectation.expected_args)
26:         actual_args = format_args(*args)
27:         __raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n  expected: #{expected_args}\n       got: #{actual_args}"
28:       end
raise_unexpected_message_error(message, *args) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 19
19:       def raise_unexpected_message_error(message, *args)
20:         __raise "#{intro} received unexpected message :#{message}#{arg_message(*args)}"
21:       end
raise_wrong_arity_error(args_to_yield, arity) click to toggle source

@private

    # File lib/rspec/mocks/error_generator.rb, line 58
58:       def raise_wrong_arity_error(args_to_yield, arity)
59:         __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
60:       end

Private Instance Methods

__raise(message) click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 78
78:       def __raise(message)
79:         message = opts[:message] unless opts[:message].nil?
80:         Kernel::raise(RSpec::Mocks::MockExpectationError, message)
81:       end
arg_list(*args) click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 91
91:       def arg_list(*args)
92:         args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
93:       end
arg_message(*args) click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 83
83:       def arg_message(*args)
84:         " with " + format_args(*args)
85:       end
count_message(count) click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 95
95:       def count_message(count)
96:         return "at least #{pretty_print(count.abs)}" if count < 0
97:         return pretty_print(count)
98:       end
format_args(*args) click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 87
87:       def format_args(*args)
88:         args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
89:       end
intro() click to toggle source
    # File lib/rspec/mocks/error_generator.rb, line 64
64:       def intro
65:         if @name
66:           "#{@declared_as} #{@name.inspect}"
67:         elsif TestDouble === @target
68:           @declared_as
69:         elsif Class === @target
70:           "<#{@target.inspect} (class)>"
71:         elsif @target
72:           @target
73:         else
74:           "nil"
75:         end
76:       end
pretty_print(count) click to toggle source
     # File lib/rspec/mocks/error_generator.rb, line 100
100:       def pretty_print(count)
101:         "#{count} time#{count == 1 ? '' : 's'}"
102:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.