webspicy 0.16.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/bin/webspicy +6 -1
  4. data/doc/1-black-box-scene.md +109 -0
  5. data/doc/2-black-box-testing.md +27 -0
  6. data/doc/3-specification-importance.md +41 -0
  7. data/doc/4-sequence-diagram.md +82 -0
  8. data/lib/webspicy.rb +18 -9
  9. data/lib/webspicy/configuration.rb +57 -8
  10. data/lib/webspicy/configuration/scope.rb +22 -16
  11. data/lib/webspicy/formaldoc.fio +7 -5
  12. data/lib/webspicy/specification.rb +10 -9
  13. data/lib/webspicy/specification/condition.rb +48 -0
  14. data/lib/webspicy/specification/err.rb +18 -0
  15. data/lib/webspicy/specification/oldies.rb +4 -0
  16. data/lib/webspicy/specification/oldies/bridge.rb +29 -0
  17. data/lib/webspicy/specification/oldies/errcondition.rb +22 -0
  18. data/lib/webspicy/specification/{postcondition.rb → oldies/postcondition.rb} +6 -0
  19. data/lib/webspicy/specification/{precondition.rb → oldies/precondition.rb} +6 -2
  20. data/lib/webspicy/specification/post.rb +20 -0
  21. data/lib/webspicy/specification/post/missing_condition_impl.rb +15 -0
  22. data/lib/webspicy/specification/post/unexpected_condition_impl.rb +15 -0
  23. data/lib/webspicy/specification/pre.rb +19 -0
  24. data/lib/webspicy/specification/{precondition → pre}/global_request_headers.rb +4 -4
  25. data/lib/webspicy/specification/{precondition → pre}/robust_to_invalid_input.rb +5 -5
  26. data/lib/webspicy/specification/service.rb +58 -24
  27. data/lib/webspicy/specification/test_case.rb +10 -17
  28. data/lib/webspicy/support.rb +32 -0
  29. data/lib/webspicy/support/data_object.rb +25 -0
  30. data/lib/webspicy/support/hooks.rb +65 -0
  31. data/lib/webspicy/support/world.rb +47 -0
  32. data/lib/webspicy/tester.rb +180 -60
  33. data/lib/webspicy/tester/asserter.rb +9 -4
  34. data/lib/webspicy/tester/assertions.rb +8 -9
  35. data/lib/webspicy/tester/client.rb +4 -50
  36. data/lib/webspicy/tester/failure.rb +6 -0
  37. data/lib/webspicy/tester/fakeses.rb +41 -0
  38. data/lib/webspicy/tester/fakeses/email.rb +38 -0
  39. data/lib/webspicy/tester/fakesmtp.rb +39 -0
  40. data/lib/webspicy/tester/fakesmtp/email.rb +27 -0
  41. data/lib/webspicy/tester/file_checker.rb +22 -0
  42. data/lib/webspicy/tester/invocation.rb +15 -196
  43. data/lib/webspicy/tester/reporter.rb +85 -0
  44. data/lib/webspicy/tester/reporter/composite.rb +38 -0
  45. data/lib/webspicy/tester/reporter/documentation.rb +74 -0
  46. data/lib/webspicy/tester/reporter/error_count.rb +25 -0
  47. data/lib/webspicy/tester/reporter/exceptions.rb +62 -0
  48. data/lib/webspicy/tester/reporter/file_progress.rb +25 -0
  49. data/lib/webspicy/tester/reporter/file_summary.rb +43 -0
  50. data/lib/webspicy/tester/reporter/progress.rb +30 -0
  51. data/lib/webspicy/tester/reporter/summary.rb +63 -0
  52. data/lib/webspicy/tester/result.rb +142 -0
  53. data/lib/webspicy/tester/result/assert_met.rb +29 -0
  54. data/lib/webspicy/tester/result/check.rb +33 -0
  55. data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
  56. data/lib/webspicy/tester/result/error_schema_met.rb +24 -0
  57. data/lib/webspicy/tester/result/invocation_succeeded.rb +13 -0
  58. data/lib/webspicy/tester/result/output_schema_met.rb +24 -0
  59. data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
  60. data/lib/webspicy/tester/result/response_header_met.rb +43 -0
  61. data/lib/webspicy/tester/result/response_status_met.rb +25 -0
  62. data/lib/webspicy/version.rb +2 -2
  63. data/lib/webspicy/web.rb +4 -0
  64. data/lib/webspicy/web/client.rb +15 -0
  65. data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
  66. data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
  67. data/lib/webspicy/{tester → web}/client/support.rb +2 -2
  68. data/lib/webspicy/web/invocation.rb +65 -0
  69. data/lib/webspicy/web/mocker.rb +90 -0
  70. data/lib/webspicy/{mocker → web/mocker}/config.ru +3 -2
  71. data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
  72. data/lib/webspicy/web/openapi/generator.rb +129 -0
  73. data/spec/unit/configuration/scope/test_each_service.rb +2 -2
  74. data/spec/unit/configuration/scope/test_each_specification.rb +7 -7
  75. data/spec/unit/specification/{precondition → pre}/test_global_request_headers.rb +9 -4
  76. data/spec/unit/specification/test_condition.rb +44 -0
  77. data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
  78. data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
  79. data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
  80. data/spec/unit/support/world/fixtures/array.json +8 -0
  81. data/spec/unit/support/world/fixtures/queue.rb +1 -0
  82. data/spec/unit/support/world/fixtures/single.json +11 -0
  83. data/spec/unit/support/world/fixtures/yaml.yml +3 -0
  84. data/spec/unit/support/world/test_world.rb +56 -0
  85. data/spec/unit/test_configuration.rb +50 -1
  86. data/spec/unit/tester/fakeses/test_email.rb +40 -0
  87. data/spec/unit/tester/test_asserter.rb +198 -3
  88. data/spec/unit/tester/test_assertions.rb +8 -6
  89. data/spec/unit/web/mocker/test_mocker.rb +35 -0
  90. data/spec/unit/web/openapi/test_generator.rb +31 -0
  91. metadata +90 -67
  92. data/examples/restful/Gemfile +0 -5
  93. data/examples/restful/Gemfile.lock +0 -105
  94. data/examples/restful/Rakefile +0 -25
  95. data/examples/restful/app.rb +0 -180
  96. data/examples/restful/webspicy/config.rb +0 -23
  97. data/examples/restful/webspicy/rack.rb +0 -7
  98. data/examples/restful/webspicy/real.rb +0 -8
  99. data/examples/restful/webspicy/schema.fio +0 -20
  100. data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
  101. data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
  102. data/examples/restful/webspicy/support/todo_removed.rb +0 -18
  103. data/examples/restful/webspicy/todo/deleteTodo.yml +0 -52
  104. data/examples/restful/webspicy/todo/getTodo.yml +0 -50
  105. data/examples/restful/webspicy/todo/getTodoSingleServiceFormat.yml +0 -46
  106. data/examples/restful/webspicy/todo/getTodos.yml +0 -36
  107. data/examples/restful/webspicy/todo/options.yml +0 -32
  108. data/examples/restful/webspicy/todo/patchTodo.yml +0 -66
  109. data/examples/restful/webspicy/todo/postCsv.yml +0 -43
  110. data/examples/restful/webspicy/todo/postFile.yml +0 -40
  111. data/examples/restful/webspicy/todo/postTodos.yml +0 -51
  112. data/examples/restful/webspicy/todo/putTodo.yml +0 -65
  113. data/examples/restful/webspicy/todo/todos.csv +0 -4
  114. data/examples/single_spec/spec.yml +0 -59
  115. data/examples/website/config.rb +0 -2
  116. data/examples/website/schema.fio +0 -1
  117. data/examples/website/specification/get-http.yml +0 -30
  118. data/examples/website/specification/get-https.yml +0 -30
  119. data/lib/webspicy/checker.rb +0 -25
  120. data/lib/webspicy/mocker.rb +0 -88
  121. data/lib/webspicy/openapi/generator.rb +0 -127
  122. data/lib/webspicy/tester/rspec_asserter.rb +0 -108
  123. data/lib/webspicy/tester/rspec_matchers.rb +0 -104
  124. data/spec/unit/mocker/test_mocker.rb +0 -32
  125. data/spec/unit/openapi/test_generator.rb +0 -28
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ module Webspicy
3
+ module Support
4
+ describe Hooks, "fire_after_each" do
5
+
6
+ class Hooker
7
+ include Hooks
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+ attr_reader :config
12
+ end
13
+
14
+ it 'work with no after_each at all' do
15
+ config = Configuration.new
16
+ Hooker.new(config).fire_after_each(1, 2, 3)
17
+ end
18
+
19
+ it 'work with one after_each' do
20
+ config = Configuration.new
21
+
22
+ seen_args = nil
23
+ config.after_each do |*args|
24
+ seen_args = args
25
+ end
26
+
27
+ Hooker.new(config).fire_after_each(1, 2, 3)
28
+
29
+ expect(seen_args).to eql([1, 2, 3])
30
+ end
31
+
32
+ it 'works with two after_each' do
33
+ config = Configuration.new
34
+
35
+ seen = false
36
+
37
+ seen_args = []
38
+ config.after_each do |*args|
39
+ seen_args << args
40
+ end
41
+ config.after_each do |*args|
42
+ seen_args << args
43
+ end
44
+
45
+ Hooker.new(config).fire_after_each(1, 2, 3)
46
+
47
+ expect(seen_args.size).to eql(2)
48
+ expect(seen_args.all?{|sa| sa == [1,2,3] }).to be(true)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,15 @@
1
1
  require 'spec_helper'
