Class: Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/soaspec/exchange.rb

Overview

This represents a request / response pair

Instance Method Summary collapse

Constructor Details

#initialize(name, override_parameters = {}) ⇒ Exchange

Returns a new instance of Exchange.



6
7
8
9
10
# File 'lib/soaspec/exchange.rb', line 6

def initialize(name, override_parameters = {})
  @test_name = name.to_s
  @api_class = Soaspec::Environment.api_handler
  @override_parameters = override_parameters
end

Instance Method Details

#[](path) ⇒ String

Extract value from path api class

Parameters:

  • path (String)

    Path to return element for api class E.g - for SOAP this is XPath

Returns:

  • (String)

    Value at path



53
54
55
# File 'lib/soaspec/exchange.rb', line 53

def [](path)
  @api_class.value_from_path(self, path)
end

#make_requestObject

Make request to handler with parameters defined



13
14
15
# File 'lib/soaspec/exchange.rb', line 13

def make_request
  @api_class.make_request(@override_parameters)
end

#mandatory_elementsObject

Elements a shared ‘success scenario’ is expected to have



27
28
29
# File 'lib/soaspec/exchange.rb', line 27

def mandatory_elements
  @api_class.mandatory_elements
end

#mandatory_xpath_valuesObject

Elements a shared ‘success scenario’ is expected to have



32
33
34
# File 'lib/soaspec/exchange.rb', line 32

def mandatory_xpath_values
  @api_class.mandatory_xpath_values
end

#responseObject

Returns response object from Api For example for SOAP it will be a Savon response response.body (body of response as Hash) response.header (head of response as Hash)



40
41
42
# File 'lib/soaspec/exchange.rb', line 40

def response
  @response
end

#status_codeInteger

Get status code from api class. This is http response for Web Api

Returns:

  • (Integer)

    Status code from api class



46
47
48
# File 'lib/soaspec/exchange.rb', line 46

def status_code
  @api_class.status_code_for(@response)
end

#to_sString

Name describing this class when used with RSpec.describe This will make the request and store the response

Returns:

  • (String)

    Name given when initializing



20
21
22
23
24
# File 'lib/soaspec/exchange.rb', line 20

def to_s
  Soaspec::SpecLogger.add_to 'Example ' + @test_name
  @response = make_request
  @test_name
end