webspicy 0.11.2 → 0.12.0

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: 6fba27996b7cbe7a2fa50068ee0c03e1474f1acf
4
- data.tar.gz: 5c08a417338a79a18b37d529937721fe05b9ccde
3
+ metadata.gz: 6d78c07ceefb51e2e501878a3c7e85abd6b9497a
4
+ data.tar.gz: 027aec45632f053e971203a2d8b6ab5d1b20fa9b
5
5
  SHA512:
6
- metadata.gz: e9e1c6f11170c2f6f8a79a4a910bf1dacc65a3f7d3df69b528f48db0062871ef5c039a7803f35771ae5c56f38f8f76ba56975d5fd5c1d27a72ace0e57800ff4e
7
- data.tar.gz: 298faf4ab3202ae045921da9a005185a3779644cc951b218f4575ee6dc8d82ac12f4a29a96db375b44abcd23b48cc9874c8b34aea05f6d14a981e789a9032dcf
6
+ metadata.gz: ebb4af1b2860f2569c18d282b9fcf2c367b6465411f57d7c01848100118412267876f68cf520b2c537610c1435aa78d4304cefdc0f2f3c9ac09ec0b91f644937
7
+ data.tar.gz: b743850dc46e00e2e3e2a077e028a6d352a0c378492c34fd471346f3586e0407a309aab1dd4127ff1c5a0625bf8d189068839dbb7cab5de6443c57f6909d015a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- webspicy (0.11.2)
4
+ webspicy (0.12.0)
5
5
  finitio (~> 0.6, >= 0.6.1)
6
6
  http (~> 2)
7
7
  path (~> 1.3)
@@ -24,6 +24,11 @@ services:
24
24
  error_schema: |-
25
25
  ErrorSchema
26
26
 
27
+ default_example:
28
+ expected:
29
+ content_type: application/json
30
+ status: 200
31
+
27
32
  examples:
28
33
 
29
34
  - description: |-
@@ -31,9 +36,6 @@ services:
31
36
  params:
32
37
  id: 1
33
38
  description: 'hello world'
34
- expected:
35
- content_type: application/json
36
- status: 200
37
39
  assert:
38
40
  - "pathFD('', description: 'hello world')"
39
41
 
@@ -30,13 +30,14 @@ Service =
30
30
  output_schema : Schema
31
31
  error_schema : Schema
32
32
  blackbox :? String
33
+ default_example :? TestCase
33
34
  examples :? [TestCase]
34
35
  counterexamples :? [TestCase]
35
36
  }
36
37
 
37
38
  TestCase =
