Module: Pact::Provider::TestMethods
- Includes:
- Logging, Rack::Test::Methods
- Defined in:
- lib/pact/provider/test_methods.rb
Instance Method Summary collapse
- #parse_body_from_response(rack_response) ⇒ Object
- #replay_interaction(interaction, request_customizer = nil, state_params = nil) ⇒ Object
- #set_metadata(example, key, value) ⇒ Object
- #set_up_provider_states(provider_states, consumer, options = {}) ⇒ Object
- #tear_down_provider_states(provider_states, consumer, options = {}) ⇒ Object
Instance Method Details
#parse_body_from_response(rack_response) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pact/provider/test_methods.rb', line 33 def parse_body_from_response rack_response case rack_response.headers['Content-Type'] when /json/ # For https://github.com/pact-foundation/pact-net/issues/237 # Only required for the pact-ruby-standalone ¯\_(ツ)_/¯ JSON.load("[#{rack_response.body}]").first else rack_response.body end end |
#replay_interaction(interaction, request_customizer = nil, state_params = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pact/provider/test_methods.rb', line 17 def replay_interaction interaction, request_customizer = nil, state_params = nil request = Request::Replayable.new(interaction.request, state_params) request = request_customizer.call(request, interaction) if request_customizer args = [request.path, request.body, request.headers] logger.info "Sending #{request.method.upcase} request to path: \"#{request.path}\" with headers: #{request.headers}, see debug logs for body" logger.debug "body :#{request.body}" response = if self.respond_to?(:custom_request) self.custom_request(request.method.upcase, *args) else self.send(request.method.downcase, *args) end logger.info "Received response with status: #{response.status}, headers: #{response.headers}, see debug logs for body" logger.debug "body: #{response.body}" end |
#set_metadata(example, key, value) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/pact/provider/test_methods.rb', line 66 def example, key, value Pact::RSpec.with_rspec_3 do example.[key] = value end Pact::RSpec.with_rspec_2 do example.example.[key] = value end end |
#set_up_provider_states(provider_states, consumer, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pact/provider/test_methods.rb', line 44 def set_up_provider_states provider_states, consumer, = {} provider_states_result = {}; # If there are no provider state, execute with an nil state to ensure global and base states are executed Pact.configuration.provider_state_set_up.call(nil, consumer, ) if provider_states.nil? || provider_states.empty? provider_states.each do | provider_state | result = Pact.configuration.provider_state_set_up.call(provider_state.name, consumer, .merge(params: provider_state.params)) if result.is_a?(Hash) provider_states_result[provider_state.name] = result end end provider_states_result end |
#tear_down_provider_states(provider_states, consumer, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/pact/provider/test_methods.rb', line 58 def tear_down_provider_states provider_states, consumer, = {} # If there are no provider state, execute with an nil state to ensure global and base states are executed Pact.configuration.provider_state_tear_down.call(nil, consumer, ) if provider_states.nil? || provider_states.empty? provider_states.reverse_each do | provider_state | Pact.configuration.provider_state_tear_down.call(provider_state.name, consumer, .merge(params: provider_state.params)) end end |