Class: RSpec::Covers::Probe::CallLog

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/covers/probe/call_log_probe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calls:, returns_by_object_id:, expectations: []) ⇒ CallLog

Returns a new instance of CallLog.



25
26
27
28
29
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 25

def initialize(calls:, returns_by_object_id:, expectations: [])
  @calls = calls
  @returns_by_object_id = returns_by_object_id
  @expectations = expectations
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



23
24
25
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 23

def calls
  @calls
end

#expectationsObject (readonly)

Returns the value of attribute expectations.



23
24
25
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 23

def expectations
  @expectations
end

#returns_by_object_idObject (readonly)

Returns the value of attribute returns_by_object_id.



23
24
25
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 23

def returns_by_object_id
  @returns_by_object_id
end

Instance Method Details

#calls_before_expectationsObject



35
36
37
38
39
40
41
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 35

def calls_before_expectations
  expectations.filter_map do |expectation|
    next if expectation.call_index.to_i <= 0

    calls[expectation.call_index - 1]
  end
end

#expectation_object_idsObject



51
52
53
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 51

def expectation_object_ids
  expectations.map(&:actual_object_id)
end

#labelsObject



47
48
49
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 47

def labels
  calls.map(&:label)
end

#labels_before_expectationsObject



43
44
45
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 43

def labels_before_expectations
  calls_before_expectations.map(&:label).uniq
end

#last_callObject



31
32
33
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 31

def last_call
  calls.last
end

#return_labels_for(object_ids) ⇒ Object



55
56
57
# File 'lib/rspec/covers/probe/call_log_probe.rb', line 55

def return_labels_for(object_ids)
  object_ids.flat_map { |object_id| returns_by_object_id.fetch(object_id, []) }.uniq
end