2
2
  module Webspicy
3
- class Tester
4
- describe Client, "around" do
3
+ module Support
4
+ describe Hooks, "fire_around" do
5
+
6
+ class Hooker
7
+ include Hooks
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+ attr_reader :config
12
+ end
5
13
 
6
14
  it 'work with no around at all' do
7
15
  config = Configuration.new
@@ -9,8 +17,7 @@ module Webspicy
9
17
  seen = false
10
18
  block = ->(){ seen = true }
11
19
 
12
- scope = Configuration::Scope.new(config)
13
- Client.new(scope).around(1, 2, 3, &block)
20
+ Hooker.new(config).fire_around(1, 2, 3, &block)
14
21
  expect(seen).to be(true)
15
22
  end
16
23
 
@@ -24,11 +31,10 @@ module Webspicy
24
31
  bl.call
25
32
  end
26
33
 
27
- scope = Configuration::Scope.new(config)
28
34
  block = ->(){ seen = true }
29
- Client.new(scope).around(1, 2, 3, &block)
35
+ Hooker.new(config).fire_around(1, 2, 3, &block)
30
36
 
31
- expect(seen_args[0...-1]).to eql([1, 2, 3])
37
+ expect(seen_args).to eql([1, 2, 3])
32
38
  expect(seen).to be(true)
