Module: Pact::Provider::TestMethods
- Includes:
- Logging, Rack::Test::Methods
- Defined in:
- lib/pact/provider/test_methods.rb
Instance Method Summary collapse
- #get_provider_state(provider_state_name, consumer) ⇒ Object
- #parse_body_from_response(rack_response) ⇒ Object
- #replay_interaction(interaction) ⇒ Object
- #set_up_provider_state(provider_state_name, consumer) ⇒ Object
- #tear_down_provider_state(provider_state_name, consumer) ⇒ Object
Methods included from Logging
Instance Method Details
#get_provider_state(provider_state_name, consumer) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pact/provider/test_methods.rb', line 46 def get_provider_state provider_state_name, consumer unless provider_state = ProviderState.get(provider_state_name, :for => consumer) extra = consumer ? " for consumer \"#{consumer}\"" : "" error_msg = <<-eos Could not find a provider state named \"#{provider_state_name}\"#{extra}. Have you required the provider states file for this consumer in your pact_helper.rb? If you have not yet defined a provider state for \"#{provider_state_name}\", here is a template: Pact.provider_states_for \"#{consumer}\" do provider_state \"#{provider_state_name}\" do set_up do # Your set up code goes here end end end eos raise error_msg end provider_state end |
#parse_body_from_response(rack_response) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/pact/provider/test_methods.rb', line 25 def parse_body_from_response rack_response case rack_response.headers['Content-Type'] when /json/ JSON.load(rack_response.body) else rack_response.body end end |
#replay_interaction(interaction) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pact/provider/test_methods.rb', line 14 def replay_interaction interaction request = Request::Replayable.new(interaction.request) args = [request.path, request.body, request.headers] logger.info "Sending #{request.method} request to path: \"#{request.path}\" with headers: #{request.headers}, see debug logs for body" logger.debug "body :#{request.body}" response = self.send(request.method, *args) logger.info "Received response with status: #{response.status}, headers: #{response.headers}, see debug logs for body" logger.debug "body: #{response.body}" end |
#set_up_provider_state(provider_state_name, consumer) ⇒ Object
34 35 36 37 38 |
# File 'lib/pact/provider/test_methods.rb', line 34 def set_up_provider_state provider_state_name, consumer if provider_state_name get_provider_state(provider_state_name, consumer).set_up end end |
#tear_down_provider_state(provider_state_name, consumer) ⇒ Object
40 41 42 43 44 |
# File 'lib/pact/provider/test_methods.rb', line 40 def tear_down_provider_state provider_state_name, consumer if provider_state_name get_provider_state(provider_state_name, consumer).tear_down end end |