38
39
  .Webspicy::Resource::Service::TestCase <info> {
39
- description : String
40
+ description :? String
40
41
  dress_params :? Boolean
41
42
  params :? Params
42
43
  headers :? .Hash
@@ -45,13 +46,13 @@ TestCase =
45
46
  seeds :? String
46
47
  requester :? String
47
48
  metadata :? { ...: .Object }
48
- expected: {
49
- status : Integer
49
+ expected :? {
50
+ status :? Integer
50
51
  content_type :? String|Nil
51
52
  error :? String
52
53
  headers :? .Hash
53
54
  }
54
- assert :? [String]
55
+ assert :? [String]
55
56
  }
56
57
 
57
58
  Params = .Array|.Hash
@@ -53,16 +53,20 @@ module Webspicy
53
53
  file_upload ? file_upload.locate(resource) : nil
54
54
  end
55
55
 
56
+ def expected
57
+ @raw[:expected] || {}
58
+ end
59
+
56
60
  def expected_content_type
57
- @raw[:expected].fetch(:content_type){ 'application/json' }
61
+ expected.fetch(:content_type){ 'application/json' }
58
62
  end
59
63
 
60
64
  def expected_status
61
- @raw[:expected][:status]
65
+ expected[:status]
62
66
  end
63
67
 
64
68
  def expected_error
65
- @raw[:expected][:error]
69
+ expected[:error]
66
70
  end
67
71
 
68
72
  def has_expected_error?
@@ -70,7 +74,7 @@ module Webspicy
70
74
  end
71
75
 
72
76
  def expected_headers
73
- @raw[:expected][:headers] || {}
77
+ expected[:headers] || {}
74
78
  end
75
79
 
76
80
  def has_expected_headers?
@@ -35,6 +35,10 @@ module Webspicy
35
35
  !postconditions.empty?
36
36
  end
37
37
 
38
+ def default_example
39
+ @raw[:default_example]
40
+ end
41
+
38
42
  def examples
39
43
  @raw[:examples]
40
44
  end
@@ -47,16 +47,22 @@ module Webspicy
47
47
  end
48
48
 
49
49
  def each_example(service)
50
- service.examples.each{|s| yield(s, false) }
50
+ service.examples.each{|e|
51
+ yield(expand_example(service, e), false)
52
+ }
51
53
  end
52
54
 
53
55
  def each_counterexamples(service, &bl)
54
- service.counterexamples.each{|s| yield(s, true) } if config.run_counterexamples?
56
+ service.counterexamples.each{|e|
57
+ yield(expand_example(service, e), true)
58
+ } if config.run_counterexamples?
55
59
  end
56
60
 
57
61
  def each_generated_counterexamples(service, &bl)
58
62
  Webspicy.with_scope(self) do
59
- service.generated_counterexamples.each{|s| yield(s, true) }
63
+ service.generated_counterexamples.each{|e|
64
+ yield(expand_example(service, e), true)
65
+ }
60
66
  end if config.run_counterexamples?
61
67
  end
62
68
 
@@ -117,6 +123,25 @@ module Webspicy
117
123
 
118
124
  private
119
125
 
126
+ def expand_example(service, example)
127
+ return example unless service.default_example
128
+ h1 = service.default_example.to_info
129
+ h2 = example.to_info
130
+ ex = Resource::Service::TestCase.new(merge_maps(h1, h2))
131
+ ex.service = service
132
+ ex
133
+ end
134
+
135
+ def merge_maps(h1, h2)
136
+ h1.merge(h2) do |k,v1,v2|
137
+ case v1
138
+ when Hash then merge_maps(v1, v2)
139
+ when Array then v1 + v2
140
+ else v2
141
+ end
142
+ end
143
+ end
144
+
120
145
  # Returns a proc that implements file_filter strategy according to the
121
146
  # type of filter installed
122
147
  def to_filter_proc(filter)
@@ -1,8 +1,8 @@
1
1
  module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 11
5
- TINY = 2
4
+ MINOR = 12
5
+ TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ module Webspicy
3
+ describe Scope, "expand_example" do
4
+
5
+ subject{ Scope.new({}).send(:expand_example, service, example) }
6
+
7
+ context 'when the service has no default example' do
8
+ let(:service) {
9
+ Webspicy.service({
10
+ method: "GET",
11
+ description: "Test service",
12
+ preconditions: "Foo",
13
+ input_schema: "{ id: Integer }",
14
+ output_schema: "{}",
15
+ error_schema: "{}"
16
+ })
17
+ }
18
+
19
+ let(:example) {
20
+ Webspicy.test_case({
21
+ description: "Hello world"
22
+ })
23
+ }
24
+
25
+ it 'returns the example itself' do
26
+ expect(subject).to be(example)
27
+ end
28
+ end
29
+
30
+ context 'when the service has a default example' do
31
+ let(:service) {
32
+ Webspicy.service({
33
+ method: "GET",
34
+ description: "Test service",
35
+ preconditions: "Foo",
36
+ input_schema: "{ id: Integer }",
37
+ output_schema: "{}",
38
+ error_schema: "{}",
39
+ default_example: {
40
+ expected: { status: 200 }
41
+ }
42
+ })
43
+ }
44
+
45
+ let(:example) {
46
+ Webspicy.test_case({
47
+ description: "Hello world",
48
+ expected: { content_type: "application/json" }
49
+ })
50
+ }
51
+
52
+ it 'deep merges the default example and the example as expected' do
53
+ expect(subject).to be_a(Resource::Service::TestCase)
54
+ expect(subject.description).to eql("Hello world")
55
+ expect(subject.expected).to eql({
56
+ status: 200,
57
+ content_type: "application/json"
58
+ })
59
+ end
60
+ end
61
+
62
+ end
63
+ end # module Webspicy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-16 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -195,6 +195,7 @@ files:
195
195
  - spec/unit/resource/test_url_placeholders.rb
196
196
  - spec/unit/scope/test_each_resource.rb
197
197
  - spec/unit/scope/test_each_service.rb
198
+ - spec/unit/scope/test_expand_example.rb
198
199
  - spec/unit/scope/test_to_real_url.rb
199
200
  - spec/unit/spec_helper.rb
200
201
  - spec/unit/test_configuration.rb
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  version: '0'
222
223
  requirements: []
223
224
  rubyforge_project:
224
- rubygems_version: 2.5.2
225
+ rubygems_version: 2.6.11
225
226
  signing_key:
226
227
  specification_version: 4
227
228
  summary: Webspicy helps testing web services as software operation black boxes!