lib/soaspec/exchange.rb in soaspec-0.0.75 vs lib/soaspec/exchange.rb in soaspec-0.0.76

- old
+ new

@@ -37,10 +37,12 @@ attr_accessor :exchange_handler # How many times to retry for a success attr_accessor :retry_count # Name used for displaying class attr_accessor :test_name + # Expect Factory to fail upon trying to create + attr_writer :fail_factory # Set retry for success variable to true so that request will be retried # for retry_count until it's true def retry_for_success @retry_for_success = true @@ -78,10 +80,11 @@ def initialize(name = self.class.to_s, override_parameters = {}) self.test_name ||= name.to_s # As a last resort this uses the global parameter. The handler should be set straight before an exchange is made to use this @exchange_handler ||= default_handler_used || Soaspec.api_handler raise '@exchange_handler not set. Set either with `Soaspec.api_handler = Handler.new` or within the exchange' unless @exchange_handler + @fail_factory = nil @override_parameters = override_parameters @retry_for_success = false self.retry_count = 3 @exchange_handler.elements.each { |element| methods_for_element(element) } end @@ -102,15 +105,15 @@ # 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 = @override_parameters - retry_count.times do - response = @exchange_handler.make_request(request_params) + (1..retry_count).each do |count| + response = exchange_handler.make_request(request_params) return response unless retry_for_success? return response if (200..299).cover? @exchange_handler.status_code_for(response) - response + break response if count == retry_count end end # Stores a value in the api handler that can be accessed by the provided name # @param [Symbol] name Name of method to use to access this value within handler @@ -210,10 +213,10 @@ # Makes request, caching the response and returning self # Used by FactoryBot # @return [Self] def save! - @retry_for_success = true # Assume using Factory you'll want a positive response + @retry_for_success = @fail_factory ? false : true call self end end \ No newline at end of file