webspicy 0.16.1 → 0.19.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 +11 -5
- data/bin/webspicy +6 -1
- data/doc/1-black-box-scene.md +109 -0
- data/doc/2-black-box-testing.md +27 -0
- data/doc/3-specification-importance.md +41 -0
- data/doc/4-sequence-diagram.md +82 -0
- data/lib/webspicy.rb +15 -4
- data/lib/webspicy/configuration.rb +57 -8
- data/lib/webspicy/configuration/scope.rb +22 -16
- data/lib/webspicy/formaldoc.fio +3 -1
- data/lib/webspicy/specification.rb +12 -10
- data/lib/webspicy/specification/condition.rb +23 -0
- data/lib/webspicy/specification/errcondition.rb +17 -0
- data/lib/webspicy/specification/postcondition.rb +1 -0
- data/lib/webspicy/specification/precondition.rb +1 -0
- data/lib/webspicy/specification/precondition/robust_to_invalid_input.rb +1 -1
- data/lib/webspicy/specification/service.rb +38 -25
- data/lib/webspicy/specification/test_case.rb +10 -17
- data/lib/webspicy/support.rb +22 -0
- data/lib/webspicy/support/data_object.rb +25 -0
- data/lib/webspicy/support/hooks.rb +65 -0
- data/lib/webspicy/support/world.rb +47 -0
- data/lib/webspicy/tester.rb +120 -61
- data/lib/webspicy/tester/asserter.rb +9 -4
- data/lib/webspicy/tester/assertions.rb +8 -9
- data/lib/webspicy/tester/client.rb +22 -42
- data/lib/webspicy/tester/failure.rb +6 -0
- data/lib/webspicy/tester/file_checker.rb +22 -0
- data/lib/webspicy/tester/invocation.rb +15 -196
- data/lib/webspicy/tester/reporter.rb +85 -0
- data/lib/webspicy/tester/reporter/composite.rb +38 -0
- data/lib/webspicy/tester/reporter/documentation.rb +67 -0
- data/lib/webspicy/tester/reporter/error_count.rb +25 -0
- data/lib/webspicy/tester/reporter/exceptions.rb +60 -0
- data/lib/webspicy/tester/reporter/file_progress.rb +22 -0
- data/lib/webspicy/tester/reporter/file_summary.rb +42 -0
- data/lib/webspicy/tester/reporter/progress.rb +28 -0
- data/lib/webspicy/tester/reporter/summary.rb +62 -0
- data/lib/webspicy/tester/result.rb +139 -0
- data/lib/webspicy/tester/result/assert_met.rb +29 -0
- data/lib/webspicy/tester/result/check.rb +33 -0
- data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
- data/lib/webspicy/tester/result/error_schema_met.rb +24 -0
- data/lib/webspicy/tester/result/output_schema_met.rb +24 -0
- data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
- data/lib/webspicy/tester/result/response_header_met.rb +43 -0
- data/lib/webspicy/tester/result/response_status_met.rb +25 -0
- data/lib/webspicy/version.rb +2 -2
- data/lib/webspicy/web.rb +4 -0
- data/lib/webspicy/web/client.rb +15 -0
- data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
- data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
- data/lib/webspicy/{tester → web}/client/support.rb +2 -2
- data/lib/webspicy/web/invocation.rb +65 -0
- data/lib/webspicy/web/mocker.rb +90 -0
- data/lib/webspicy/web/mocker/config.ru +6 -0
- data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
- data/lib/webspicy/web/openapi/generator.rb +129 -0
- data/spec/unit/configuration/scope/test_each_service.rb +2 -2
- data/spec/unit/configuration/scope/test_each_specification.rb +7 -7
- data/spec/unit/specification/test_condition.rb +26 -0
- data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
- data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
- data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
- data/spec/unit/support/world/fixtures/array.json +8 -0
- data/spec/unit/support/world/fixtures/queue.rb +1 -0
- data/spec/unit/support/world/fixtures/single.json +11 -0
- data/spec/unit/support/world/fixtures/yaml.yml +3 -0
- data/spec/unit/support/world/test_world.rb +56 -0
- data/spec/unit/test_configuration.rb +50 -1
- data/spec/unit/tester/test_asserter.rb +198 -3
- data/spec/unit/tester/test_assertions.rb +8 -6
- data/spec/unit/web/mocker/test_mocker.rb +35 -0
- data/spec/unit/web/openapi/test_generator.rb +31 -0
- metadata +72 -61
- data/examples/restful/Gemfile +0 -5
- data/examples/restful/Gemfile.lock +0 -105
- data/examples/restful/Rakefile +0 -25
- data/examples/restful/app.rb +0 -180
- data/examples/restful/webspicy/config.rb +0 -23
- data/examples/restful/webspicy/rack.rb +0 -7
- data/examples/restful/webspicy/real.rb +0 -8
- data/examples/restful/webspicy/schema.fio +0 -20
- data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
- data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
- data/examples/restful/webspicy/support/todo_removed.rb +0 -18
- data/examples/restful/webspicy/todo/deleteTodo.yml +0 -52
- data/examples/restful/webspicy/todo/getTodo.yml +0 -50
- data/examples/restful/webspicy/todo/getTodoSingleServiceFormat.yml +0 -46
- data/examples/restful/webspicy/todo/getTodos.yml +0 -36
- data/examples/restful/webspicy/todo/options.yml +0 -32
- data/examples/restful/webspicy/todo/patchTodo.yml +0 -66
- data/examples/restful/webspicy/todo/postCsv.yml +0 -43
- data/examples/restful/webspicy/todo/postFile.yml +0 -40
- data/examples/restful/webspicy/todo/postTodos.yml +0 -51
- data/examples/restful/webspicy/todo/putTodo.yml +0 -65
- data/examples/restful/webspicy/todo/todos.csv +0 -4
- data/examples/single_spec/spec.yml +0 -59
- data/examples/website/config.rb +0 -2
- data/examples/website/schema.fio +0 -1
- data/examples/website/specification/get-http.yml +0 -34
- data/examples/website/specification/get-https.yml +0 -34
- data/lib/webspicy/checker.rb +0 -25
- data/lib/webspicy/mocker.rb +0 -88
- data/lib/webspicy/openapi/generator.rb +0 -127
- data/lib/webspicy/tester/rspec_asserter.rb +0 -108
- data/lib/webspicy/tester/rspec_matchers.rb +0 -104
- data/spec/unit/mocker/test_mocker.rb +0 -32
- data/spec/unit/openapi/test_generator.rb +0 -28
data/examples/website/config.rb
DELETED
data/examples/website/schema.fio
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
@import webspicy/scalars
|
@@ -1,34 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: |-
|
3
|
-
Your backend is broken website
|
4
|
-
|
5
|
-
url: |-
|
6
|
-
http://yourbackendisbroken.dev
|
7
|
-
|
8
|
-
services:
|
9
|
-
- method: |-
|
10
|
-
GET
|
11
|
-
|
12
|
-
description: |-
|
13
|
-
Redirects to the https version
|
14
|
-
|
15
|
-
input_schema: |-
|
16
|
-
Any
|
17
|
-
|
18
|
-
output_schema: |-
|
19
|
-
Any
|
20
|
-
|
21
|
-
error_schema: |-
|
22
|
-
Any
|
23
|
-
|
24
|
-
examples:
|
25
|
-
|
26
|
-
- description: |-
|
27
|
-
it works
|
28
|
-
params:
|
29
|
-
id: 1
|
30
|
-
expected:
|
31
|
-
content_type: text/html
|
32
|
-
status: 3xx
|
33
|
-
headers:
|
34
|
-
Location: https://yourbackendisbroken.dev/?id=1
|
@@ -1,34 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: |-
|
3
|
-
Your backend is broken website
|
4
|
-
|
5
|
-
url: |-
|
6
|
-
https://yourbackendisbroken.dev
|
7
|
-
|
8
|
-
services:
|
9
|
-
- method: |-
|
10
|
-
GET
|
11
|
-
|
12
|
-
description: |-
|
13
|
-
Returns the web page
|
14
|
-
|
15
|
-
input_schema: |-
|
16
|
-
Any
|
17
|
-
|
18
|
-
output_schema: |-
|
19
|
-
Any
|
20
|
-
|
21
|
-
error_schema: |-
|
22
|
-
Any
|
23
|
-
|
24
|
-
examples:
|
25
|
-
|
26
|
-
- description: |-
|
27
|
-
it works
|
28
|
-
params:
|
29
|
-
id: 1
|
30
|
-
expected:
|
31
|
-
content_type: text/html
|
32
|
-
status: 200
|
33
|
-
assert:
|
34
|
-
- notEmpty
|
data/lib/webspicy/checker.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Webspicy
|
2
|
-
class Checker
|
3
|
-
|
4
|
-
def initialize(config)
|
5
|
-
@config = Configuration.dress(config)
|
6
|
-
end
|
7
|
-
attr_reader :config
|
8
|
-
|
9
|
-
def call
|
10
|
-
config.each_scope do |scope|
|
11
|
-
scope.each_specification_file do |file, folder|
|
12
|
-
RSpec.describe file.relative_to(folder).to_s do
|
13
|
-
|
14
|
-
it 'meets the formal doc data schema' do
|
15
|
-
Webspicy.specification(file.load, file, scope)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
RSpec::Core::Runner.run config.rspec_options
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
data/lib/webspicy/mocker.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require "finitio/generation"
|
2
|
-
require "json"
|
3
|
-
module Webspicy
|
4
|
-
class Mocker
|
5
|
-
|
6
|
-
def initialize(config)
|
7
|
-
@config = Configuration.dress(config)
|
8
|
-
@generator = config.generator || Finitio::Generation.new
|
9
|
-
end
|
10
|
-
attr_reader :config, :generator
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
req = Rack::Request.new(env)
|
14
|
-
path = req.path
|
15
|
-
meth = req.request_method
|
16
|
-
if meth == "OPTIONS" && has_service?(path)
|
17
|
-
[204, {}, []]
|
18
|
-
elsif service = find_service(meth, path)
|
19
|
-
status = best_status_code(service)
|
20
|
-
body = status == 204 ? "" : random_body(service, req)
|
21
|
-
headers = generate_headers(service)
|
22
|
-
[ status, headers, [ body ].compact ]
|
23
|
-
else
|
24
|
-
[404, {}, []]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def has_service?(path)
|
31
|
-
config.each_scope do |scope|
|
32
|
-
scope.each_specification do |specification|
|
33
|
-
next unless url_matches?(specification, path)
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
|
40
|
-
def find_service(method, path)
|
41
|
-
config.each_scope do |scope|
|
42
|
-
scope.each_specification do |specification|
|
43
|
-
next unless url_matches?(specification, path)
|
44
|
-
scope.each_service(specification) do |service|
|
45
|
-
return service if service.method == method
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def generate_headers(service)
|
53
|
-
{
|
54
|
-
"Content-Type" => best_content_type(service)
|
55
|
-
}.delete_if{|k,v| v.nil? }
|
56
|
-
end
|
57
|
-
|
58
|
-
def best_status_code(service)
|
59
|
-
if ex = service.examples.first
|
60
|
-
(ex.expected_status && ex.expected_status.to_i) || 200
|
61
|
-
else
|
62
|
-
200
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def best_content_type(service)
|
67
|
-
if ex = service.examples.first
|
68
|
-
ex.expected_content_type
|
69
|
-
else
|
70
|
-
"application/json"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def url_matches?(specification, path)
|
75
|
-
specification.url_pattern.match(path)
|
76
|
-
end
|
77
|
-
|
78
|
-
def random_body(service, request)
|
79
|
-
world = OpenStruct.new({
|
80
|
-
service: service,
|
81
|
-
request: request
|
82
|
-
})
|
83
|
-
data = generator.call(service.output_schema.main, world)
|
84
|
-
JSON.pretty_generate(data) if data
|
85
|
-
end
|
86
|
-
|
87
|
-
end # class Mocker
|
88
|
-
end # module Webspicy
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require "finitio/generation"
|
2
|
-
require "finitio/json_schema"
|
3
|
-
module Webspicy
|
4
|
-
module Openapi
|
5
|
-
class Generator
|
6
|
-
|
7
|
-
def initialize(config)
|
8
|
-
@config = Configuration.dress(config)
|
9
|
-
@generator = config.generator || Finitio::Generation.new
|
10
|
-
end
|
11
|
-
attr_reader :config, :generator
|
12
|
-
|
13
|
-
def call
|
14
|
-
{
|
15
|
-
openapi: "3.0.2",
|
16
|
-
info: {
|
17
|
-
version: "1.0.0",
|
18
|
-
title: "Hello API"
|
19
|
-
},
|
20
|
-
paths: paths
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def paths
|
27
|
-
config.each_scope.inject({}) do |paths,scope|
|
28
|
-
scope.each_specification.inject(paths) do |paths,specification|
|
29
|
-
paths.merge(path_for(specification)){|k,ps,qs|
|
30
|
-
ps.merge(qs)
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def path_for(specification)
|
37
|
-
{
|
38
|
-
specification.url => {
|
39
|
-
summary: specification.name
|
40
|
-
}.merge(verbs_for(specification))
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def verbs_for(specification)
|
45
|
-
specification.services.inject({}) do |verbs,service|
|
46
|
-
verb = service.method.downcase
|
47
|
-
verb_defn = {
|
48
|
-
description: service.description,
|
49
|
-
responses: responses_for(service)
|
50
|
-
}
|
51
|
-
unless ["get", "options", "delete", "head"].include?(verb)
|
52
|
-
verb_defn[:requestBody] = request_body_for(service)
|
53
|
-
end
|
54
|
-
verbs.merge({ verb => verb_defn })
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def request_body_for(service)
|
59
|
-
schema = actual_input_schema(service)
|
60
|
-
{
|
61
|
-
required: true,
|
62
|
-
content: {
|
63
|
-
"application/json" => {
|
64
|
-
schema: schema.to_json_schema,
|
65
|
-
example: generator.call(schema, {})
|
66
|
-
}
|
67
|
-
}
|
68
|
-
}
|
69
|
-
end
|
70
|
-
|
71
|
-
def responses_for(service)
|
72
|
-
result = {}
|
73
|
-
service.examples.each_with_object(result) do |test_case, rs|
|
74
|
-
rs.merge!(response_for(test_case, false)){|k,r1,r2| r1 }
|
75
|
-
end
|
76
|
-
service.counterexamples.each_with_object(result) do |test_case, rs|
|
77
|
-
rs.merge!(response_for(test_case, true)){|k,r1,r2| r1 }
|
78
|
-
end
|
79
|
-
result
|
80
|
-
end
|
81
|
-
|
82
|
-
def response_for(test_case, counterexample)
|
83
|
-
res = {
|
84
|
-
description: test_case.description,
|
85
|
-
}
|
86
|
-
status = (test_case.expected_status && test_case.expected_status.to_int) || 200
|
87
|
-
if test_case.expected_content_type && status != 204
|
88
|
-
content = {
|
89
|
-
schema: schema_for(test_case, counterexample)
|
90
|
-
}
|
91
|
-
unless counterexample
|
92
|
-
content[:example] = example_for(test_case, counterexample)
|
93
|
-
end
|
94
|
-
res[:content] = {
|
95
|
-
test_case.expected_content_type => content
|
96
|
-
}
|
97
|
-
end
|
98
|
-
{
|
99
|
-
status => res
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
def schema_for(test_case, counterexample)
|
104
|
-
schema = actual_output_schema(test_case, counterexample)
|
105
|
-
schema.to_json_schema
|
106
|
-
end
|
107
|
-
|
108
|
-
def example_for(test_case, counterexample)
|
109
|
-
schema = actual_output_schema(test_case, counterexample)
|
110
|
-
generator.call(schema, {})
|
111
|
-
end
|
112
|
-
|
113
|
-
def actual_output_schema(test_case, counterexample)
|
114
|
-
if counterexample
|
115
|
-
test_case.service.error_schema['Main']
|
116
|
-
else
|
117
|
-
test_case.service.output_schema['Main']
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def actual_input_schema(service)
|
122
|
-
service.input_schema['Main']
|
123
|
-
end
|
124
|
-
|
125
|
-
end # class Generator
|
126
|
-
end # module Openapi
|
127
|
-
end # module Webspicy
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module Webspicy
|
2
|
-
class Tester
|
3
|
-
class RSpecAsserter
|
4
|
-
|
5
|
-
def initialize(rspec, invocation)
|
6
|
-
@rspec = rspec
|
7
|
-
@invocation = invocation
|
8
|
-
end
|
9
|
-
attr_reader :rspec, :invocation
|
10
|
-
|
11
|
-
def response
|
12
|
-
invocation.response
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_case
|
16
|
-
invocation.test_case
|
17
|
-
end
|
18
|
-
|
19
|
-
def service
|
20
|
-
test_case.service
|
21
|
-
end
|
22
|
-
|
23
|
-
def assert!
|
24
|
-
assert_status_met
|
25
|
-
assert_content_type_met
|
26
|
-
assert_expected_headers
|
27
|
-
assert_output_schema_met
|
28
|
-
assert_assertions_met
|
29
|
-
assert_postconditions_met
|
30
|
-
|
31
|
-
assert_no_other_errors
|
32
|
-
end
|
33
|
-
|
34
|
-
def assert_status_met
|
35
|
-
got = response.status
|
36
|
-
expected = test_case.expected_status
|
37
|
-
rspec.expect(got).to rspec.match_response_status(expected)
|
38
|
-
end
|
39
|
-
|
40
|
-
def assert_content_type_met
|
41
|
-
return if test_case.is_expected_status?(204)
|
42
|
-
return unless ect = test_case.expected_content_type
|
43
|
-
got = response.content_type
|
44
|
-
got = got.mime_type if got.respond_to?(:mime_type)
|
45
|
-
if ect.nil?
|
46
|
-
rspec.expect(ect).to rspec.have_no_response_type
|
47
|
-
else
|
48
|
-
rspec.expect(got).to rspec.match_content_type(ect)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def assert_expected_headers
|
53
|
-
return unless test_case.has_expected_headers?
|
54
|
-
test_case.expected_headers.each_pair do |k,v|
|
55
|
-
got = response.headers[k]
|
56
|
-
if got.nil?
|
57
|
-
rspec.expect(got).to rspec.be_in_response_headers(k)
|
58
|
-
else
|
59
|
-
rspec.expect(got).to rspec.match_response_header(k, v)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def assert_output_schema_met
|
65
|
-
return if test_case.is_expected_status?(204)
|
66
|
-
return if invocation.is_redirect?
|
67
|
-
if invocation.is_empty_response?
|
68
|
-
body = response.body.to_s.strip
|
69
|
-
rspec.expect(body).to rspec.be_an_empty_response_body
|
70
|
-
else
|
71
|
-
b = invocation.dressed_body
|
72
|
-
if invocation.is_expected_success?
|
73
|
-
rspec.expect(b).to rspec.meet_output_schema
|
74
|
-
else
|
75
|
-
rspec.expect(b).to rspec.meet_error_schema
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def assert_assertions_met
|
81
|
-
return unless test_case.has_assertions?
|
82
|
-
asserter = Tester::Asserter.new(invocation.dressed_body)
|
83
|
-
test_case.assert.each do |assert|
|
84
|
-
begin
|
85
|
-
asserter.instance_eval(assert)
|
86
|
-
rescue => ex
|
87
|
-
rspec.expect(ex).to rspec.meet_assertion(assert)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def assert_postconditions_met
|
93
|
-
return unless service.has_postconditions?
|
94
|
-
return if test_case.counterexample?
|
95
|
-
service.postconditions.each do |post|
|
96
|
-
msg = post.check(invocation)
|
97
|
-
rspec.expect(msg).to rspec.meet_postcondition(post)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def assert_no_other_errors
|
102
|
-
errors = invocation.errors
|
103
|
-
rspec.expect(errors).to rspec.be_an_empty_errors_array
|
104
|
-
end
|
105
|
-
|
106
|
-
end # class RSpecAsserter
|
107
|
-
end # class Tester
|
108
|
-
end # module Webspicy
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'rspec/expectations'
|
2
|
-
|
3
|
-
RSpec::Matchers.define :match_response_status do |expected|
|
4
|
-
match do |actual|
|
5
|
-
expected === actual
|
6
|
-
end
|
7
|
-
failure_message_for_should do |actual|
|
8
|
-
"expected response status #{actual} to be #{expected}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
RSpec::Matchers.define :have_no_response_type do
|
13
|
-
match do |actual|
|
14
|
-
actual.nil?
|
15
|
-
end
|
16
|
-
failure_message_for_should do |actual|
|
17
|
-
"expected Content-Type not to be present"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
RSpec::Matchers.define :match_content_type do |expected|
|
22
|
-
match do |actual|
|
23
|
-
actual.to_s.start_with?(expected.to_s)
|
24
|
-
end
|
25
|
-
failure_message_for_should do |actual|
|
26
|
-
"expected Content-Type to be `#{expected}`, got `#{actual}`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
RSpec::Matchers.define :be_in_response_headers do |header_name|
|
31
|
-
match do |actual|
|
32
|
-
!actual.nil?
|
33
|
-
end
|
34
|
-
failure_message_for_should do |actual|
|
35
|
-
"expected response header `#{header_name}` to be set"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
RSpec::Matchers.define :match_response_header do |header_name, expected|
|
40
|
-
match do |actual|
|
41
|
-
expected == actual
|
42
|
-
end
|
43
|
-
failure_message_for_should do |actual|
|
44
|
-
"expected response header `#{header_name}` to be `#{expected}`, got `#{actual}`"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
RSpec::Matchers.define :be_an_empty_response_body do
|
49
|
-
match do |actual|
|
50
|
-
actual.empty?
|
51
|
-
end
|
52
|
-
failure_message_for_should do |actual|
|
53
|
-
"expected response body to be empty, started with `#{actual[0..20]}`"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
RSpec::Matchers.define :meet_output_schema do
|
58
|
-
match do |actual|
|
59
|
-
!actual.is_a?(Exception)
|
60
|
-
end
|
61
|
-
failure_message_for_should do |actual|
|
62
|
-
"expected response body to meet output schema, got following error:\n" + \
|
63
|
-
" #{actual.message}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
RSpec::Matchers.define :meet_error_schema do
|
68
|
-
match do |actual|
|
69
|
-
!actual.is_a?(Exception)
|
70
|
-
end
|
71
|
-
failure_message_for_should do |actual|
|
72
|
-
"expected response body to meet error schema, got following error:\n" + \
|
73
|
-
" #{actual.message}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
RSpec::Matchers.define :meet_assertion do |assert|
|
78
|
-
match do |actual|
|
79
|
-
actual.nil?
|
80
|
-
end
|
81
|
-
failure_message_for_should do |actual|
|
82
|
-
"expected assertion `#{assert}` to be met, got following error:\n" + \
|
83
|
-
" #{actual.message}"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
RSpec::Matchers.define :meet_postcondition do |post|
|
88
|
-
match do |actual|
|
89
|
-
actual.nil?
|
90
|
-
end
|
91
|
-
failure_message_for_should do |actual|
|
92
|
-
"expected postcondition `#{post.class.name}` to be met, got following error:\n" + \
|
93
|
-
" #{actual}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
RSpec::Matchers.define :be_an_empty_errors_array do
|
98
|
-
match do |actual|
|
99
|
-
actual.empty?
|
100
|
-
end
|
101
|
-
failure_message_for_should do |actual|
|
102
|
-
"expected no webspicy error, got the following ones:\n" + actual.map{|a| " #{a}" }.join("\n")
|
103
|
-
end
|
104
|
-
end
|