lib/soaspec/exchange.rb in soaspec-0.0.64 vs lib/soaspec/exchange.rb in soaspec-0.0.65
- old
+ new
@@ -2,15 +2,13 @@
# This represents a request / response pair
class Exchange
# Class of Api Handler for which this exchange is made
- attr_reader :api_class
+ attr_accessor :api_class
# How many times to retry for a success
attr_accessor :retry_count
- # Params used when making a request
- attr_accessor :default_params
# Name used for displaying class
attr_accessor :test_name
# Set retry for success variable to true so that request will be retried
# for retry_count until it's true
@@ -46,27 +44,28 @@
end
end
end
end
- # Merge exchange initialized request params with ones set later on
- def merge_request_body
- if @override_parameters[:body] || default_params[:body]
- @override_parameters[:body] ||= {}
- @override_parameters[:body].merge!(default_params[:body])
- @override_parameters
- else
- @override_parameters.merge(default_params[:body])
- end
+ # Specify a url to add onto the base_url of the ExchangeHandler used
+ # @param [String] url Url to add onto the base_url of the ExchangeHandler used
+ def suburl=(url)
+ @override_parameters[:suburl] = url
end
+ # Specify HTTP method to use. Default is :post
+ # @param [Symbol] method HTTP method. E.g, :get, :patch
+ def method=(method)
+ @override_parameters[:method] = method
+ end
+
# Make request to handler with parameters defined
# Will retry until success code reached if retry_for_success? is set
# @return [Response] Response from Api handler
def make_request
Soaspec::SpecLogger.add_to 'Example ' + test_name
- request_params = default_params ? merge_request_body : @override_parameters
+ request_params = @override_parameters
retry_count.times do
response = @api_class.make_request(request_params)
return response unless retry_for_success?
return response if (200..299).cover? @api_class.status_code_for(response)
response
@@ -140,19 +139,19 @@
# Set a parameter request in the request body.
# Can be used to build a request over several steps (e.g Cucumber)
# Will be used with FactoryBot
def []=(key, value)
- self.default_params = { body: {} } unless default_params # Initialize as Hash if not set
- default_params[:body][key] = value
+ @override_parameters[:body] ||= {}
+ @override_parameters[:body][key] = value
end
# Implement undefined setter with []= for FactoryBot to use without needing to define params to set
# @param [Object] method_name
# @param [Object] args
# @param [Object] block
def method_missing(method_name, *args, &block)
- if method_name[-1] == '='
+ if method_name[-1] == '=' # A setter method
if args.first.class < Exchange # This would be prerequisite exchange
define_singleton_method(method_name[0..-2]) do
args.first
end
else
\ No newline at end of file