Class: Pact::MockService::Session

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Session

Returns a new instance of Session.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pact/mock_service/session.rb', line 14

def initialize options
  @pact_written = false
  @logger = options[:logger]
  @expected_interactions = Interactions::ExpectedInteractions.new
  @actual_interactions = Interactions::ActualInteractions.new
  @verified_interactions = Interactions::VerifiedInteractions.new
  @warn_on_too_many_interactions = options[:warn_on_too_many_interactions] || false
  @max_concurrent_interactions_before_warning = get_max_concurrent_interactions_before_warning
  @consumer_contract_details = {
    pact_dir: options[:pact_dir],
    consumer: {name: options[:consumer]},
    provider: {name: options[:provider]},
    interactions: verified_interactions,
    pact_specification_version: options[:pact_specification_version],
    pactfile_write_mode: options[:pactfile_write_mode]
  }
end

Instance Attribute Details

#actual_interactionsObject (readonly)

Returns the value of attribute actual_interactions.



12
13
14
# File 'lib/pact/mock_service/session.rb', line 12

def actual_interactions
  @actual_interactions
end

#consumer_contract_detailsObject (readonly)

Returns the value of attribute consumer_contract_details.



12
13
14
# File 'lib/pact/mock_service/session.rb', line 12

def consumer_contract_details
  @consumer_contract_details
end

#expected_interactionsObject (readonly)

Returns the value of attribute expected_interactions.



12
13
14
# File 'lib/pact/mock_service/session.rb', line 12

def expected_interactions
  @expected_interactions
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/pact/mock_service/session.rb', line 12

def logger
  @logger
end

#verified_interactionsObject (readonly)

Returns the value of attribute verified_interactions.



12
13
14
# File 'lib/pact/mock_service/session.rb', line 12

def verified_interactions
  @verified_interactions
end

Instance Method Details

#add_expected_interaction(interaction) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/pact/mock_service/session.rb', line 59

def add_expected_interaction interaction
  if (previous_interaction = interaction_already_verified_with_same_description_and_provider_state_but_not_equal(interaction))
    handle_almost_duplicate_interaction previous_interaction, interaction
  else
    really_add_expected_interaction interaction
  end
end

#clear_allObject



52
53
54
55
56
57
# File 'lib/pact/mock_service/session.rb', line 52

def clear_all
  expected_interactions.clear
  actual_interactions.clear
  verified_interactions.clear
  @pact_written = false
end

#clear_expected_and_actual_interactionsObject



47
48
49
50
# File 'lib/pact/mock_service/session.rb', line 47

def clear_expected_and_actual_interactions
  expected_interactions.clear
  actual_interactions.clear
end

#pact_written?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pact/mock_service/session.rb', line 32

def pact_written?
  @pact_written
end

#record_pact_writtenObject



36
37
38
# File 'lib/pact/mock_service/session.rb', line 36

def record_pact_written
  @pact_written = true
end

#set_expected_interactions(interactions) ⇒ Object



40
41
42
43
44
45
# File 'lib/pact/mock_service/session.rb', line 40

def set_expected_interactions interactions
  clear_expected_and_actual_interactions
  interactions.each do | interaction |
    add_expected_interaction interaction
  end
end