Class: Synthesis::ExpectationRecord

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/synthesis/expectation_record.rb

Class Method Summary collapse

Methods included from Logging

silence!, speak!

Class Method Details

.[](matcher) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/synthesis/expectation_record.rb', line 35

def [](matcher)
  # Using a hash for faster look up of expectations 
  # when recording invocations
  expectations_with_return_values[matcher] ||
  expectations_without_return_values[matcher] ||
  Expectation::NilExpectation.new
end

.add_expectation(receiver, method, track, args = []) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/synthesis/expectation_record.rb', line 6

def add_expectation(receiver, method, track, args = [])
  unless ignore?(receiver)
    expectation = Expectation.new(receiver, method, track, args)
    expectations << expectation
    expectation
  end
end

.expectationsObject



22
23
24
25
26
27
28
29
# File 'lib/synthesis/expectation_record.rb', line 22

def expectations
  # Using an Array instead of a Set because the +Expectation+ instance 
  # is not complete when first added. A Set would result to possible duplicates.
  # obj.expects(:method).with(:args)
  # the +Expectation+ will be added when obj.expects(:method) is called
  # the +Expectation+ arguments will be added when .with(:args) is called
  @expectations ||= []
end

.has_untested_expectations?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/synthesis/expectation_record.rb', line 65

def has_untested_expectations?
  untested_expectations.any?
end

.ignore(*args) ⇒ Object



18
19
20
# File 'lib/synthesis/expectation_record.rb', line 18

def ignore(*args)
  ignored.merge(args)
end

.ignoredObject



31
32
33
# File 'lib/synthesis/expectation_record.rb', line 31

def ignored
  @ignored ||= Set.new
end

.record_invocationsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/synthesis/expectation_record.rb', line 43

def record_invocations
  expectations.map! { |e| e.explode }
  expectations.flatten!
  expectations.uniq!
  expectations.each do |e|
    e.record_invocations
    if e.return_values_defined?
      expectations_with_return_values[e] = e 
    else
      expectations_without_return_values[e] = e
    end
  end
end

.remove(expectation) ⇒ Object



14
15
16
# File 'lib/synthesis/expectation_record.rb', line 14

def remove(expectation)
  expectations.delete(expectation)
end

.tested_expectationsObject



57
58
59
# File 'lib/synthesis/expectation_record.rb', line 57

def tested_expectations
  expectations.select { |e| e.invoked? }
end

.untested_expectationsObject



61
62
63
# File 'lib/synthesis/expectation_record.rb', line 61

def untested_expectations
  expectations.select { |e| !e.invoked? }
end