lib/soaspec.rb in soaspec-0.0.46 vs lib/soaspec.rb in soaspec-0.0.47

- old
+ new

@@ -9,10 +9,11 @@ require 'jsonpath' require 'soaspec/version' require 'soaspec/exchange_handlers/soap_handler' require 'soaspec/exchange_handlers/exchange_handler' +require 'soaspec/exchange_handlers/rest_methods' require 'soaspec/exchange' require 'soaspec/matchers' require 'soaspec/soaspec_shared_examples' require 'soaspec/hash_methods' require 'soaspec/spec_logger' @@ -23,132 +24,56 @@ require 'soaspec/not_found_errors' # Gem for handling SOAP and REST api tests module Soaspec - # Folder used to store credentials - # Used in auth2_file command - # @param [String] folder - def self.credentials_folder=(folder) - @credentials_folder = folder - end + class << self - # Credentials folder used to store secret data (not in source control) E.g passwords - def self.credentials_folder - @credentials_folder - end + # Folder used to store credentials + # Used in auth2_file command + # @param [String] folder + def credentials_folder=(folder) + @credentials_folder = folder + end - # Used so that exchange class knows what context it's in - # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this - def self.api_handler=(handler) - @api_handler = handler - end + # Credentials folder used to store secret data (not in source control) E.g passwords + def credentials_folder + @credentials_folder + end - def self.api_handler - @api_handler - end - - # Whether to transform strings to keys automatically - def self.always_use_keys=(use_keys) - @always_use_keys = use_keys - end - - def self.always_use_keys? - @always_use_keys || true - end - - # Whether to remove namespaces from response in Xpath assertion automatically - # For why this may not be a good thing in general see - # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html - # This will be overridden if xpath has a ':' in it - def self.strip_namespaces=(remove_namespaces_from_response) - @strip_namespaces = remove_namespaces_from_response - end - - # Whether to remove namespaces in xpath assertion automatically - def self.strip_namespaces? - @strip_namespaces || false - end - - # -Deprecated- for favour of putting directly in Soaspec - # Represents Environment parameters used in Soaspec tests - module Environment - # Used so that exchange class knows what context it's in - def self.api_handler=(handler) - Soaspec.api_handler = handler + # @param [ExchangeHandler] handler A class inheriting from Soaspec::ExchangeHandler. Exchange class uses this + def api_handler=(handler) + @api_handler = handler end - def self.api_handler - Soaspec.api_handler + def api_handler + @api_handler end - # Whether to transform strings to keys automatically - def self.always_use_keys=(use_keys) - Soaspec.always_use_keys = use_keys + # Set whether to transform strings to keys in request automatically + # @param [Boolean] use_keys + def always_use_keys=(use_keys) + @always_use_keys = use_keys end - def self.always_use_keys? - Soaspec.always_use_keys? || true + # @return [Boolean] Whether to transform strings to keys in request automatically + def always_use_keys? + @always_use_keys || true end # Whether to remove namespaces from response in Xpath assertion automatically # For why this may not be a good thing in general see # http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html # This will be overridden if xpath has a ':' in it - def self.strip_namespaces=(remove_namespaces_from_response) - Soaspec.strip_namespaces = remove_namespaces_from_response + def strip_namespaces=(remove_namespaces) + @strip_namespaces = remove_namespaces end # Whether to remove namespaces in xpath assertion automatically - def self.strip_namespaces? - Soaspec.strip_namespaces? || false + def strip_namespaces? + @strip_namespaces || false end - end - - # Contains commonly used REST methods - module RestMethods - # Make REST Post Exchange - # @param [String] name Name of test displayed - # @param [Hash] params Exchange parameters - # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body - def post(name, params = {}) - Exchange.new(name, method: :post, **params) - end - - # Make REST Patch Exchange - # @param [String] name Name of test displayed - # @param [Hash] params Exchange parameters - # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body - def patch(name, params = {}) - Exchange.new(name, method: :patch, **params) - end - - # Make REST Put Exchange - # @param [String] name Name of test displayed - # @param [Hash] params Exchange parameters - # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body - def put(name, params = {}) - Exchange.new(name, method: :put, **params) - end - - # Make REST Get Exchange - # @param [String] name Name of test displayed - # @param [Hash] params Exchange parameters - # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body - def get(name, params = {}) - Exchange.new(name, method: :get, **params) - end - - # Make REST Delete Exchange - # @param [String] name Name of test displayed - # @param [Hash] params Exchange parameters - # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body - def delete(name, params = {}) - Exchange.new(name, method: :delete, **params) - end - end - end RestClient.log = Soaspec::SpecLogger.create