soaspec 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 648bba6578889b06fd5b8c3a1871e2dff381eb5e
4
- data.tar.gz: 8b508b96c93f1928a222c3c7a4980d23438aae12
3
+ metadata.gz: 9fa5a1248a62fb5ce03d9b24d914dfa98c978e28
4
+ data.tar.gz: 601743d42c8399edb5a34e82c9569a35b7f7522e
5
5
  SHA512:
6
- metadata.gz: b76fcbd53b8be2780a0dc64af8cf59a04ac07b1e68c91ffdb9814aeea3e4cbdc442510ef88a88991d1c914b011a567d4b260b8a07e22c52e95e419f57d9e3616
7
- data.tar.gz: 18e2478c0df3c22b3c247fb2ffe974987bb5a1e14979c67ce049d056889d6cab944945a486069906774fc30ce32798d3a64d3f71afb5cfa0a1303d4d0ea6f819
6
+ metadata.gz: a3237657f1be3b97ecd7de2fe1f093fe7d024cf18b0d4f8e51879595b5aa7218270fd83eca07da23f2bf354c92625263c89ece87f7fd5664c59099593c4e06e1
7
+ data.tar.gz: a8d4aab8cbf8825512e197915655277e64033c453d346b5bca10c2ea7623a668282a481f47caf4c666e52d5890e852af50cf42c6eddd9819c8159bb93afe9f61
data/ChangeLog CHANGED
@@ -1,9 +1,14 @@
1
+ Version 0.0.10 / 2018-1-21
2
+ * Enhancements
3
+ * Added [] method to perform xpath assertion
4
+ * Using Savon xpath. No need to explicitly provide namespace for xpath
5
+
1
6
  Version 0.0.9 / 2018-1-20
2
7
  * Refactoring
3
8
  * class_options -> savon_options - More specific
4
9
  * default_operation -> operation - Not default anymore so better not in name
5
10
  * Enhancements
6
- * Made mandatory_xpath_values method to add to 'success sceanarios' shared example
11
+ * Made mandatory_xpath_values method to add to 'success scenarios' shared example
7
12
 
8
13
  Version 0.0.8 / 2018-1-19
9
14
  * Enhancements
data/Gemfile CHANGED
@@ -4,10 +4,11 @@ git_source(:gitlab) { |repo_name| "https://gitlab.com/samuel-garratt/soaspec" }
4
4
 
5
5
  # Specify your gem's dependencies in soaspec.gemspec
6
6
  gemspec
7
- gem 'rspec'
8
7
  gem 'rest-client'
9
8
  gem 'savon'
10
9
  gem 'require_all'
11
10
  gem 'nokogiri'
12
11
  gem 'rake', '12.2.1'
12
+ gem 'rspec'
13
+ gem 'rspec-its'
13
14
  gem 'rspec_junit_formatter'
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.9)
4
+ soaspec (0.0.10)
5
5
  rest-client (>= 2.0)
6
6
  rspec (~> 3.0)
7
+ rspec-its (>= 1.2.0)
7
8
  savon (>= 2)
8
9
 
9
10
  GEM
@@ -55,6 +56,9 @@ GEM
55
56
  rspec-expectations (3.7.0)
56
57
  diff-lcs (>= 1.2.0, < 2.0)
57
58
  rspec-support (~> 3.7.0)
59
+ rspec-its (1.2.0)
60
+ rspec-core (>= 3.0.0)
61
+ rspec-expectations (>= 3.0.0)
58
62
  rspec-mocks (3.7.0)
59
63
  diff-lcs (>= 1.2.0, < 2.0)
60
64
  rspec-support (~> 3.7.0)
@@ -89,6 +93,7 @@ DEPENDENCIES
89
93
  require_all
90
94
  rest-client
91
95
  rspec
96
+ rspec-its
92
97
  rspec_junit_formatter
93
98
  savon
94
99
  soaspec!
@@ -2,12 +2,12 @@ require 'rest-client' # REST
2
2
  require 'erb' # Embedded ruby
3
3
  require 'yaml' # Reading yaml
4
4
  require 'rspec' # Testing framework
5
+ require 'rspec/its'
5
6
  require 'savon' # SOAP
6
7
  require 'nokogiri' # XPath
7
8
  require 'date'
8
9
 