33
39
  end
34
40
 
@@ -47,12 +53,11 @@ module Webspicy
47
53
  bl.call
48
54
  end
49
55
 
50
- scope = Configuration::Scope.new(config)
51
56
  block = ->(){ seen = true }
52
- Client.new(scope).around(1, 2, 3, &block)
57
+ Hooker.new(config).fire_around(1, 2, 3, &block)
53
58
 
54
59
  expect(seen_args.size).to eql(2)
55
- expect(seen_args.all?{|sa| sa[0...-1] == [1,2,3] }).to be(true)
60
+ expect(seen_args.all?{|sa| sa == [1,2,3] }).to be(true)
56
61
  expect(seen).to be(true)
57
62
  end
58
63
 
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ module Webspicy
3
+ module Support
4
+ describe Hooks, "fire_before_each" do
5
+
6
+ class Hooker
7
+ include Hooks
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+ attr_reader :config
12
+ end
13
+
14
+ it 'work with no before_each at all' do
15
+ config = Configuration.new
16
+ Hooker.new(config).fire_before_each(1, 2, 3)
17
+ end
18
+
19
+ it 'work with one before_each' do
20
+ config = Configuration.new
21
+
22
+ seen_args = nil
23
+ config.before_each do |*args|
24
+ seen_args = args
25
+ end
26
+
27
+ Hooker.new(config).fire_before_each(1, 2, 3)
28
+
29
+ expect(seen_args).to eql([1, 2, 3])
30
+ end
31
+
32
+ it 'works with two before_each' do
33
+ config = Configuration.new
34
+
35
+ seen = false
36
+
37
+ seen_args = []
38
+ config.before_each do |*args|
39
+ seen_args << args
40
+ end
41
+ config.before_each do |*args|
42
+ seen_args << args
43
+ end
44
+
45
+ Hooker.new(config).fire_before_each(1, 2, 3)
46
+
47
+ expect(seen_args.size).to eql(2)
48
+ expect(seen_args.all?{|sa| sa == [1,2,3] }).to be(true)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "name": "foo"
4
+ },
5
+ {
6
+ "name": "bar"
7
+ }
8
+ ]
@@ -0,0 +1 @@
1
+ Webspicy::SpecTests::Queue.new
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": 1,
3
+ "name": "single",
4
+ "version": {
5
+ "major": "1",
6
+ "minor": "0"
7
+ },
8
+ "hobbies": [
9
+ { "name": "programming"}
10
+ ]
11
+ }
@@ -0,0 +1,3 @@
1
+ ---
2
+ id: 3
3
+ name: 'YAML'
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ module Webspicy
4
+ module SpecTests
5
+ class Queue
6
+ include Webspicy::Support::World::Item
7
+
8
+ end
9
+ end
10
+ end
11
+
12
+ module Webspicy
13
+ module Support
14
+ describe World do
15
+
16
+ let(:config){
17
+ Configuration.new(restful_folder)
18
+ }
19
+
20
+ subject do
21
+ World.new Path.dir/"fixtures", config
22
+ end
23
+
24
+ it 'supports single objects' do
25
+ expect(subject.single.name).to eql("single")
26
+ expect(subject.single.version.minor).to eql("0")
27
+ expect(subject.single.hobbies[0].name).to eql("programming")
28
+ end
29
+
30
+ it 'supports yaml too' do
31
+ expect(subject.yaml.name).to eql("YAML")
32
+ end
33
+
34
+ it 'supports arrays' do
35
+ expect(subject.array[0].name).to eql("foo")
36
+ expect(subject.array[1].name).to eql("bar")
37
+ end
38
+
39
+ it 'allows setting new attributes on itself' do
40
+ subject.foo = "bar"
41
+ expect(subject.foo).to eql("bar")
42
+ end
43
+
44
+ it 'allows setting new attributes on existing objects' do
45
+ subject.single.foo = "bar"
46
+ expect(subject.single.foo).to eql("bar")
47
+ end
48
+
49
+ it 'supports ruby files and evaluates them' do
50
+ q = subject.queue
51
+ expect(q).to be_a(Webspicy::SpecTests::Queue)
52
+ expect(q.config).to be(config)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -40,7 +40,7 @@ module Webspicy
40
40
  end
