webspicy 0.15.5 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -24
- data/bin/webspicy +30 -13
- data/examples/restful/Gemfile +2 -2
- data/examples/restful/Gemfile.lock +53 -33
- data/examples/restful/Rakefile +0 -1
- data/examples/restful/app.rb +19 -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 +7 -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/restful/webspicy/todo/putTodo.yml +65 -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 +34 -0
- data/examples/website/specification/get-https.yml +34 -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 +24 -9
- data/lib/webspicy/mocker.rb +8 -8
- data/lib/webspicy/openapi.rb +1 -0
- data/lib/webspicy/openapi/generator.rb +127 -0
- data/lib/webspicy/{resource.rb → specification.rb} +26 -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 -133
- data/lib/webspicy/client/rack_test_client.rb +0 -168
- 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
data/lib/webspicy/checker.rb
CHANGED
@@ -8,11 +8,11 @@ module Webspicy
|
|
8
8
|
|
9
9
|
def call
|
10
10
|
config.each_scope do |scope|
|
11
|
-
scope.
|
11
|
+
scope.each_specification_file do |file, folder|
|
12
12
|
RSpec.describe file.relative_to(folder).to_s do
|
13
13
|
|
14
14
|
it 'meets the formal doc data schema' do
|
15
|
-
Webspicy.
|
15
|
+
Webspicy.specification(file.load, file, scope)
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -13,27 +13,57 @@ module Webspicy
|
|
13
13
|
@rspec_options = default_rspec_options
|
14
14
|
@run_examples = default_run_examples
|
15
15
|
@run_counterexamples = default_run_counterexamples
|
16
|
+
@run_generated_counterexamples = default_run_generated_counterexamples
|
16
17
|
@file_filter = default_file_filter
|
17
18
|
@service_filter = default_service_filter
|
18
19
|
@test_case_filter = default_test_case_filter
|
19
|
-
@
|
20
|
+
@colors = {
|
21
|
+
:highlight => :cyan,
|
22
|
+
:error => :red,
|
23
|
+
:success => :green
|
24
|
+
}
|
25
|
+
@scope_factory = ->(config){ Scope.new(config) }
|
26
|
+
@client = Tester::HttpClient
|
20
27
|
Path.require_tree(folder/'support') if (folder/'support').exists?
|
21
28
|
yield(self) if block_given?
|
22
29
|
end
|
23
30
|
attr_accessor :folder
|
24
31
|
protected :folder=
|
25
32
|
|
33
|
+
attr_accessor :colors
|
34
|
+
|
26
35
|
def self.dress(arg, &bl)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
case arg
|
37
|
+
when Configuration
|
38
|
+
arg
|
39
|
+
when /^https?:\/\//
|
40
|
+
Configuration.new{|c|
|
41
|
+
c.scope_factory = SingleUrl.new(arg)
|
42
|
+
}
|
43
|
+
when ->(f){ Path(f).exists? }
|
44
|
+
arg = Path(arg)
|
45
|
+
if arg.file? && arg.ext == ".rb"
|
46
|
+
c = Kernel.instance_eval arg.read, arg.to_s
|
47
|
+
yield(c) if block_given?
|
48
|
+
c
|
49
|
+
elsif arg.file? && arg.ext == '.yml'
|
50
|
+
folder = arg.backfind("[config.rb]")
|
51
|
+
if folder && folder.exists?
|
52
|
+
dress(folder/"config.rb"){|c|
|
53
|
+
c.scope_factory = SingleYmlFile.new(arg)
|
54
|
+
}
|
55
|
+
else
|
56
|
+
Configuration.new{|c|
|
57
|
+
c.scope_factory = SingleYmlFile.new(arg)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
elsif arg.directory? and (arg/'config.rb').file?
|
61
|
+
dress(arg/'config.rb', &bl)
|
62
|
+
else
|
63
|
+
raise ArgumentError, "Missing config.rb file"
|
64
|
+
end
|
35
65
|
else
|
36
|
-
raise ArgumentError, "
|
66
|
+
raise ArgumentError, "Unable to turn `#{arg}` to a configuration"
|
37
67
|
end
|
38
68
|
end
|
39
69
|
|
@@ -51,10 +81,16 @@ module Webspicy
|
|
51
81
|
config.each_scope(&bl)
|
52
82
|
end
|
53
83
|
else
|
54
|
-
yield
|
84
|
+
yield factor_scope
|
55
85
|
end
|
56
86
|
end
|
57
87
|
|
88
|
+
attr_accessor :scope_factory
|
89
|
+
|
90
|
+
def factor_scope
|
91
|
+
@scope_factory.call(self)
|
92
|
+
end
|
93
|
+
|
58
94
|
# Adds a folder to the list of folders where test case definitions are
|
59
95
|
# to be found.
|
60
96
|
def folder(folder = nil, &bl)
|
@@ -108,7 +144,7 @@ module Webspicy
|
|
108
144
|
|
109
145
|
# Returns the defaut value for run_examples
|
110
146
|
def default_run_examples
|
111
|
-
ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'only')
|
147
|
+
ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'only' && ENV['ROBUST'] != 'generated')
|
112
148
|
end
|
113
149
|
private :default_run_examples
|
114
150
|
|
@@ -125,10 +161,27 @@ module Webspicy
|
|
125
161
|
|
126
162
|
# Returns the defaut value for run_counterexamples
|
127
163
|
def default_run_counterexamples
|
128
|
-
ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'no')
|
164
|
+
ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'no' && ENV['ROBUST'] != 'generated')
|
129
165
|
end
|
130
166
|
private :default_run_counterexamples
|
131
167
|
|
168
|
+
# Sets whether generated counter examples have to be ran or not.
|
169
|
+
def run_generated_counterexamples=(run_generated_counterexamples)
|
170
|
+
@run_generated_counterexamples = run_generated_counterexamples
|
171
|
+
end
|
172
|
+
attr_reader :run_generated_counterexamples
|
173
|
+
|
174
|
+
# Whether generated counter examples must be ran or not.
|
175
|
+
def run_generated_counterexamples?
|
176
|
+
@run_generated_counterexamples
|
177
|
+
end
|
178
|
+
|
179
|
+
# Returns the defaut value for run_generated_counterexamples
|
180
|
+
def default_run_generated_counterexamples
|
181
|
+
ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'no')
|
182
|
+
end
|
183
|
+
private :default_run_generated_counterexamples
|
184
|
+
|
132
185
|
# Installs a host (resolver).
|
133
186
|
#
|
134
187
|
# The host resolver is responsible from transforming URLs found in
|
@@ -347,7 +400,7 @@ module Webspicy
|
|
347
400
|
elsif not(self.parent.nil?)
|
348
401
|
self.parent.data_system
|
349
402
|
else
|
350
|
-
|
403
|
+
Webspicy::DEFAULT_SYSTEM
|
351
404
|
end
|
352
405
|
end
|
353
406
|
|
@@ -379,3 +432,6 @@ module Webspicy
|
|
379
432
|
|
380
433
|
end
|
381
434
|
end
|
435
|
+
require_relative 'configuration/scope'
|
436
|
+
require_relative 'configuration/single_url'
|
437
|
+
require_relative 'configuration/single_yml_file'
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Configuration
|
3
|
+
class Scope
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def preconditions
|
11
|
+
config.preconditions
|
12
|
+
end
|
13
|
+
|
14
|
+
def postconditions
|
15
|
+
config.postconditions
|
16
|
+
end
|
17
|
+
|
18
|
+
###
|
19
|
+
### Eachers -- Allow navigating the web service definitions
|
20
|
+
###
|
21
|
+
|
22
|
+
# Yields each specification file in the current scope
|
23
|
+
def each_specification_file(&bl)
|
24
|
+
return enum_for(:each_specification_file) unless block_given?
|
25
|
+
_each_specification_file(config, &bl)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Recursive implementation of `each_specification_file` for each
|
29
|
+
# folder in the configuration.
|
30
|
+
def _each_specification_file(config)
|
31
|
+
folder = config.folder
|
32
|
+
folder.glob("**/*.yml").select(&to_filter_proc(config.file_filter)).each do |file|
|
33
|
+
yield file, folder
|
34
|
+
end
|
35
|
+
end
|
36
|
+
private :_each_specification_file
|
37
|
+
|
38
|
+
# Yields each specification in the current scope in turn.
|
39
|
+
def each_specification(&bl)
|
40
|
+
return enum_for(:each_specification) unless block_given?
|
41
|
+
each_specification_file do |file, folder|
|
42
|
+
yield Webspicy.specification(file.load, file, self)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def each_service(specification, &bl)
|
47
|
+
specification.services.select(&to_filter_proc(config.service_filter)).each(&bl)
|
48
|
+
end
|
49
|
+
|
50
|
+
def each_example(service, &bl)
|
51
|
+
service.examples
|
52
|
+
.map{|e| expand_example(service, e) }
|
53
|
+
.select(&to_filter_proc(config.test_case_filter))
|
54
|
+
.each(&bl) if config.run_examples?
|
55
|
+
end
|
56
|
+
|
57
|
+
def each_counterexamples(service, &bl)
|
58
|
+
service.counterexamples
|
59
|
+
.map{|e| expand_example(service, e) }
|
60
|
+
.select(&to_filter_proc(config.test_case_filter))
|
61
|
+
.each(&bl) if config.run_counterexamples?
|
62
|
+
end
|
63
|
+
|
64
|
+
def each_generated_counterexamples(service, &bl)
|
65
|
+
Webspicy.with_scope(self) do
|
66
|
+
service.generated_counterexamples
|
67
|
+
.map{|e| expand_example(service, e) }
|
68
|
+
.select(&to_filter_proc(config.test_case_filter))
|
69
|
+
.each(&bl) if config.run_generated_counterexamples?
|
70
|
+
end if config.run_generated_counterexamples?
|
71
|
+
end
|
72
|
+
|
73
|
+
def each_testcase(service, &bl)
|
74
|
+
each_example(service, &bl)
|
75
|
+
each_counterexamples(service, &bl)
|
76
|
+
each_generated_counterexamples(service, &bl)
|
77
|
+
end
|
78
|
+
|
79
|
+
###
|
80
|
+
### Schemas -- For parsing input and output data schemas found in
|
81
|
+
### web service definitions
|
82
|
+
###
|
83
|
+
|
84
|
+
# Parses a Finitio schema based on the data system.
|
85
|
+
def parse_schema(fio)
|
86
|
+
data_system.parse(fio)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns the Data system to use for parsing schemas
|
90
|
+
def data_system
|
91
|
+
@data_system ||= config.data_system
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
###
|
96
|
+
### Service invocation: abstract the configuration about what client is
|
97
|
+
### used and how to instantiate it
|
98
|
+
###
|
99
|
+
|
100
|
+
# Returns an instance of the client to use to invoke web services
|
101
|
+
def get_client
|
102
|
+
config.client.new(self)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Convert an instantiated URL found in a webservice definition
|
106
|
+
# to a real URL, using the configuration host.
|
107
|
+
#
|
108
|
+
# When no host resolved on the configuration and the url is not
|
109
|
+
# already an absolute URL, yields the block if given, or raise
|
110
|
+
# an exception.
|
111
|
+
def to_real_url(url, test_case = nil, &bl)
|
112
|
+
case config.host
|
113
|
+
when Proc
|
114
|
+
config.host.call(url, test_case)
|
115
|
+
when String
|
116
|
+
url =~ /^http/ ? url : "#{config.host}#{url}"
|
117
|
+
else
|
118
|
+
return url if url =~ /^http/
|
119
|
+
return yield(url) if block_given?
|
120
|
+
raise "Unable to resolve `#{url}` : no host resolver provided\nSee `Configuration#host="
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
###
|
125
|
+
### Private methods
|
126
|
+
###
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def expand_example(service, example)
|
131
|
+
return example unless service.default_example
|
132
|
+
h1 = service.default_example.to_info
|
133
|
+
h2 = example.to_info
|
134
|
+
ex = Specification::TestCase.new(merge_maps(h1, h2))
|
135
|
+
ex.bind(service, example.counterexample?)
|
136
|
+
end
|
137
|
+
|
138
|
+
def merge_maps(h1, h2)
|
139
|
+
h1.merge(h2) do |k,v1,v2|
|
140
|
+
case v1
|
141
|
+
when Hash then merge_maps(v1, v2)
|
142
|
+
when Array then v1 + v2
|
143
|
+
else v2
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns a proc that implements file_filter strategy according to the
|
149
|
+
# type of filter installed
|
150
|
+
def to_filter_proc(filter)
|
151
|
+
case ff = filter
|
152
|
+
when NilClass then ->(f){ true }
|
153
|
+
when Proc then ff
|
154
|
+
when Regexp then ->(f){ ff =~ f.to_s }
|
155
|
+
else
|
156
|
+
->(f){ ff === f }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end # class Scope
|
161
|
+
end # class Configuration
|
162
|
+
end # module Webspicy
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Configuration
|
3
|
+
class SingleUrl
|
4
|
+
|
5
|
+
class SingleUrlScope < Scope
|
6
|
+
|
7
|
+
def initialize(config, url)
|
8
|
+
super(config)
|
9
|
+
@url = url
|
10
|
+
end
|
11
|
+
attr_reader :url
|
12
|
+
|
13
|
+
def each_specification(&bl)
|
14
|
+
return enum_for(:each_specification) unless block_given?
|
15
|
+
spec = <<~YML
|
16
|
+
---
|
17
|
+
name: |-
|
18
|
+
Default specification
|
19
|
+
url: |-
|
20
|
+
#{url}
|
21
|
+
|
22
|
+
services:
|
23
|
+
- method: |-
|
24
|
+
GET
|
25
|
+
description: |-
|
26
|
+
Getting #{url}
|
27
|
+
|
28
|
+
input_schema: |-
|
29
|
+
Any
|
30
|
+
output_schema: |-
|
31
|
+
Any
|
32
|
+
error_schema: |-
|
33
|
+
Any
|
34
|
+
|
35
|
+
examples:
|
36
|
+
- description: |-
|
37
|
+
it returns a 200
|
38
|
+
params: {}
|
39
|
+
expected:
|
40
|
+
status: 200
|
41
|
+
YML
|
42
|
+
Webspicy.debug(spec)
|
43
|
+
yield Webspicy.specification(spec, nil, self)
|
44
|
+
end
|
45
|
+
|
46
|
+
end # class SingleUrlScope
|
47
|
+
|
48
|
+
def initialize(url)
|
49
|
+
@url = url
|
50
|
+
end
|
51
|
+
|
52
|
+
def call(config)
|
53
|
+
SingleUrlScope.new(config, @url)
|
54
|
+
end
|
55
|
+
|
56
|
+
end # class SingleUrl
|
57
|
+
end # class Configuration
|
58
|
+
end # module Webspicy
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Configuration
|
3
|
+
class SingleYmlFile
|
4
|
+
|
5
|
+
class SingleYmlFileScope < Scope
|
6
|
+
|
7
|
+
def initialize(config, file)
|
8
|
+
super(config)
|
9
|
+
@file = file
|
10
|
+
end
|
11
|
+
attr_reader :file
|
12
|
+
|
13
|
+
def each_specification(&bl)
|
14
|
+
return enum_for(:each_specification) unless block_given?
|
15
|
+
yield Webspicy.specification(file.read, nil, self)
|
16
|
+
end
|
17
|
+
|
18
|
+
end # class SingleYmlFileScope
|
19
|
+
|
20
|
+
def initialize(file)
|
21
|
+
@file = file
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(config)
|
25
|
+
SingleYmlFileScope.new(config, @file)
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class SingleYmlFile
|
29
|
+
end # class Configuration
|
30
|
+
end # module Webspicy
|
data/lib/webspicy/formaldoc.fio
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@import finitio/data
|
2
2
|
|
3
3
|
Method =
|
4
|
-
String( s | s =~ /^(GET|POST|POST_FORM|PUT|DELETE|PATCH|OPTIONS)$/ )
|
4
|
+
String( s | s =~ /^(GET|POST|POST_FORM|PUT|DELETE|PATCH|PUT|OPTIONS)$/ )
|
5
5
|
|
6
6
|
Tag = String( s | s.length > 0 )
|
7
7
|
|
@@ -17,15 +17,30 @@ FileUpload =
|
|
17
17
|
param_name :? String
|
18
18
|
}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
Specification = .Webspicy::Specification
|
21
|
+
<info> {
|
22
|
+
name: String
|
23
|
+
url: String
|
24
|
+
services: [Service]
|
25
|
+
}
|
26
|
+
<singleservice> {
|
27
|
+
name :? String
|
28
|
+
url : String
|
29
|
+
method : Method
|
30
|
+
description : String
|
31
|
+
preconditions :? [String]|String
|
32
|
+
postconditions :? [String]|String
|
33
|
+
input_schema : Schema
|
34
|
+
output_schema : Schema
|
35
|
+
error_schema : Schema
|
36
|
+
blackbox :? String
|
37
|
+
default_example :? TestCase
|
38
|
+
examples :? [TestCase]
|
39
|
+
counterexamples :? [TestCase]
|
40
|
+
}
|
26
41
|
|
27
42
|
Service =
|
28
|
-
.Webspicy::
|
43
|
+
.Webspicy::Specification::Service <info> {
|
29
44
|
method : Method
|
30
45
|
description : String
|
31
46
|
preconditions :? [String]|String
|
@@ -40,7 +55,7 @@ Service =
|
|
40
55
|
}
|
41
56
|
|
42
57
|
TestCase =
|
43
|
-
.Webspicy::
|
58
|
+
.Webspicy::Specification::TestCase <info> {
|
44
59
|
description :? String
|
45
60
|
dress_params :? Boolean
|
46
61
|
params :? Params
|