webspicy 0.15.8 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +76 -24
- data/bin/webspicy +30 -14
- data/examples/restful/Gemfile.lock +40 -24
- data/examples/restful/Rakefile +0 -1
- data/examples/restful/app.rb +4 -1
- data/examples/restful/webspicy/config.rb +9 -0
- data/examples/restful/webspicy/{todo/deleteTodo.yml → formaldef/todo/_one/delete.yml} +7 -1
- data/examples/restful/webspicy/formaldef/todo/_one/get.simpler.yml +46 -0
- data/examples/restful/webspicy/{todo/getTodo.yml → formaldef/todo/_one/get.yml} +0 -0
- data/examples/restful/webspicy/{todo/patchTodo.yml → formaldef/todo/_one/patch.yml} +3 -0
- data/examples/restful/webspicy/{todo/putTodo.yml → formaldef/todo/_one/put.yml} +0 -0
- data/examples/restful/webspicy/{todo/getTodos.yml → formaldef/todo/get.yml} +0 -0
- data/examples/restful/webspicy/{todo → formaldef/todo}/options.yml +1 -1
- data/examples/restful/webspicy/{todo/postCsv.yml → formaldef/todo/post.csv.yml} +0 -0
- data/examples/restful/webspicy/{todo/postFile.yml → formaldef/todo/post.file.yml} +1 -1
- data/examples/restful/webspicy/{todo/postTodos.yml → formaldef/todo/post.yml} +0 -0
- data/examples/restful/webspicy/{todo → formaldef/todo}/todos.csv +0 -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_not_removed.rb +21 -0
- data/examples/restful/webspicy/support/todo_removed.rb +20 -0
- 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 +49 -17
- data/lib/webspicy/checker.rb +5 -20
- data/lib/webspicy/configuration.rb +79 -14
- data/lib/webspicy/configuration/scope.rb +154 -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 +25 -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/rspec/checker.rb +2 -0
- data/lib/webspicy/rspec/checker/rspec_checker.rb +24 -0
- data/lib/webspicy/rspec/support/rspec_runnable.rb +27 -0
- data/lib/webspicy/rspec/tester.rb +4 -0
- data/lib/webspicy/rspec/tester/rspec_asserter.rb +121 -0
- data/lib/webspicy/rspec/tester/rspec_matchers.rb +114 -0
- data/lib/webspicy/rspec/tester/rspec_tester.rb +63 -0
- data/lib/webspicy/{resource.rb → specification.rb} +31 -10
- data/lib/webspicy/specification/errcondition.rb +16 -0
- 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 +38 -25
- data/lib/webspicy/specification/test_case.rb +133 -0
- data/lib/webspicy/support.rb +2 -0
- data/lib/webspicy/support/colorize.rb +28 -0
- data/lib/webspicy/support/data_object.rb +25 -0
- data/lib/webspicy/support/status_range.rb +6 -1
- data/lib/webspicy/tester.rb +8 -77
- data/lib/webspicy/tester/asserter.rb +11 -5
- data/lib/webspicy/tester/assertions.rb +13 -10
- 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/failure.rb +6 -0
- data/lib/webspicy/tester/invocation.rb +70 -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 +246 -0
- data/spec/unit/tester/test_assertions.rb +12 -10
- data/tasks/test.rake +3 -1
- metadata +106 -48
- 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
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Webspicy
|
3
|
+
class Configuration
|
4
|
+
describe Scope, "expand_example" do
|
5
|
+
|
6
|
+
subject{ Scope.new({}).send(:expand_example, service, example) }
|
7
|
+
|
8
|
+
context 'when the service has no default example' do
|
9
|
+
let(:service) {
|
10
|
+
Webspicy.service({
|
11
|
+
method: "GET",
|
12
|
+
description: "Test service",
|
13
|
+
preconditions: "Foo",
|
14
|
+
input_schema: "{ id: Integer }",
|
15
|
+
output_schema: "{}",
|
16
|
+
error_schema: "{}"
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:example) {
|
21
|
+
Webspicy.test_case({
|
22
|
+
description: "Hello world"
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
it 'returns the example itself' do
|
27
|
+
expect(subject).to be(example)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the service has a default example' do
|
32
|
+
let(:service) {
|
33
|
+
Webspicy.service({
|
34
|
+
method: "GET",
|
35
|
+
description: "Test service",
|
36
|
+
preconditions: "Foo",
|
37
|
+
input_schema: "{ id: Integer }",
|
38
|
+
output_schema: "{}",
|
39
|
+
error_schema: "{}",
|
40
|
+
default_example: {
|
41
|
+
expected: { status: 200 }
|
42
|
+
}
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
let(:example) {
|
47
|
+
Webspicy.test_case({
|
48
|
+
description: "Hello world",
|
49
|
+
expected: { content_type: "application/json" }
|
50
|
+
})
|
51
|
+
}
|
52
|
+
|
53
|
+
it 'deep merges the default example and the example as expected' do
|
54
|
+
expect(subject).to be_a(Specification::TestCase)
|
55
|
+
expect(subject.description).to eql("Hello world")
|
56
|
+
expect(subject.expected).to eql({
|
57
|
+
status: Support::StatusRange.int(200),
|
58
|
+
content_type: "application/json"
|
59
|
+
})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Webspicy
|
3
|
+
class Configuration
|
4
|
+
describe Scope, 'to_real_url' do
|
5
|
+
|
6
|
+
let(:scope) {
|
7
|
+
Scope.new(configuration)
|
8
|
+
}
|
9
|
+
|
10
|
+
context 'when no host at all' do
|
11
|
+
|
12
|
+
let(:configuration) {
|
13
|
+
Configuration.new
|
14
|
+
}
|
15
|
+
|
16
|
+
it 'does nothing on absolute URLs already' do
|
17
|
+
url = 'http://127.0.0.1:4567/todo'
|
18
|
+
got = scope.to_real_url(url)
|
19
|
+
expect(got).to eql(url)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'yields the block relative URLs' do
|
23
|
+
got = scope.to_real_url("/todo"){ "hello" }
|
24
|
+
expect(got).to eql("hello")
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'fails on relative URLs and no block is given' do
|
28
|
+
expect(->(){
|
29
|
+
scope.to_real_url("/todo")
|
30
|
+
}).to raise_error(/Unable to resolve `\/todo`/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with a static host' do
|
35
|
+
|
36
|
+
let(:configuration) {
|
37
|
+
Configuration.new do |c|
|
38
|
+
c.host = "http://127.0.0.1:4568"
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
it 'does nothing on absolute URLs already' do
|
43
|
+
url = 'http://127.0.0.1:4567/todo'
|
44
|
+
got = scope.to_real_url(url)
|
45
|
+
expect(got).to eql(url)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'resolves relative URLs as expected' do
|
49
|
+
url = '/todo'
|
50
|
+
got = scope.to_real_url(url)
|
51
|
+
expect(got).to eql("http://127.0.0.1:4568/todo")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with a dynamic host resolver' do
|
57
|
+
|
58
|
+
let(:configuration) {
|
59
|
+
Configuration.new do |c|
|
60
|
+
c.host = ->(url, tc) {
|
61
|
+
"http://127.0.0.1:4568#{url}"
|
62
|
+
}
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
it 'resolves absolute URLs' do
|
67
|
+
url = 'http://127.0.0.1:4567/todo'
|
68
|
+
got = scope.to_real_url(url)
|
69
|
+
expect(got).to eql("http://127.0.0.1:4568#{url}")
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'resolves relative URLs as expected' do
|
73
|
+
url = '/todo'
|
74
|
+
got = scope.to_real_url(url)
|
75
|
+
expect(got).to eql("http://127.0.0.1:4568/todo")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webspicy/openapi'
|
3
|
+
require 'openapi3_parser'
|
4
|
+
module Webspicy
|
5
|
+
module Openapi
|
6
|
+
describe Generator do
|
7
|
+
|
8
|
+
let(:config) {
|
9
|
+
Configuration.new(restful_folder)
|
10
|
+
}
|
11
|
+
|
12
|
+
subject {
|
13
|
+
ruby_objs = Generator.new(config).call
|
14
|
+
JSON.parse(ruby_objs.to_json)
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'works fine' do
|
18
|
+
document = Openapi3Parser.load(subject)
|
19
|
+
#puts JSON.pretty_generate(subject)
|
20
|
+
document.errors.each do |err|
|
21
|
+
puts err.inspect
|
22
|
+
end unless document.errors.empty?
|
23
|
+
expect(document.errors).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Webspicy
|
4
|
+
class Specification
|
5
|
+
module Precondition
|
6
|
+
describe GlobalRequestHeaders do
|
7
|
+
let(:gbr){
|
8
|
+
GlobalRequestHeaders.new('Accept' => 'application/json')
|
9
|
+
}
|
10
|
+
|
11
|
+
describe "instrument" do
|
12
|
+
it 'injects the headers' do
|
13
|
+
tc = TestCase.new({})
|
14
|
+
gbr.instrument(tc, nil)
|
15
|
+
expect(tc.headers['Accept']).to eql("application/json")
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'keeps original headers unchanged' do
|
19
|
+
tc = TestCase.new({
|
20
|
+
headers: {
|
21
|
+
'Content-Type' => 'text/plain'
|
22
|
+
}
|
23
|
+
})
|
24
|
+
gbr.instrument(tc, nil)
|
25
|
+
expect(tc.headers['Content-Type']).to eql("text/plain")
|
26
|
+
expect(tc.headers['Accept']).to eql("application/json")
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has low precedence' do
|
30
|
+
tc = TestCase.new({
|
31
|
+
headers: {
|
32
|
+
'Accept' => 'text/plain'
|
33
|
+
}
|
34
|
+
})
|
35
|
+
gbr.instrument(tc, nil)
|
36
|
+
expect(tc.headers['Accept']).to eql("text/plain")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Webspicy
|
3
|
-
class
|
3
|
+
class Specification
|
4
4
|
describe Service, "dress_params" do
|
5
5
|
|
6
6
|
it 'symbolizes keys' do
|
@@ -30,5 +30,5 @@ module Webspicy
|
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
|
-
end # class
|
33
|
+
end # class Specification
|
34
34
|
end # module Webspicy
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
module Webspicy
|
3
|
+
class Specification
|
4
|
+
describe TestCase, "mutate" do
|
5
|
+
|
6
|
+
it 'helps easily creating a new test by mutation' do
|
7
|
+
tc = TestCase.new({
|
8
|
+
:params => {
|
9
|
+
"id" => 1
|
10
|
+
}
|
11
|
+
})
|
12
|
+
tc2 = tc.mutate({
|
13
|
+
:params => {
|
14
|
+
"id" => 2
|
15
|
+
}
|
16
|
+
})
|
17
|
+
expect(tc2).to be_a(TestCase)
|
18
|
+
expect(tc.params["id"]).to eql(1)
|
19
|
+
expect(tc2.params["id"]).to eql(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
module Webspicy
|
3
|
-
describe
|
3
|
+
describe Specification, "instantiate_url" do
|
4
4
|
|
5
5
|
it 'does nothing when the url has no placeholder' do
|
6
|
-
r =
|
6
|
+
r = Specification.new(url: "/test/a/url")
|
7
7
|
url, params = r.instantiate_url(foo: "bar")
|
8
8
|
expect(url).to eq("/test/a/url")
|
9
9
|
expect(params).to eq(foo: "bar")
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'instantiates placeholders and strips corresponding params' do
|
13
|
-
r =
|
13
|
+
r = Specification.new(url: "/test/{foo}/url")
|
14
14
|
url, params = r.instantiate_url(foo: "bar", baz: "coz")
|
15
15
|
expect(url).to eq("/test/bar/url")
|
16
16
|
expect(params).to eq(baz: "coz")
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'instantiates placeholders and strips corresponding params even when multiple' do
|
20
|
-
r =
|
20
|
+
r = Specification.new(url: "/test/{foo}/url/{bar}")
|
21
21
|
url, params = r.instantiate_url(foo: "bar", bar: "baz", baz: "coz")
|
22
22
|
expect(url).to eq("/test/bar/url/baz")
|
23
23
|
expect(params).to eq(baz: "coz")
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'supports placeholders corresponding to subentities' do
|
27
|
-
r =
|
27
|
+
r = Specification.new(url: "/test/{foo.id}/url")
|
28
28
|
url, params = r.instantiate_url(foo: {id: "bar"}, baz: "coz")
|
29
29
|
expect(url).to eq("/test/bar/url")
|
30
30
|
expect(params).to eq(foo: {}, baz: "coz")
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
module Webspicy
|
3
|
-
describe
|
3
|
+
describe Specification, "url_placeholders" do
|
4
4
|
|
5
5
|
it 'returns an empty array on none' do
|
6
|
-
r =
|
6
|
+
r = Specification.new(url: "/test/a/url")
|
7
7
|
expect(r.url_placeholders).to eq([])
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'returns all placeholders' do
|
11
|
-
r =
|
11
|
+
r = Specification.new(url: "/test/{foo}/url/{bar}")
|
12
12
|
expect(r.url_placeholders).to eq(["foo", "bar"])
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns all placeholders expr' do
|
16
|
-
r =
|
16
|
+
r = Specification.new(url: "/test/{foo.id}/url/{bar}")
|
17
17
|
expect(r.url_placeholders).to eq(["foo.id", "bar"])
|
18
18
|
end
|
19
19
|
|
@@ -31,6 +31,23 @@ module Webspicy
|
|
31
31
|
expect(c.preconditions.size).to eq(1)
|
32
32
|
end
|
33
33
|
|
34
|
+
it 'supports an URL and returns a specific configuration instance' do
|
35
|
+
c = Configuration.dress("http://google.com/")
|
36
|
+
expect(c).to be_a(Configuration)
|
37
|
+
expect(c.folder).to eq(Path.pwd)
|
38
|
+
expect(c.each_scope.to_a.size).to eql(1)
|
39
|
+
expect(c.each_scope.to_a.first.each_specification.to_a.size).to eql(1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'supports a single .yml file and returns a specific configuration instance' do
|
43
|
+
file = restful_folder/"formaldef/todo/get.yml"
|
44
|
+
c = Configuration.dress(file)
|
45
|
+
expect(c).to be_a(Configuration)
|
46
|
+
expect(c.folder).to eq(restful_folder)
|
47
|
+
expect(c.each_scope.to_a.size).to eql(1)
|
48
|
+
expect(c.each_scope.to_a.first.each_specification.to_a.size).to eql(1)
|
49
|
+
end
|
50
|
+
|
34
51
|
it 'yields the block with the configuration, if given' do
|
35
52
|
seen = nil
|
36
53
|
Configuration.dress(Path.dir/'configuration'){|c|
|
@@ -56,20 +73,20 @@ module Webspicy
|
|
56
73
|
|
57
74
|
it 'creates a child when adding a folder' do
|
58
75
|
Configuration.new(Path.dir) do |c|
|
59
|
-
child = c.folder '
|
76
|
+
child = c.folder 'specification'
|
60
77
|
expect(child).to be_a(Configuration)
|
61
|
-
expect(child.folder).to eql(Path.dir/'
|
78
|
+
expect(child.folder).to eql(Path.dir/'specification')
|
62
79
|
end
|
63
80
|
end
|
64
81
|
|
65
82
|
it 'yield the child to the block if any given' do
|
66
83
|
Configuration.new(Path.dir) do |c|
|
67
84
|
seen = nil
|
68
|
-
c.folder '
|
85
|
+
c.folder 'specification' do |child|
|
69
86
|
seen = child
|
70
87
|
end
|
71
88
|
expect(seen).to be_a(Configuration)
|
72
|
-
expect(seen.folder).to eql(Path.dir/'
|
89
|
+
expect(seen.folder).to eql(Path.dir/'specification')
|
73
90
|
end
|
74
91
|
end
|
75
92
|
end
|
@@ -223,7 +240,7 @@ module Webspicy
|
|
223
240
|
let(:before_aller) { ->(){} }
|
224
241
|
let(:after_aller) { ->(){} }
|
225
242
|
let(:config) do
|
226
|
-
Configuration.new(Path.dir/'
|
243
|
+
Configuration.new(Path.dir/'specification') do |c|
|
227
244
|
c.before_all(&before_aller)
|
228
245
|
c.before_each(&before_eacher)
|
229
246
|
c.after_each(&after_eacher)
|
@@ -243,7 +260,7 @@ module Webspicy
|
|
243
260
|
describe 'dup' do
|
244
261
|
|
245
262
|
let(:original) do
|
246
|
-
Configuration.new(Path.dir/'
|
263
|
+
Configuration.new(Path.dir/'specification') do |c|
|
247
264
|
c.host = "http://127.0.0.1"
|
248
265
|
c.folder 'service'
|
249
266
|
end
|
@@ -253,7 +270,7 @@ module Webspicy
|
|
253
270
|
duped = original.dup do |d|
|
254
271
|
d.host = "http://127.0.0.1:4567"
|
255
272
|
end
|
256
|
-
expect(duped.folder).to eql(Path.dir/'
|
273
|
+
expect(duped.folder).to eql(Path.dir/'specification')
|
257
274
|
expect(duped.host).to eql("http://127.0.0.1:4567")
|
258
275
|
expect(original.host).to eql("http://127.0.0.1")
|
259
276
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Webspicy
|
3
|
+
class Tester
|
4
|
+
describe Client, "around" do
|
5
|
+
|
6
|
+
it 'work with no around at all' do
|
7
|
+
config = Configuration.new
|
8
|
+
|
9
|
+
seen = false
|
10
|
+
block = ->(){ seen = true }
|
11
|
+
|
12
|
+
scope = Configuration::Scope.new(config)
|
13
|
+
Client.new(scope).around(1, 2, 3, &block)
|
14
|
+
expect(seen).to be(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'work with one around' do
|
18
|
+
config = Configuration.new
|
19
|
+
|
20
|
+
seen = false
|
21
|
+
seen_args = nil
|
22
|
+
config.around_each do |*args, &bl|
|
23
|
+
seen_args = args
|
24
|
+
bl.call
|
25
|
+
end
|
26
|
+
|
27
|
+
scope = Configuration::Scope.new(config)
|
28
|
+
block = ->(){ seen = true }
|
29
|
+
Client.new(scope).around(1, 2, 3, &block)
|
30
|
+
|
31
|
+
expect(seen_args[0...-1]).to eql([1, 2, 3])
|
32
|
+
expect(seen).to be(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'works with two arounds' do
|
36
|
+
config = Configuration.new
|
37
|
+
|
38
|
+
seen = false
|
39
|
+
|
40
|
+
seen_args = []
|
41
|
+
config.around_each do |*args, &bl|
|
42
|
+
seen_args << args
|
43
|
+
bl.call
|
44
|
+
end
|
45
|
+
config.around_each do |*args, &bl|
|
46
|
+
seen_args << args
|
47
|
+
bl.call
|
48
|
+
end
|
49
|
+
|
50
|
+
scope = Configuration::Scope.new(config)
|
51
|
+
block = ->(){ seen = true }
|
52
|
+
Client.new(scope).around(1, 2, 3, &block)
|
53
|
+
|
54
|
+
expect(seen_args.size).to eql(2)
|
55
|
+
expect(seen_args.all?{|sa| sa[0...-1] == [1,2,3] }).to be(true)
|
56
|
+
expect(seen).to be(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|