Module: FlexMock::SpyDescribers

Extended by:
SpyDescribers
Included in:
CountValidator, RSpecMatchers::HaveReceived, SpyDescribers, TestUnitAssertions
Defined in:
lib/flexmock/spy_describers.rb

Instance Method Summary collapse

Instance Method Details

#append_call_record(result, call_record) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/flexmock/spy_describers.rb', line 44

def append_call_record(result, call_record)
  result <<
    "    " <<
    FlexMock.format_call(call_record.method_name, call_record.args)
  if call_record.expectation
    result <<
      " matched by " <<
      call_record.expectation.description
  end
  result << "\n"
end

#block_description(needs_block) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/flexmock/spy_describers.rb', line 71

def block_description(needs_block)
  case needs_block
  when true
    " with a block"
  when false
    " without a block"
  else
    ""
  end
end

#describe_calls(spy) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flexmock/spy_describers.rb', line 31

def describe_calls(spy)
  result = ''
  if spy.flexmock_calls.empty?
    result << "No messages have been received\n"
  else
    result << "The following messages have been received:\n"
    spy.flexmock_calls.each do |call_record|
      append_call_record(result, call_record)
    end
  end
  result
end

#describe_spy(spy, sym, args, options, not_clause = "") ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/flexmock/spy_describers.rb', line 20

def describe_spy(spy, sym, args, options, not_clause="")
  result = "expected "
  result << FlexMock.format_call(sym, args)
  result << " to#{not_clause} be received by " << spy.inspect
  result << times_description(options[:times])
  result << block_description(options[:with_block])
  result << ".\n"
  result << describe_calls(spy)
  result
end

#describe_spy_expectation(spy, sym, args, options = {}) ⇒ Object



12
13
14
# File 'lib/flexmock/spy_describers.rb', line 12

def describe_spy_expectation(spy, sym, args, options={})
  describe_spy(spy, sym, args, options)
end

#describe_spy_negative_expectation(spy, sym, args, options = {}) ⇒ Object



16
17
18
# File 'lib/flexmock/spy_describers.rb', line 16

def describe_spy_negative_expectation(spy, sym, args, options={})
  describe_spy(spy, sym, args, options, " NOT")
end

#spy_description(spy, sym, args, options) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/flexmock/spy_describers.rb', line 4

def spy_description(spy, sym, args, options)
  result = "have received "
  result << FlexMock.format_call(sym, args)
  result << times_description(options[:times])
  result << block_description(options[:with_block])
  result
end

#times_description(times) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/flexmock/spy_describers.rb', line 56

def times_description(times)
  case times
  when 0
    " never"
  when 1
    " once"
  when 2
    " twice"
  when nil
    ""
  else
    " #{times} times"
  end
end