Skip to content

Commit

Permalink
feat(v3): support set up and tear down of multiple provider states
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 1, 2018
1 parent 6207520 commit cbad0be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/pact/provider/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def describe_interaction interaction, options
before do | example |
interaction_context.run_once :before do
Pact.configuration.logger.info "Running example '#{Pact::RSpec.full_description(example)}'"
set_up_provider_state interaction.provider_state, options[:consumer]
set_up_provider_states interaction.provider_states, options[:consumer]
replay_interaction interaction, options[:request_customizer]
interaction_context.last_response = last_response
end
end

after do
interaction_context.run_once :after do
tear_down_provider_state interaction.provider_state, options[:consumer]
tear_down_provider_states interaction.provider_states, options[:consumer]
end
end

Expand Down
12 changes: 8 additions & 4 deletions lib/pact/provider/test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ def parse_body_from_response rack_response
end
end

def set_up_provider_state provider_state_name, consumer, options = {}
Pact.configuration.provider_state_set_up.call(provider_state_name, consumer, options)
def set_up_provider_states provider_states, consumer, options = {}
provider_states.each do | provider_state |
Pact.configuration.provider_state_set_up.call(provider_state.name, consumer, options.merge(params: provider_state.params))
end
end

def tear_down_provider_state provider_state_name, consumer, options = {}
Pact.configuration.provider_state_tear_down.call(provider_state_name, consumer, options)
def tear_down_provider_states provider_states, consumer, options = {}
provider_states.reverse.each do | provider_state |
Pact.configuration.provider_state_tear_down.call(provider_state.name, consumer, options.merge(params: provider_state.params))
end
end

def set_metadata example, key, value
Expand Down

0 comments on commit cbad0be

Please sign in to comment.