webspicy 0.15.8 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -24
  3. data/bin/webspicy +30 -14
  4. data/examples/restful/Gemfile.lock +40 -24
  5. data/examples/restful/Rakefile +0 -1
  6. data/examples/restful/app.rb +4 -1
  7. data/examples/restful/webspicy/config.rb +9 -0
  8. data/examples/restful/webspicy/{todo/deleteTodo.yml → formaldef/todo/_one/delete.yml} +7 -1
  9. data/examples/restful/webspicy/formaldef/todo/_one/get.simpler.yml +46 -0
  10. data/examples/restful/webspicy/{todo/getTodo.yml → formaldef/todo/_one/get.yml} +0 -0
  11. data/examples/restful/webspicy/{todo/patchTodo.yml → formaldef/todo/_one/patch.yml} +3 -0
  12. data/examples/restful/webspicy/{todo/putTodo.yml → formaldef/todo/_one/put.yml} +0 -0
  13. data/examples/restful/webspicy/{todo/getTodos.yml → formaldef/todo/get.yml} +0 -0
  14. data/examples/restful/webspicy/{todo → formaldef/todo}/options.yml +1 -1
  15. data/examples/restful/webspicy/{todo/postCsv.yml → formaldef/todo/post.csv.yml} +0 -0
  16. data/examples/restful/webspicy/{todo/postFile.yml → formaldef/todo/post.file.yml} +1 -1
  17. data/examples/restful/webspicy/{todo/postTodos.yml → formaldef/todo/post.yml} +0 -0
  18. data/examples/restful/webspicy/{todo → formaldef/todo}/todos.csv +0 -0
  19. data/examples/restful/webspicy/rack.rb +1 -1
  20. data/examples/restful/webspicy/real.rb +1 -1
  21. data/examples/restful/webspicy/schema.fio +2 -2
  22. data/examples/restful/webspicy/support/must_be_authenticated.rb +2 -2
  23. data/examples/restful/webspicy/support/todo_not_removed.rb +21 -0
  24. data/examples/restful/webspicy/support/todo_removed.rb +20 -0
  25. data/examples/single_spec/spec.yml +59 -0
  26. data/examples/website/config.rb +2 -0
  27. data/examples/website/schema.fio +1 -0
  28. data/examples/website/specification/get-http.yml +30 -0
  29. data/examples/website/specification/get-https.yml +30 -0
  30. data/lib/finitio/webspicy/scalars.fio +25 -0
  31. data/lib/webspicy.rb +49 -17
  32. data/lib/webspicy/checker.rb +5 -20
  33. data/lib/webspicy/configuration.rb +79 -14
  34. data/lib/webspicy/configuration/scope.rb +154 -0
  35. data/lib/webspicy/configuration/single_url.rb +58 -0
  36. data/lib/webspicy/configuration/single_yml_file.rb +30 -0
  37. data/lib/webspicy/formaldoc.fio +25 -8
  38. data/lib/webspicy/mocker.rb +8 -8
  39. data/lib/webspicy/mocker/config.ru +5 -0
  40. data/lib/webspicy/openapi.rb +1 -0
  41. data/lib/webspicy/openapi/generator.rb +127 -0
  42. data/lib/webspicy/rspec/checker.rb +2 -0
  43. data/lib/webspicy/rspec/checker/rspec_checker.rb +24 -0
  44. data/lib/webspicy/rspec/support/rspec_runnable.rb +27 -0
  45. data/lib/webspicy/rspec/tester.rb +4 -0
  46. data/lib/webspicy/rspec/tester/rspec_asserter.rb +121 -0
  47. data/lib/webspicy/rspec/tester/rspec_matchers.rb +114 -0
  48. data/lib/webspicy/rspec/tester/rspec_tester.rb +63 -0
  49. data/lib/webspicy/{resource.rb → specification.rb} +31 -10
  50. data/lib/webspicy/specification/errcondition.rb +16 -0
  51. data/lib/webspicy/specification/file_upload.rb +37 -0
  52. data/lib/webspicy/specification/postcondition.rb +16 -0
  53. data/lib/webspicy/specification/precondition.rb +19 -0
  54. data/lib/webspicy/specification/precondition/global_request_headers.rb +35 -0
  55. data/lib/webspicy/specification/precondition/robust_to_invalid_input.rb +68 -0
  56. data/lib/webspicy/{resource → specification}/service.rb +38 -25
  57. data/lib/webspicy/specification/test_case.rb +133 -0
  58. data/lib/webspicy/support.rb +2 -0
  59. data/lib/webspicy/support/colorize.rb +28 -0
  60. data/lib/webspicy/support/data_object.rb +25 -0
  61. data/lib/webspicy/support/status_range.rb +6 -1
  62. data/lib/webspicy/tester.rb +8 -77
  63. data/lib/webspicy/tester/asserter.rb +11 -5
  64. data/lib/webspicy/tester/assertions.rb +13 -10
  65. data/lib/webspicy/tester/client.rb +63 -0
  66. data/lib/webspicy/tester/client/http_client.rb +154 -0
  67. data/lib/webspicy/tester/client/rack_test_client.rb +188 -0
  68. data/lib/webspicy/tester/client/support.rb +65 -0
  69. data/lib/webspicy/tester/failure.rb +6 -0
  70. data/lib/webspicy/tester/invocation.rb +70 -0
  71. data/lib/webspicy/version.rb +2 -2
  72. data/spec/{unit/spec_helper.rb → spec_helper.rb} +0 -0
  73. data/spec/unit/configuration/scope/test_each_service.rb +49 -0
  74. data/spec/unit/configuration/scope/test_each_specification.rb +68 -0
  75. data/spec/unit/configuration/scope/test_expand_example.rb +65 -0
  76. data/spec/unit/configuration/scope/test_to_real_url.rb +82 -0
  77. data/spec/unit/openapi/test_generator.rb +28 -0
  78. data/spec/unit/specification/precondition/test_global_request_headers.rb +42 -0
  79. data/spec/unit/{resource → specification}/service/test_dress_params.rb +2 -2
  80. data/spec/unit/specification/test_case/test_mutate.rb +24 -0
  81. data/spec/unit/{resource → specification}/test_instantiate_url.rb +5 -5
  82. data/spec/unit/{resource → specification}/test_url_placeholders.rb +4 -4
  83. data/spec/unit/test_configuration.rb +24 -7
  84. data/spec/unit/tester/client/test_around.rb +61 -0
  85. data/spec/unit/tester/test_asserter.rb +246 -0
  86. data/spec/unit/tester/test_assertions.rb +12 -10
  87. data/tasks/test.rake +3 -1
  88. metadata +106 -48
  89. data/LICENSE.md +0 -22
  90. data/lib/webspicy/client.rb +0 -61
  91. data/lib/webspicy/client/http_client.rb +0 -145
  92. data/lib/webspicy/client/rack_test_client.rb +0 -181
  93. data/lib/webspicy/client/support.rb +0 -48
  94. data/lib/webspicy/file_upload.rb +0 -35
  95. data/lib/webspicy/postcondition.rb +0 -14
  96. data/lib/webspicy/precondition.rb +0 -15
  97. data/lib/webspicy/resource/service/invocation.rb +0 -212
  98. data/lib/webspicy/resource/service/test_case.rb +0 -132
  99. data/lib/webspicy/scope.rb +0 -160
  100. data/spec/unit/client/test_around.rb +0 -59
  101. data/spec/unit/scope/test_each_resource.rb +0 -66
  102. data/spec/unit/scope/test_each_service.rb +0 -47
  103. data/spec/unit/scope/test_expand_example.rb +0 -63
  104. data/spec/unit/scope/test_to_real_url.rb +0 -80
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
- module Webspicy
3
- describe Client, "around" do
4
-
5
- it 'work with no around at all' do
6
- config = Configuration.new
7
-
8
- seen = false
9
- block = ->(){ seen = true }
10
-
11
- scope = Scope.new(config)
12
- Client.new(scope).around(1, 2, 3, &block)
13
- expect(seen).to be(true)
14
- end
15
-
16
- it 'work with one around' do
17
- config = Configuration.new
18
-
19
- seen = false
20
- seen_args = nil
21
- config.around_each do |*args, &bl|
22
- seen_args = args
23
- bl.call
24
- end
25
-
26
- scope = Scope.new(config)
27
- block = ->(){ seen = true }
28
- Client.new(scope).around(1, 2, 3, &block)
29
-
30
- expect(seen_args[0...-1]).to eql([1, 2, 3])
31
- expect(seen).to be(true)
32
- end
33
-
34
- it 'works with two arounds' do
35
- config = Configuration.new
36
-
37
- seen = false
38
-
39
- seen_args = []
40
- config.around_each do |*args, &bl|
41
- seen_args << args
42
- bl.call
43
- end
44
- config.around_each do |*args, &bl|
45
- seen_args << args
46
- bl.call
47
- end
48
-
49
- scope = Scope.new(config)
50
- block = ->(){ seen = true }
51
- Client.new(scope).around(1, 2, 3, &block)
52
-
53
- expect(seen_args.size).to eql(2)
54
- expect(seen_args.all?{|sa| sa[0...-1] == [1,2,3] }).to be(true)
55
- expect(seen).to be(true)
56
- end
57
-
58
- end
59
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
- module Webspicy
3
- describe Scope, 'each_resource' do
4
-
5
- let(:scope) {
6
- Scope.new(configuration)
7
- }
8
-
9
- subject {
10
- scope.each_resource.to_a
11
- }
12
-
13
- context 'without any filter' do
14
-
15
- let(:configuration) {
16
- Configuration.new(restful_folder)
17
- }
18
-
19
- it 'returns all files' do
20
- expect(subject.size).to eql(restful_folder.glob('**/*.yml').size)
21
- end
22
- end
23
-
24
- context 'with a file filter as a proc' do
25
-
26
- let(:configuration) {
27
- Configuration.new(restful_folder){|c|
28
- c.file_filter = ->(f) {
29
- f.basename.to_s == "getTodo.yml"
30
- }
31
- }
32
- }
33
-
34
- it 'returns only that file' do
35
- expect(subject.size).to eql(1)
36
- end
37
- end
38
-
39
- context 'with a file filter as a Regex' do
40
-
41
- let(:configuration) {
42
- Configuration.new(restful_folder){|c|
43
- c.file_filter = /getTodo.yml/
44
- }
45
- }
46
-
47
- it 'returns only that file' do
48
- expect(subject.size).to eql(1)
49
- end
50
- end
51
-
52
- context 'when having children folders' do
53
-
54
- let(:configuration) {
55
- Configuration.new(restful_folder) do |c|
56
- c.folder 'todo'
57
- end
58
- }
59
-
60
- it 'returns all files' do
61
- expect(subject.size).to eql(restful_folder.glob('**/*.yml').size)
62
- end
63
- end
64
-
65
- end
66
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
- module Webspicy
3
- describe Scope, 'each_service' do
4
-
5
- let(:scope) {
6
- Scope.new(configuration)
7
- }
8
-
9
- let(:resource) {
10
- scope.each_resource.first
11
- }
12
-
13
- subject {
14
- scope.each_service(resource).to_a
15
- }
16
-
17
- context 'without any filter' do
18
-
19
- let(:configuration) {
20
- Configuration.new(restful_folder){|c|
21
- c.file_filter = /getTodo.yml/
22
- }
23
- }
24
-
25
- it 'returns all services' do
26
- expect(subject.size).to eql(1)
27
- end
28
- end
29
-
30
- context 'with a service filter as a proc' do
31
-
32
- let(:configuration) {
33
- Configuration.new(restful_folder){|c|
34
- c.file_filter = /getTodo.yml/
35
- c.service_filter = ->(s) {
36
- s.method == "POST"
37
- }
38
- }
39
- }
40
-
41
- it 'returns nothing' do
42
- expect(subject.size).to eql(0)
43
- end
44
- end
45
-
46
- end
47
- end
@@ -1,63 +0,0 @@
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: Support::StatusRange.int(200),
57
- content_type: "application/json"
58
- })
59
- end
60
- end
61
-
62
- end
63
- end # module Webspicy
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
- module Webspicy
3
- describe Scope, 'to_real_url' do
4
-
5
- let(:scope) {
6
- Scope.new(configuration)
7
- }
8
-
9
- context 'when no host at all' do
10
-
11
- let(:configuration) {
12
- Configuration.new
13
- }
14
-
15
- it 'does nothing on absolute URLs already' do
16
- url = 'http://127.0.0.1:4567/todo'
17
- got = scope.to_real_url(url)
18
- expect(got).to eql(url)
19
- end
20
-
21
- it 'yields the block relative URLs' do
22
- got = scope.to_real_url("/todo"){ "hello" }
23
- expect(got).to eql("hello")
24
- end
25
-
26
- it 'fails on relative URLs and no block is given' do
27
- expect(->(){
28
- scope.to_real_url("/todo")
29
- }).to raise_error(/Unable to resolve `\/todo`/)
30
- end
31
- end
32
-
33
- context 'with a static host' do
34
-
35
- let(:configuration) {
36
- Configuration.new do |c|
37
- c.host = "http://127.0.0.1:4568"
38
- end
39
- }
40
-
41
- it 'does nothing on absolute URLs already' do
42
- url = 'http://127.0.0.1:4567/todo'
43
- got = scope.to_real_url(url)
44
- expect(got).to eql(url)
45
- end
46
-
47
- it 'resolves relative URLs as expected' do
48
- url = '/todo'
49
- got = scope.to_real_url(url)
50
- expect(got).to eql("http://127.0.0.1:4568/todo")
51
- end
52
-
53
- end
54
-
55
- context 'with a dynamic host resolver' do
56
-
57
- let(:configuration) {
58
- Configuration.new do |c|
59
- c.host = ->(url, tc) {
60
- "http://127.0.0.1:4568#{url}"
61
- }
62
- end
63
- }
64
-
65
- it 'resolves absolute URLs' do
66
- url = 'http://127.0.0.1:4567/todo'
67
- got = scope.to_real_url(url)
68
- expect(got).to eql("http://127.0.0.1:4568#{url}")
69
- end
70
-
71
- it 'resolves relative URLs as expected' do
72
- url = '/todo'
73
- got = scope.to_real_url(url)
74
- expect(got).to eql("http://127.0.0.1:4568/todo")
75
- end
76
-
77
- end
78
-
79
- end
80
- end