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
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -30,7 +30,7 @@ class MustBeAuthenticated
|
|
30
30
|
def counterexample(description, role, expected, status = 401)
|
31
31
|
YAML.load <<-YML.gsub(/^\s+[#][ ]/, "")
|
32
32
|
# description: |-
|
33
|
-
# (#{self.class.name})
|
33
|
+
# #{description} (#{self.class.name} PRE)
|
34
34
|
# params:
|
35
35
|
# id: 1
|
36
36
|
# dress_params:
|
@@ -41,7 +41,7 @@ class MustBeAuthenticated
|
|
41
41
|
# content_type: application/json
|
42
42
|
# status: #{status}
|
43
43
|
# assert:
|
44
|
-
# - "pathFD('', error: '#{expected}')"
|
44
|
+
# - "pathFD('', error: '#{expected}')"
|
45
45
|
YML
|
46
46
|
end
|
47
47
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class TodoNotRemoved
|
2
|
+
include Webspicy::Specification::Postcondition
|
3
|
+
|
4
|
+
def self.match(service, descr)
|
5
|
+
return TodoNotRemoved.new if descr =~ /If it existed, the todo has not been removed/
|
6
|
+
end
|
7
|
+
|
8
|
+
def check(invocation)
|
9
|
+
client, scope, test_case = invocation.client,
|
10
|
+
invocation.client.scope,
|
11
|
+
invocation.test_case
|
12
|
+
return if invocation.response.status == 404
|
13
|
+
id = test_case.params['id']
|
14
|
+
url = scope.to_real_url("/todo/#{id}", test_case){|url| url }
|
15
|
+
response = client.api.get(url, {}, {
|
16
|
+
"Accept" => "application/json"
|
17
|
+
})
|
18
|
+
return nil if response.status == 200
|
19
|
+
"Todo `#{id}` was not supposed to be deleted, it was not found"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class TodoRemoved
|
2
|
+
include Webspicy::Specification::Postcondition
|
3
|
+
|
4
|
+
def self.match(service, descr)
|
5
|
+
return TodoRemoved.new if descr =~ /The todo has been removed/
|
6
|
+
end
|
7
|
+
|
8
|
+
def check(invocation)
|
9
|
+
client, scope, test_case = invocation.client,
|
10
|
+
invocation.client.scope,
|
11
|
+
invocation.test_case
|
12
|
+
id = test_case.params['id']
|
13
|
+
url = scope.to_real_url("/todo/#{id}", test_case){|url| url }
|
14
|
+
response = client.api.get(url, {}, {
|
15
|
+
"Accept" => "application/json"
|
16
|
+
})
|
17
|
+
return nil if response.status == 404
|
18
|
+
"Todo `#{id}` was not deleted, it has been found"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
name: |-
|
3
|
+
Todo
|
4
|
+
|
5
|
+
url: |-
|
6
|
+
http://127.0.0.1:4567/todo/{id}
|
7
|
+
|
8
|
+
services:
|
9
|
+
- method: |-
|
10
|
+
GET
|
11
|
+
|
12
|
+
description: |-
|
13
|
+
Returns a single todo item
|
14
|
+
|
15
|
+
input_schema: |-
|
16
|
+
{
|
17
|
+
id: Integer
|
18
|
+
}
|
19
|
+
|
20
|
+
output_schema: |-
|
21
|
+
{
|
22
|
+
id: Integer
|
23
|
+
description: String
|
24
|
+
}
|
25
|
+
|
26
|
+
error_schema: |-
|
27
|
+
{
|
28
|
+
error: String
|
29
|
+
}
|
30
|
+
|
31
|
+
examples:
|
32
|
+
|
33
|
+
- description: |-
|
34
|
+
when requested on an existing TODO
|
35
|
+
headers:
|
36
|
+
Accept: application/json
|
37
|
+
params:
|
38
|
+
id: 1
|
39
|
+
expected:
|
40
|
+
content_type: application/json
|
41
|
+
status: 200
|
42
|
+
assert:
|
43
|
+
- "pathFD('', id: 1)"
|
44
|
+
- "match('description', /Refactor/)"
|
45
|
+
- "notMatch('description', /Foo/)"
|
46
|
+
|
47
|
+
counterexamples:
|
48
|
+
|
49
|
+
- description: |-
|
50
|
+
when requested on an unexisting TODO
|
51
|
+
headers:
|
52
|
+
Accept: application/json
|
53
|
+
params:
|
54
|
+
id: 999254654
|
55
|
+
expected:
|
56
|
+
content_type: application/json
|
57
|
+
status: 404
|
58
|
+
assert:
|
59
|
+
- "pathFD('', error: 'No such todo')"
|
@@ -0,0 +1 @@
|
|
1
|
+
@import webspicy/scalars
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
url: |-
|
3
|
+
http://yourbackendisbroken.dev
|
4
|
+
|
5
|
+
method: |-
|
6
|
+
GET
|
7
|
+
|
8
|
+
description: |-
|
9
|
+
Redirects to the https version
|
10
|
+
|
11
|
+
input_schema: |-
|
12
|
+
Any
|
13
|
+
|
14
|
+
output_schema: |-
|
15
|
+
Any
|
16
|
+
|
17
|
+
error_schema: |-
|
18
|
+
Any
|
19
|
+
|
20
|
+
examples:
|
21
|
+
|
22
|
+
- description: |-
|
23
|
+
it works
|
24
|
+
params:
|
25
|
+
id: 1
|
26
|
+
expected:
|
27
|
+
content_type: text/html
|
28
|
+
status: 3xx
|
29
|
+
headers:
|
30
|
+
Location: https://yourbackendisbroken.dev/?id=1
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
url: |-
|
3
|
+
https://yourbackendisbroken.dev
|
4
|
+
|
5
|
+
method: |-
|
6
|
+
GET
|
7
|
+
|
8
|
+
description: |-
|
9
|
+
Returns the web page
|
10
|
+
|
11
|
+
input_schema: |-
|
12
|
+
Any
|
13
|
+
|
14
|
+
output_schema: |-
|
15
|
+
Any
|
16
|
+
|
17
|
+
error_schema: |-
|
18
|
+
Any
|
19
|
+
|
20
|
+
examples:
|
21
|
+
|
22
|
+
- description: |-
|
23
|
+
it works
|
24
|
+
params:
|
25
|
+
id: 1
|
26
|
+
expected:
|
27
|
+
content_type: text/html
|
28
|
+
status: 200
|
29
|
+
assert:
|
30
|
+
- notEmpty
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Any
|
2
|
+
Any = .
|
3
|
+
|
4
|
+
# Booleans
|
5
|
+
Nil = .NilClass
|
6
|
+
True = .TrueClass
|
7
|
+
False = .FalseClass
|
8
|
+
Boolean = .TrueClass|.FalseClass
|
9
|
+
|
10
|
+
# Numbers
|
11
|
+
Numeric = .Numeric
|
12
|
+
Integer = .Integer
|
13
|
+
Float = .Float
|
14
|
+
Real = .Float
|
15
|
+
|
16
|
+
# String
|
17
|
+
String = .String
|
18
|
+
|
19
|
+
# Date, Time, DateTime
|
20
|
+
Date = .Date <iso8601> .String \( s | Date.iso8601(s) )
|
21
|
+
\( d | d.iso8601 )
|
22
|
+
Time = .Time <iso8601> .String \( s | Time.iso8601(s) )
|
23
|
+
\( t | t.iso8601 )
|
24
|
+
DateTime = .DateTime <iso8601> .String \( s | DateTime.iso8601(s) )
|
25
|
+
\( t | t.iso8601 )
|
data/lib/webspicy.rb
CHANGED
@@ -7,25 +7,33 @@ require 'ostruct'
|
|
7
7
|
require 'yaml'
|
8
8
|
require 'rspec'
|
9
9
|
require 'rack/test'
|
10
|
-
require
|
10
|
+
require 'mustermann'
|
11
|
+
require 'colorized_string'
|
12
|
+
require 'securerandom'
|
11
13
|
module Webspicy
|
12
14
|
|
13
15
|
###
|
14
16
|
### Load library
|
15
17
|
###
|
16
18
|
|
19
|
+
require 'webspicy/version'
|
17
20
|
require 'webspicy/support'
|
21
|
+
require 'webspicy/specification'
|
18
22
|
require 'webspicy/configuration'
|
19
|
-
require 'webspicy/file_upload'
|
20
|
-
require 'webspicy/scope'
|
21
|
-
require 'webspicy/client'
|
22
|
-
require 'webspicy/resource'
|
23
|
-
require 'webspicy/precondition'
|
24
|
-
require 'webspicy/postcondition'
|
25
23
|
require 'webspicy/checker'
|
26
24
|
require 'webspicy/tester'
|
27
|
-
|
28
|
-
|
25
|
+
|
26
|
+
###
|
27
|
+
### Backward compatibility
|
28
|
+
###
|
29
|
+
Client = Tester::Client
|
30
|
+
HttpClient = Tester::HttpClient
|
31
|
+
RackTestClient = Tester::RackTestClient
|
32
|
+
Resource = Specification
|
33
|
+
Precondition = Specification::Precondition
|
34
|
+
Postcondition = Specification::Postcondition
|
35
|
+
FileUpload = Specification::FileUpload
|
36
|
+
Scope = Configuration::Scope
|
29
37
|
|
30
38
|
###
|
31
39
|
### About folders
|
@@ -36,30 +44,39 @@ module Webspicy
|
|
36
44
|
EXAMPLES_FOLDER = ROOT_FOLDER/('examples')
|
37
45
|
|
38
46
|
###
|
39
|
-
### About formal doc and
|
47
|
+
### About formal doc and specifications defined there
|
40
48
|
###
|
41
|
-
|
49
|
+
Finitio.stdlib_path(Path.dir/"finitio")
|
50
|
+
DEFAULT_SYSTEM = Finitio.system(<<~FIO)
|
51
|
+
@import webspicy/scalars
|
52
|
+
FIO
|
42
53
|
FORMALDOC = Finitio.system(Path.dir/("webspicy/formaldoc.fio"))
|
43
54
|
|
44
55
|
# Returns a default scope instance.
|
45
56
|
def default_scope
|
46
|
-
Scope.new(Configuration.new)
|
57
|
+
Configuration::Scope.new(Configuration.new)
|
47
58
|
end
|
48
59
|
module_function :default_scope
|
49
60
|
|
50
|
-
def
|
61
|
+
def specification(raw, file = nil, scope = default_scope)
|
62
|
+
raw = YAML.load(raw) if raw.is_a?(String)
|
51
63
|
with_scope(scope) do
|
52
|
-
r = FORMALDOC["
|
64
|
+
r = FORMALDOC["Specification"].dress(raw)
|
65
|
+
r.config = scope.config
|
53
66
|
r.located_at!(file) if file
|
54
67
|
r
|
55
68
|
end
|
69
|
+
rescue Finitio::Error => ex
|
70
|
+
handle_finitio_error(ex, scope)
|
56
71
|
end
|
57
|
-
module_function :
|
72
|
+
module_function :specification
|
58
73
|
|
59
74
|
def service(raw, scope = default_scope)
|
60
75
|
with_scope(scope) do
|
61
76
|
FORMALDOC["Service"].dress(raw)
|
62
77
|
end
|
78
|
+
rescue Finitio::Error => ex
|
79
|
+
handle_finitio_error(ex)
|
63
80
|
end
|
64
81
|
module_function :service
|
65
82
|
|
@@ -67,9 +84,19 @@ module Webspicy
|
|
67
84
|
with_scope(scope) do
|
68
85
|
FORMALDOC["TestCase"].dress(raw)
|
69
86
|
end
|
87
|
+
rescue Finitio::Error => ex
|
88
|
+
handle_finitio_error(ex)
|
70
89
|
end
|
71
90
|
module_function :test_case
|
72
91
|
|
92
|
+
def handle_finitio_error(ex, scope)
|
93
|
+
msg = "#{ex.message}:\n #{ex.root_cause.message}"
|
94
|
+
msg = Support::Colorize.colorize_error(msg, scope.config)
|
95
|
+
fatal(msg)
|
96
|
+
raise
|
97
|
+
end
|
98
|
+
module_function :handle_finitio_error
|
99
|
+
|
73
100
|
#
|
74
101
|
# Yields the block after having installed `scope` globally.
|
75
102
|
#
|
@@ -120,7 +147,7 @@ module Webspicy
|
|
120
147
|
if scope = Thread.current[:webspicy_scope]
|
121
148
|
scope.parse_schema(fio)
|
122
149
|
else
|
123
|
-
|
150
|
+
DEFAULT_SYSTEM.system(fio)
|
124
151
|
end
|
125
152
|
end
|
126
153
|
module_function :schema
|
@@ -132,7 +159,7 @@ module Webspicy
|
|
132
159
|
LOGGER = ::Logger.new(STDOUT)
|
133
160
|
LOGGER.level = Logger.const_get(ENV['LOG_LEVEL'] || 'WARN')
|
134
161
|
LOGGER.formatter = proc { |severity, datetime, progname, msg|
|
135
|
-
"
|
162
|
+
" " + msg + "\n"
|
136
163
|
}
|
137
164
|
|
138
165
|
def info(*args, &bl)
|
@@ -145,4 +172,9 @@ module Webspicy
|
|
145
172
|
end
|
146
173
|
module_function :debug
|
147
174
|
|
175
|
+
def fatal(*args, &bl)
|
176
|
+
LOGGER && LOGGER.fatal(*args, &bl)
|
177
|
+
end
|
178
|
+
module_function :fatal
|
179
|
+
|
148
180
|
end
|
data/lib/webspicy/checker.rb
CHANGED
@@ -1,25 +1,10 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Checker
|
3
3
|
|
4
|
-
def
|
5
|
-
|
4
|
+
def self.new(*args, &bl)
|
5
|
+
require_relative 'rspec/checker'
|
6
|
+
RSpecChecker.new(*args, &bl)
|
6
7
|
end
|
7
|
-
attr_reader :config
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
scope.each_resource_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.resource(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
|
9
|
+
end # class Checker
|
10
|
+
end # module Webspicy
|