soaspec 0.0.34 → 0.0.35

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: 2772080392ed404ebee4d3a0824f37e9571bfa3e
4
- data.tar.gz: a60560d10c60d210f73d9d5a8c41cac99c3537c4
3
+ metadata.gz: 4c7df2a27ca4097085513de2d9afa7d45e8eb9ff
4
+ data.tar.gz: 691d473c89b69df0dbb5fcb21ffdfe13c67dd236
5
5
  SHA512:
6
- metadata.gz: 8b1de42e0a49fae8cecf9062bd82fe9c9a4c097e6cc8b38e12055cf5dc8e45c2234eca0fd26c4275f27551708f717412b771d1e4558314f828f32e5753046042
7
- data.tar.gz: '080b93456d42b877b5f2d86d5a18e323310eedd11cd3cbbd159518aafbccbb3e8882c9a2afebff0d22fabcc7309dfd9b96532ad2fb6d47fa25183e8f5607b34d'
6
+ metadata.gz: 2a5a1e6b75df8eca6e4b03ac1e654e0d649c92dcbb72af84852115f5cdf3b8427697fdaf8a1aff779398c9d993e8734eeb4b0b2340a7e59e2956b15fd1178935
7
+ data.tar.gz: 38e3753dfaf0f7eeb859601777a3158019fa84cb5e0e1497b03cccc3143f6fd8b3f2b09ad0cce493c52fc46ff120d60ec0c319077747ec08e938d8e90a8fe4e4
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Version 0.0.35 / 2018-3-13
2
+ * Enhancements
3
+ * Handle array of JSON hashes starting with '['
4
+ * Handle patch and put methods with data for REST
5
+
1
6
  Version 0.0.34 / 2018-3-12
2
7
  * Enhancements
3
8
  * Add oauth2 and oauth2_file methods to make it easy to load oauth2 parameters. Still a work in progress to handle all oauth2 variations
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.34)
4
+ soaspec (0.0.35)
5
5
  jsonpath
6
6
  rest-client (>= 2.0)
7
7
  rspec (~> 3.0)
data/lib/soaspec.rb CHANGED
@@ -83,6 +83,22 @@ module Soaspec
83
83
  Exchange.new(name, method: :post, **params)
84
84
  end
85
85
 
86
+ # Make REST Patch Exchange
87
+ # @param [String] name Name of test displayed
88
+ # @param [Hash] params Exchange parameters
89
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
90
+ def patch(name, params = {})
91
+ Exchange.new(name, method: :patch, **params)
92
+ end
93
+
94
+ # Make REST Put Exchange
95
+ # @param [String] name Name of test displayed
96
+ # @param [Hash] params Exchange parameters
97
+ # @return [Exchange] Instance of Exchange class. Assertions are made by default on the response body
98
+ def put(name, params = {})
99
+ Exchange.new(name, method: :put, **params)
100
+ end
101
+
86
102
  # Make REST Get Exchange
87
103
  # @param [String] name Name of test displayed
88
104
  # @param [Hash] params Exchange parameters
@@ -12,6 +12,16 @@ module Soaspec
12
12
  end
13
13
  end
14
14
 
15
+ # Defines mandatory xpaths value pairs to be included in 'success scenario' shared example
16
+ #
17
+ # @example Inside class
18
+ # mandatory_xpath_values '//xmlns:GetWeatherResult' => 'Data Not Found'
19
+ #
20
+ # In test
21
+ # describe Exchange(:name) do
22
+ # it_behaves_like 'success scenario' # Includes xpath pair validation
23
+ # end
24
+ #
15
25
  def mandatory_xpath_values(xpath_value_pairs)
16
26
  raise ArgumentError('Hash of {xpath => expected values} expected ') unless xpath_value_pairs.is_a? Hash
17
27
  define_method('expected_mandatory_xpath_values') do
@@ -113,7 +113,7 @@ module Soaspec
113
113
 
114
114
  begin
115
115
  response = case test_values[:method]
116
- when :post
116
+ when :post, :patch, :put
117
117
  unless test_values[:payload]
118
118
  test_values[:payload] = JSON.generate(test_values[:body]).to_s if test_values[:body]
119
119
  end
@@ -150,7 +150,10 @@ module Soaspec
150
150
  raise ArgumentError("Empty Body. Can't assert on it") if response.body.empty?
151
151
  case Interpreter.response_type_for response
152
152
  when :json
153
- JSON.parse(response.body).transform_keys_to_symbols
153
+ converted = JSON.parse(response.body)
154
+ return converted.transform_keys_to_symbols if converted.is_a? Hash
155
+ return converted.map!(&:transform_keys_to_symbols) if converted.is_a? Array
156
+ raise 'Incorrect Type prodcued ' + converted.class
154
157
  when :xml
155
158
  parser = Nori.new(convert_tags_to: lambda { |tag| tag.snakecase.to_sym })
156
159
  parser.parse(response.body)
@@ -106,7 +106,7 @@ module Soaspec
106
106
  case format
107
107
  when :hash
108
108
  response.body
109
- when :xml
109
+ when :raw
110
110
  response.body.to_xml
111
111
  else
112
112
  response.body
@@ -1,4 +1,6 @@
1
1
 
2
+
3
+
2
4
  # Override Hash class with convience methods
3
5
  class Hash
4
6
 
@@ -76,4 +78,11 @@ class Hash
76
78
  end
77
79
  end
78
80
 
79
- end
81
+ end
82
+
83
+ class Array
84
+ # Call include key on 1st element of array
85
+ def include_key?(key)
86
+ first.include_key? key
87
+ end
88
+ end
@@ -9,7 +9,7 @@ class Interpreter
9
9
  case response.body[0]
10
10
  when '<'
11
11
  :xml
12
- when '{'
12
+ when '{', '['
13
13
  :json
14
14
  else
15
15
  :unknown
@@ -22,7 +22,7 @@ RSpec::Matchers.define :include_in_body do |expected|
22
22
  end
23
23
 
24
24
  failure_message do |actual|
25
- "expected that #{actual.api_class.response_body(actual.response, format: :xml)} would contain value #{expected}"
25
+ "expected that #{actual.api_class.response_body(actual.response, format: :raw)} would contain value #{expected}"
26
26
  end
27
27
  end
28
28
 
@@ -44,10 +44,12 @@ RSpec::Matchers.define :have_element_at_xpath do |xpath|
44
44
  end
45
45
 
46
46
  failure_message do |actual|
47
- "expected that #{actual.api_class.response_body(actual.response, format: :xml)} would have element at xpath '#{xpath}'"
47
+ "expected that #{actual.api_class.response_body(actual.response, format: :raw)} would have element at xpath '#{xpath}'"
48
48
  end
49
49
  end
50
50
 
51
+ RSpec::Matchers.alias_matcher :have_element_at_path, :have_element_at_xpath
52
+
51
53
  # Whether an element at xpath (defined by key) has value (defined by value).
52
54
  # @param [Hash] expected_hash Xpath => Value pair (e.g. '//xmlns:GetWeatherResult' => 'Data Not Found')
53
55
  RSpec::Matchers.define :have_xpath_value do |expected_hash|
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.34'
2
+ VERSION = '0.0.35'
3
3
  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.34
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-11 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler