soaspec 0.0.6 → 0.0.7

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: 5c8b35235618cab8abce3be4ef5633cbae54968a
4
- data.tar.gz: 9f7aa825578f961704f2d97466aae64f692c7790
3
+ metadata.gz: 4b4452d636edba383d91b460bf2a53ea47957ec2
4
+ data.tar.gz: fa67e6a673bf4c1468570f30520e1ad79d764ad3
5
5
  SHA512:
6
- metadata.gz: 76fc37780aeecf08879871760d4571722d7350d6a28ab19752e036fac0ed0def0674310dbb4f319e961d60c6b98e002587744c67214de14e037e65f40d45c536
7
- data.tar.gz: 0ebb64c1dbf98c6160be64beb550b965e6d2eb42d44f82a1edc9ce7994c64c366e87d7a0544b698261a8c1051b90037bd37c619c31f549b16403e7ec0b1c53c9
6
+ metadata.gz: 49b74f30a8f0bce484e0993be7214c1ffdf69cf38bde63bed506f1434bce94b16a8cf1f708d90092a239f675cb76e156c74f3c496c0aba89a0e296155cc5f22f
7
+ data.tar.gz: b3290ad9ed129d0628565d762a920d833652824921b1e28927aa19ccf2979c6938a5146cd6934c77ec8d5e84f26a40fabed987b94f39e7a6ba8989533c14e071
@@ -0,0 +1,4 @@
1
+ Version 0.0.7 / 2018-1-19
2
+ * Enhancements
3
+ * Added contain_key matcher
4
+ * mandatory_elements method created for SoapHandler - can be used to add tests to success scenarios (see example get_weather_web_service class for details)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soaspec (0.0.6)
4
+ soaspec (0.0.7)
5
5
  rest-client (>= 2.0)
6
6
  rspec (~> 3.0)
7
7
  savon (>= 2)
@@ -101,5 +101,15 @@ module Soaspec
101
101
  @default_hash = hash
102
102
  end
103
103
 
104
+ def status_code_for(response)
105
+ response.http.code
106
+ end
107
+
108
+ # Override this to specify elements that must be present in the response
109
+ # Make it an Array of keys
110
+ def mandatory_elements
111
+ nil
112
+ end
113
+
104
114
  end
105
115
  end
@@ -21,7 +21,7 @@ class Exchange
21
21
  # Name describing this class when used with `RSpec.describe`
22
22
  # @return [String] Name given when initializing
23
23
  def to_s
24
- @response = self.make_request
24
+ @response = make_request
25
25
  if Soaspec::Environment.api_handler.class < Soaspec::BasicSoapHandler
26
26
  @xml_response = @response.to_xml
27
27
  @xml_doc = @response.doc
@@ -32,7 +32,11 @@ class Exchange
32
32
  def contain(value)
33
33
  @xml_response.include? value
34
34
  end
35
-
35
+
36
+ def mandatory_elements
37
+ Soaspec::Environment.api_handler.mandatory_elements
38
+ end
39
+
36
40
  # Returns Savon response
37
41
  # response.body (body of response as Hash)
38
42
  # response.header (head of response as Hash)
@@ -41,7 +45,7 @@ class Exchange
41
45
  end
42
46
 
43
47
  def status_code
44
- @response.http.code
48
+ Soaspec::Environment.api_handler.status_code_for(@response)
45
49
  end
46
50
 
47
51
  end
@@ -15,12 +15,22 @@ class Hash
15
15
 
16
16
  # Value present in nested Hash
17
17
  def include_value?(value)
18
- self.each_value do |v|
18
+ each_value do |v|
19
19
  return true if v == value
20
- if v.is_a? Hash
21
- v.each_value do |v|
22
- return true if v == value
23
- end
20
+ next unless v.is_a? Hash
21
+ v.each_value do |v|
22
+ return true if v == value
23
+ end
24
+ end
25
+ false
26
+ end
27
+
28
+ def include_key?(key)
29
+ each do |k, v|
30
+ return true if k == key
31
+ next unless v.is_a? Hash
32
+ v.each do |k, v|
33
+ return true if k == key
24
34
  end
25
35
  end
26
36
  false
@@ -11,6 +11,16 @@ RSpec::Matchers.define :contain_value do |expected|
11
11
  end
12
12
  end
13
13
 
14
+ RSpec::Matchers.define :contain_key do |expected|
15
+ match do |actual|
16
+ expect(actual.response.body.include_key?(expected)).to be true
17
+ end
18
+
19
+ failure_message do |actual|
20
+ "expected that #{actual.response.body} would contain key #{expected}"
21
+ end
22
+ end
23
+
14
24
  RSpec::Matchers.define :have_element_at_xpath do |expected|
15
25
  match do |exchange|
16
26
  expect(exchange.xml_doc.at_xpath(expected, Soaspec::Environment.api_handler.namespaces).content).not_to be_empty
@@ -4,4 +4,13 @@ shared_examples_for 'success scenario' do
4
4
  it 'has status code of 200' do
5
5
  expect(described_class.status_code).to eq 200
6
6
  end
7
+ if described_class.mandatory_elements
8
+ context 'has expected mandatory elements' do
9
+ described_class.mandatory_elements.each do |mandatory_element|
10
+ it "#{mandatory_element} element" do
11
+ expect(described_class).to contain_key mandatory_element
12
+ end
13
+ end
14
+ end
15
+ end
7
16
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
@@ -107,6 +107,7 @@ files:
107
107
  - ".rspec"
108
108
  - ".travis.yml"
109
109
  - CODE_OF_CONDUCT.md
110
+ - ChangeLog
110
111
  - Gemfile
111
112
  - Gemfile.lock
112
113
  - LICENSE.txt