Class: Pact::MockService::Interactions::InteractionMismatch::CandidateDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/mock_service/interactions/interaction_mismatch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(candidate_interaction, actual_request) ⇒ CandidateDiff

Returns a new instance of CandidateDiff.



41
42
43
44
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 41

def initialize candidate_interaction, actual_request
  @candidate_interaction = candidate_interaction
  @actual_request = actual_request
end

Instance Attribute Details

#actual_requestObject

Returns the value of attribute actual_request.



39
40
41
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 39

def actual_request
  @actual_request
end

#candidate_interactionObject

Returns the value of attribute candidate_interaction.



39
40
41
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 39

def candidate_interaction
  @candidate_interaction
end

Instance Method Details

#diffObject



67
68
69
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 67

def diff
  @diff ||= candidate_interaction.request.difference(actual_request)
end

#diff_formatterObject



63
64
65
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 63

def diff_formatter
  Pact.configuration.diff_formatter_for_content_type(candidate_interaction.request.content_type)
end

#mismatched_attributesObject



46
47
48
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 46

def mismatched_attributes
  diff.keys
end

#to_hashObject



50
51
52
53
54
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 50

def to_hash
  summary = {:description => candidate_interaction.description}
  summary[:provider_state] = candidate_interaction.provider_state if candidate_interaction.provider_state
  summary.merge(diff)
end

#to_sObject



56
57
58
59
60
61
# File 'lib/pact/mock_service/interactions/interaction_mismatch.rb', line 56

def to_s
  [
    "Diff with interaction: #{candidate_interaction.description_with_provider_state_quoted}",
    diff_formatter.call(diff, **{colour: false})
  ].join("\n")
end