webspicy 0.15.7 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +71 -24
- data/bin/webspicy +30 -14
- data/examples/restful/Gemfile +2 -2
- data/examples/restful/Gemfile.lock +53 -33
- data/examples/restful/Rakefile +0 -1
- data/examples/restful/app.rb +4 -1
- data/examples/restful/webspicy/config.rb +8 -0
- data/examples/restful/webspicy/rack.rb +1 -1
- data/examples/restful/webspicy/real.rb +1 -1
- data/examples/restful/webspicy/schema.fio +2 -2
- data/examples/restful/webspicy/support/must_be_authenticated.rb +2 -2
- data/examples/restful/webspicy/support/todo_removed.rb +18 -0
- data/examples/restful/webspicy/todo/deleteTodo.yml +4 -1
- data/examples/restful/webspicy/todo/getTodoSingleServiceFormat.yml +46 -0
- data/examples/restful/webspicy/todo/options.yml +1 -1
- data/examples/restful/webspicy/todo/patchTodo.yml +3 -0
- data/examples/restful/webspicy/todo/postFile.yml +1 -1
- data/examples/single_spec/spec.yml +59 -0
- data/examples/website/config.rb +2 -0
- data/examples/website/schema.fio +1 -0
- data/examples/website/specification/get-http.yml +30 -0
- data/examples/website/specification/get-https.yml +30 -0
- data/lib/finitio/webspicy/scalars.fio +25 -0
- data/lib/webspicy.rb +48 -17
- data/lib/webspicy/checker.rb +2 -2
- data/lib/webspicy/configuration.rb +70 -14
- data/lib/webspicy/configuration/scope.rb +162 -0
- data/lib/webspicy/configuration/single_url.rb +58 -0
- data/lib/webspicy/configuration/single_yml_file.rb +30 -0
- data/lib/webspicy/formaldoc.fio +23 -8
- data/lib/webspicy/mocker.rb +8 -8
- data/lib/webspicy/mocker/config.ru +5 -0
- data/lib/webspicy/openapi.rb +1 -0
- data/lib/webspicy/openapi/generator.rb +127 -0
- data/lib/webspicy/{resource.rb → specification.rb} +28 -5
- data/lib/webspicy/specification/file_upload.rb +37 -0
- data/lib/webspicy/specification/postcondition.rb +16 -0
- data/lib/webspicy/specification/precondition.rb +19 -0
- data/lib/webspicy/specification/precondition/global_request_headers.rb +35 -0
- data/lib/webspicy/specification/precondition/robust_to_invalid_input.rb +68 -0
- data/lib/webspicy/{resource → specification}/service.rb +11 -6
- data/lib/webspicy/specification/test_case.rb +139 -0
- data/lib/webspicy/support.rb +1 -0
- data/lib/webspicy/support/colorize.rb +28 -0
- data/lib/webspicy/support/status_range.rb +6 -1
- data/lib/webspicy/tester.rb +16 -11
- data/lib/webspicy/tester/asserter.rb +3 -2
- data/lib/webspicy/tester/assertions.rb +5 -1
- data/lib/webspicy/tester/client.rb +63 -0
- data/lib/webspicy/tester/client/http_client.rb +154 -0
- data/lib/webspicy/tester/client/rack_test_client.rb +188 -0
- data/lib/webspicy/tester/client/support.rb +65 -0
- data/lib/webspicy/tester/invocation.rb +218 -0
- data/lib/webspicy/tester/rspec_asserter.rb +108 -0
- data/lib/webspicy/tester/rspec_matchers.rb +104 -0
- data/lib/webspicy/version.rb +2 -2
- data/spec/{unit/spec_helper.rb → spec_helper.rb} +0 -0
- data/spec/unit/configuration/scope/test_each_service.rb +49 -0
- data/spec/unit/configuration/scope/test_each_specification.rb +68 -0
- data/spec/unit/configuration/scope/test_expand_example.rb +65 -0
- data/spec/unit/configuration/scope/test_to_real_url.rb +82 -0
- data/spec/unit/openapi/test_generator.rb +28 -0
- data/spec/unit/specification/precondition/test_global_request_headers.rb +42 -0
- data/spec/unit/{resource → specification}/service/test_dress_params.rb +2 -2
- data/spec/unit/specification/test_case/test_mutate.rb +24 -0
- data/spec/unit/{resource → specification}/test_instantiate_url.rb +5 -5
- data/spec/unit/{resource → specification}/test_url_placeholders.rb +4 -4
- data/spec/unit/test_configuration.rb +24 -7
- data/spec/unit/tester/client/test_around.rb +61 -0
- data/spec/unit/tester/test_asserter.rb +51 -0
- data/spec/unit/tester/test_assertions.rb +4 -4
- data/tasks/test.rake +3 -1
- metadata +88 -45
- data/LICENSE.md +0 -22
- data/lib/webspicy/client.rb +0 -61
- data/lib/webspicy/client/http_client.rb +0 -145
- data/lib/webspicy/client/rack_test_client.rb +0 -181
- data/lib/webspicy/client/support.rb +0 -48
- data/lib/webspicy/file_upload.rb +0 -35
- data/lib/webspicy/postcondition.rb +0 -14
- data/lib/webspicy/precondition.rb +0 -15
- data/lib/webspicy/resource/service/invocation.rb +0 -212
- data/lib/webspicy/resource/service/test_case.rb +0 -132
- data/lib/webspicy/scope.rb +0 -160
- data/spec/unit/client/test_around.rb +0 -59
- data/spec/unit/scope/test_each_resource.rb +0 -66
- data/spec/unit/scope/test_each_service.rb +0 -47
- data/spec/unit/scope/test_expand_example.rb +0 -63
- 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
|