Class: Exchange

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

Overview

This represents a request / response pair

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Exchange.



8
9
10
11
12
# File 'lib/soaspec/exchange.rb', line 8

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

Instance Attribute Details

#api_classObject (readonly)

Returns the value of attribute api_class.



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

def api_class
  @api_class
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



55
56
57
# File 'lib/soaspec/exchange.rb', line 55

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

#make_requestObject

Make request to handler with parameters defined



15
16
17
# File 'lib/soaspec/exchange.rb', line 15

def make_request
  @api_class.make_request(@override_parameters)
end

#mandatory_elementsObject

Elements a shared ‘success scenario’ is expected to have



29
30
31
# File 'lib/soaspec/exchange.rb', line 29

def mandatory_elements
  @api_class.mandatory_elements
end

#mandatory_xpath_valuesObject

Elements a shared ‘success scenario’ is expected to have



34
35
36
# File 'lib/soaspec/exchange.rb', line 34

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)



42
43
44
# File 'lib/soaspec/exchange.rb', line 42

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



48
49
50
# File 'lib/soaspec/exchange.rb', line 48

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



22
23
24
25
26
# File 'lib/soaspec/exchange.rb', line 22

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