9
10
  require 'soaspec/version'
10
- require 'soaspec/common'
11
11
  require 'soaspec/basic_soap_handler'
12
12
  require 'soaspec/tester'
13
13
  require 'soaspec/exchange'
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'yaml'
3
- require_relative 'common'
4
3
  require_relative 'tester'
5
4
  require_relative 'hash_methods'
6
5
 
@@ -9,8 +8,6 @@ module Soaspec
9
8
  class BasicSoapHandler < Tester
10
9
  # Savon client used to make SOAP calls
11
10
  attr_accessor :client
12
- # Namespaces used in XML body
13
- attr_accessor :namespaces
14
11
  # SOAP Operation to use by default
15
12
  attr_accessor :operation
16
13
 
@@ -57,7 +54,6 @@ module Soaspec
57
54
  options.merge! savon_options
58
55
  options.merge!(specific_options)
59
56
  @client = Savon.client(options)
60
- self.namespaces = {}
61
57
  @name = name
62
58
  end
63
59
 
@@ -91,10 +87,6 @@ module Soaspec
91
87
  @name
92
88
  end
93
89
 
94
- def include?(value)
95
- @xml_response.include? value
96
- end
97
-
98
90
  def default_hash=(hash)
99
91
  @request_option = :hash
100
92
  @default_hash = hash
@@ -123,5 +115,16 @@ module Soaspec
123
115
  nil
124
116
  end
125
117
 
118
+ def xpath_value_for(param)
119
+ result = param[:exchange].response.xpath(param[:xpath]).first
120
+ raise 'No value at Xpath' unless result
121
+ result.inner_text
122
+ end
123
+
124
+ def value_from_path(exchange, path)
125
+ path = '//' + path if path[0] != '/'
126
+ xpath_value_for(exchange: exchange, xpath: path)
127
+ end
128
+
126
129
  end
127
130
  end
@@ -3,10 +3,6 @@ require_relative '../soaspec'
3
3
  # This represents a request / response pair
4
4
  class Exchange
5
5
 
6
- attr_reader :xml_response
7
-
8
- attr_reader :xml_doc
9
-
10
6
  def initialize(name, override_parameters = {})
11
7
  @test_name = name.to_s
12
8
  @api_class = Soaspec::Environment.api_handler
@@ -23,10 +19,6 @@ class Exchange
23
19
  # @return [String] Name given when initializing
24
20
  def to_s
25
21
  @response = make_request
26
- if @api_class.class < Soaspec::BasicSoapHandler
27
- @xml_response = @response.to_xml
28
- @xml_doc = @response.doc
29
- end
30
22
  @test_name
31
23
  end
32
24
 
@@ -40,15 +32,25 @@ class Exchange
40
32
  @api_class.mandatory_xpath_values
41
33
  end
42
34
 
43
- # Returns Savon response
35
+ # Returns response object from Api
36
+ # For example for SOAP it will be a Savon response
44
37
  # response.body (body of response as Hash)
45
38
  # response.header (head of response as Hash)
46
39
  def response
47
40
  @response
48
41
  end
49
42
 
43
+ # Get status code from api class. This is http response for Web Api
44
+ # @return [Integer] Status code from api class
50
45
  def status_code
51
46
  @api_class.status_code_for(@response)
52
47
  end
53
48
 
49
+ # Extract value from path api class
50
+ # @param [String] path Path to return element for api class E.g - for SOAP this is XPath
51
+ # @return [String] Value at path
52
+ def [](path)
53
+ @api_class.value_from_path(self, path)
54
+ end
55
+
54
56
  end
@@ -47,4 +47,25 @@ class Hash
47
47
  result != []
48
48
  end
49
49
 
50
+ # Loop through each item within a key within a Hash if the key exists
51
+ # @param [Key] Key within hash to iterate through
52
+ def each_if_not_null(key)
53
+ case key.class.to_s
54
+ when 'String'
55
+ if self[key]
56
+ self[key].each do |list_item|
57
+ yield(list_item)
58
+ end
59
+ end
60
+ when 'Array'
61
+ if self[key[0]]
62
+ if self[key[0]][key[1]]
63
+ self[key[0]][key[1]].each do |list_item|
64
+ yield(list_item)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
50
71
  end
@@ -1,13 +1,6 @@
1
1
 
