6
def initialize(target, name)
15
def raise_unexpected_message_error(sym, *args)
16
__raise "#{intro} received unexpected message :#{sym}#{arg_message(*args)}"
19
def raise_unexpected_message_args_error(expectation, *args)
20
expected_args = format_args(*expectation.expected_args)
21
actual_args = args.empty? ? "(no args)" : format_args(*args)
22
__raise "#{intro} expected #{expectation.sym.inspect} with #{expected_args} but received it with #{actual_args}"
25
def raise_expectation_error(sym, expected_received_count, actual_received_count, *args)
26
__raise "#{intro} expected :#{sym}#{arg_message(*args)} #{count_message(expected_received_count)}, but received it #{count_message(actual_received_count)}"
29
def raise_out_of_order_error(sym)
30
__raise "#{intro} received :#{sym} out of order"
33
def raise_block_failed_error(sym, detail)
34
__raise "#{intro} received :#{sym} but passed block failed with: #{detail}"
37
def raise_missing_block_error(args_to_yield)
38
__raise "#{intro} asked to yield |#{arg_list(*args_to_yield)}| but no block was passed"
41
def raise_wrong_arity_error(args_to_yield, arity)
42
__raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
47
@name ? "Mock '#{@name}'" : @target.inspect
51
message = opts[:message] unless opts[:message].nil?
52
Kernel::raise(Spec::Mocks::MockExpectationError, message)
55
def arg_message(*args)
56
" with " + format_args(*args)
59
def format_args(*args)
60
return "(no args)" if args.empty? || args == [:no_args]
61
return "(any args)" if args == [:any_args]
62
"(" + arg_list(*args) + ")"
67
arg.respond_to?(:description) ? arg.description : arg.inspect
71
def count_message(count)
72
return "at least #{pretty_print(count.abs)}" if count < 0
73
return pretty_print(count)
76
def pretty_print(count)
77
return "once" if count == 1
78
return "twice" if count == 2
79
return "#{count} times"