41
41
 
42
42
  it 'supports a single .yml file and returns a specific configuration instance' do
43
- file = restful_folder/"todo/getTodo.yml"
43
+ file = restful_folder/"formaldef/todo/get.yml"
44
44
  c = Configuration.dress(file)
45
45
  expect(c).to be_a(Configuration)
46
46
  expect(c.folder).to eq(restful_folder)
@@ -48,6 +48,11 @@ module Webspicy
48
48
  expect(c.each_scope.to_a.first.each_specification.to_a.size).to eql(1)
49
49
  end
50
50
 
51
+ it 'exposes the world as a World instance' do
52
+ c = Configuration.dress(restful_folder)
53
+ expect(c.world).to be_a(Support::World)
54
+ end
55
+
51
56
  it 'yields the block with the configuration, if given' do
52
57
  seen = nil
53
58
  Configuration.dress(Path.dir/'configuration'){|c|
@@ -106,6 +111,7 @@ module Webspicy
106
111
  ENV['ROBUST'] = 'yes'
107
112
  config = Configuration.new
108
113
  expect(config.run_counterexamples?).to eql(true)
114
+ ENV.delete('ROBUST')
109
115
  end
110
116
 
111
117
  it 'ignores the environment is set explicitly' do
@@ -114,6 +120,7 @@ module Webspicy
114
120
  c.run_counterexamples = false
115
121
  end
116
122
  expect(config.run_counterexamples?).to eql(false)
123
+ ENV.delete('ROBUST')
117
124
  end
118
125
  end
119
126
 
@@ -130,6 +137,7 @@ module Webspicy
130
137
  expect(config.file_filter).to be_a(Regexp)
131
138
  expect(config.file_filter).to match("foo/bar/getTodo.yml")
132
139
  expect(config.file_filter).not_to match("foo/bar/getTodos.yml")
140
+ ENV.delete('RESOURCE')
133
141
  end
134
142
 
135
143
  it 'allows expressing a no match' do
@@ -138,6 +146,7 @@ module Webspicy
138
146
  expect(config.file_filter).to be_a(Proc)
139
147
  expect(config.file_filter.call("foo/bar/getTodos.yml")).to eq(true)
140
148
  expect(config.file_filter.call("foo/bar/getTodo.yml")).to eq(false)
149
+ ENV.delete('RESOURCE')
141
150
  end
142
151
 
143
152
  it 'ignores the environment if set explicitly' do
@@ -146,6 +155,7 @@ module Webspicy
146
155
  c.file_filter = nil
147
156
  end
148
157
  expect(config.file_filter).to be_nil
158
+ ENV.delete('RESOURCE')
149
159
  end
150
160
  end
151
161
 
@@ -160,6 +170,7 @@ module Webspicy
160
170
  ENV['METHOD'] = 'GET'
161
171
  config = Configuration.new
162
172
  expect(config.service_filter).to be_a(Proc)
173
+ ENV.delete('METHOD')
163
174
  end
164
175
 
165
176
  it 'ignores the environment is set explicitly' do
@@ -168,6 +179,36 @@ module Webspicy
168
179
  c.service_filter = nil
169
180
  end
170
181
  expect(config.service_filter).to be_nil
182
+ ENV.delete('METHOD')
183
+ end
184
+ end
185
+
186
+ describe 'insecure' do
187
+
188
+ it 'is false by default' do
189
+ config = Configuration.new
190
+ expect(config.insecure).to eql(false)
191
+ end
192
+
193
+ it 'is true if INSECURE is set to yes' do
194
+ ENV['INSECURE'] = 'yes'
195
+ config = Configuration.new
196
+ expect(config.insecure).to eql(true)
197
+ ENV.delete('INSECURE')
198
+ end
199
+
200
+ it 'is true if INSECURE is set to 1' do
201
+ ENV['INSECURE'] = '1'
202
+ config = Configuration.new
203
+ expect(config.insecure).to eql(true)
204
+ ENV.delete('INSECURE')
205
+ end
206
+
207
+ it 'is false if INSECURE is set to no' do
208
+ ENV['INSECURE'] = 'no'
209
+ config = Configuration.new
210
+ expect(config.insecure).to eql(false)
211
+ ENV.delete('INSECURE')
171
212
  end
172
213
  end
173
214
 
@@ -187,48 +228,56 @@ module Webspicy
187
228
  ENV['TAG'] = 'foo'
188
229
  expect(subject).to be_a(Proc)
189
230
  expect(subject.call(tc)).to eql(true)
231
+ ENV.delete('TAG')
190
232
  end
191
233
 
192
234
  it 'allows no matching a single tag' do
193
235
  ENV['TAG'] = 'baz'
194
236
  expect(subject).to be_a(Proc)
195
237
  expect(subject.call(tc)).to eql(false)
238
+ ENV.delete('TAG')
196
239
  end
197
240
 
198
241
  it 'allows setting multiple tags' do
199
242
  ENV['TAG'] = 'foo,baz'
200
243
  expect(subject).to be_a(Proc)
201
244
  expect(subject.call(tc)).to eql(true)
245
+ ENV.delete('TAG')
202
246
  end
203
247
 
204
248
  it 'allows no matching any of multiple tags' do
205
249
  ENV['TAG'] = 'foi,baz'
206
250
  expect(subject).to be_a(Proc)
207
251
  expect(subject.call(tc)).to eql(false)
252
+ ENV.delete('TAG')
208
253
  end
209
254
 
210
255
  it 'allows setting a single negative tag' do
211
256
  ENV['TAG'] = '!foo'
212
257
  expect(subject).to be_a(Proc)
213
258
  expect(subject.call(tc)).to eql(false)
259
+ ENV.delete('TAG')
214
260
  end
215
261
 
216
262
  it 'allows not matching a single negative tag' do
217
263
  ENV['TAG'] = '!baz'
218
264
  expect(subject).to be_a(Proc)
219
265
  expect(subject.call(tc)).to eql(true)
266
+ ENV.delete('TAG')
220
267
  end
221
268
 
222
269
  it 'allows mixing positive & negative tags and have a match' do
223
270
  ENV['TAG'] = 'foo,!baz'
224
271
  expect(subject).to be_a(Proc)
225
272
  expect(subject.call(tc)).to eql(true)
273
+ ENV.delete('TAG')
226
274
  end
227
275
 
228
276
  it 'allows mixing positive & negative tags and have no match' do
229
277
  ENV['TAG'] = 'foo,!bar'
230
278
  expect(subject).to be_a(Proc)
231
279
  expect(subject.call(tc)).to eql(false)
280
+ ENV.delete('TAG')
232
281
  end
233
282
 
234
283
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'webspicy/tester/fakeses'
3
+ module Webspicy
4
+ class Tester
5
+ class Fakeses
6
+ describe Email do
7
+
8
+ DATA = Base64.encode64 <<~J
9
+ From: Webspicy <noreply@webspicy.io>
10
+ To: someone@world.com
11
+ Subject: Hey world, hello!
12
+ J
13
+
14
+ DATA = JSON.parse <<~J
15
+ {
16
+ "id": "1782605f-da34-9c02-6a38-d7e101029cbf",
17
+ "body": {
18
+ "Source": "noreply@webspicy.io",
19
+ "Destinations.member.1": "someone@world.com",
20
+ "RawMessage.Data": "#{DATA.gsub /\n/, ''}",
21
+ "Action": "SendRawEmail",
22
+ "Version": "2010-12-01"
23
+ }
24
+ }
25
+ J
26
+
27
+ subject{
28
+ Email.new(DATA)
29
+ }
30
+
31
+ it 'works as expected' do
32
+ expect(subject.from).to eql("noreply@webspicy.io")
33
+ expect(subject.to).to eql(["someone@world.com"])
34
+ expect(subject.subject).to eql("Hey world, hello!")
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end