2
2
  require_relative 'hash_methods'
3
3
 
4
- def xpath_for(param)
5
- # TODO: look a using Savon's xpath rather than converting to Nokogiri
6
- result = param[:exchange].xml_doc.at_xpath(param[:xpath], Soaspec::Environment.api_handler.namespaces)
7
- raise 'No value at Xpath' unless result
8
- result
9
- end
10
-
11
4
  RSpec::Matchers.define :contain_value do |expected|
12
5
  match do |actual|
13
6
  expect(actual.response.body.include_value?(expected)).to be true
@@ -30,13 +23,13 @@ end
30
23
 
31
24
  RSpec::Matchers.define :have_element_at_xpath do |xpath|
32
25
  match do |exchange|
33
- expect(xpath_for(exchange: exchange, xpath: xpath).content).not_to be_empty
26
+ expect(exchange[xpath]).not_to be_empty
34
27
  end
35
28
  end
36
29
 
37
30
  RSpec::Matchers.define :have_xpath_value do |expected_hash|
38
31
  match do |exchange|
39
- expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring
40
- expect(xpath_for(exchange: exchange, xpath: expected_hash.keys.first).content).to eq expected_hash.values.first
32
+ expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring
33
+ expect(exchange[expected_hash.keys.first]).to eq expected_hash.values.first
41
34
  end
42
35
  end
@@ -11,9 +11,9 @@ shared_examples_for 'success scenario' do
11
11
  end
12
12
  end
13
13
  end
14
- context 'has expected xpath values' do
15
- described_class.mandatory_xpath_values.each do |xpath_pair|
16
- it { is_expected.to have_xpath_value xpath_pair }
14
+ described_class.mandatory_xpath_values.each do |xpath, value|
15
+ it "has xpath '#{xpath}' equal to '#{value}'" do
16
+ expect(described_class).to have_xpath_value(xpath => value)
17
17
  end
18
18
  end
19
19
  end
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'yaml'
3
- require_relative 'common'
4
3
 
5
4
  module Soaspec
6
5
  # Has basic methods common for methods defining RSpec tests in YAML
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Helps to create RSpec specs for SOAP or REST apis }
13
13
  spec.description = %q{Helps to create RSpec specs for SOAP or REST apis. Easily represent multiple requests with
14
- the same }
14
+ the same configuration }
15
15
  spec.homepage = 'https://gitlab.com/samuel-garratt/soaspec'
16
16
  spec.license = 'MIT'
17
17
 
@@ -27,6 +27,7 @@ the same }
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_dependency 'rest-client', '>= 2.0' # REST
29
29
  spec.add_dependency 'rspec', '~> 3.0' # This framework is designed to work with RSpec
30
+ spec.add_dependency 'rspec-its', '>= 1.2.0'
30
31
  spec.add_dependency 'savon', '>= 2' # SOAP
31
32
 
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-20 00:00:00.000000000 Z
11
+ date: 2018-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: savon
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '2'
97
111
  description: "Helps to create RSpec specs for SOAP or REST apis. Easily represent
98
- multiple requests with\nthe same "
112
+ multiple requests with\nthe same configuration "
99
113
  email:
100
114
  - samuel.garratt@integrationqa.com
101
115
  executables:
@@ -118,7 +132,6 @@ files:
118
132
  - exe/soaspec-init
119
133
  - lib/soaspec.rb
120
134
  - lib/soaspec/basic_soap_handler.rb
121
- - lib/soaspec/common.rb
122
135
  - lib/soaspec/exchange.rb
123
136
  - lib/soaspec/hash_methods.rb
124
137
  - lib/soaspec/matchers.rb
@@ -1,24 +0,0 @@
1
- class Hash
2
-
3
- # Loop through each item within a key within a Hash if the key exists
4
- # @param [Key] Key within hash to iterate through
5
- def each_if_not_null(key)
6
- case key.class.to_s
7
- when 'String'
8
- if self[key]
9
- self[key].each do |list_item|
10
- yield(list_item)
11
- end
12
- end
13
- when 'Array'
14
- if self[key[0]]
15
- if self[key[0]][key[1]]
16
- self[key[0]][key[1]].each do |list_item|
17
- yield(list_item)
18
- end
19
- end
20
- end
21
- end
22
- end
23
-
24
- end