webspicy 0.18.0 → 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/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 +17 -7
- data/lib/webspicy/configuration.rb +48 -8
- data/lib/webspicy/configuration/scope.rb +22 -8
- data/lib/webspicy/formaldoc.fio +5 -5
- data/lib/webspicy/specification.rb +2 -0
- data/lib/webspicy/specification/condition.rb +23 -0
- data/lib/webspicy/specification/errcondition.rb +1 -0
- data/lib/webspicy/specification/postcondition.rb +1 -0
- data/lib/webspicy/specification/precondition.rb +1 -0
- data/lib/webspicy/specification/service.rb +11 -6
- data/lib/webspicy/specification/test_case.rb +8 -9
- data/lib/webspicy/support.rb +21 -0
- data/lib/webspicy/support/hooks.rb +65 -0
- data/lib/webspicy/support/world.rb +47 -0
- data/lib/webspicy/tester.rb +136 -3
- data/lib/webspicy/tester/client.rb +22 -42
- data/lib/webspicy/tester/file_checker.rb +22 -0
- data/lib/webspicy/tester/invocation.rb +15 -48
- 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 +1 -1
- 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/{mocker → web/mocker}/config.ru +3 -2
- data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
- data/lib/webspicy/web/openapi/generator.rb +129 -0
- 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 +49 -0
- data/spec/unit/web/mocker/test_mocker.rb +35 -0
- data/spec/unit/web/openapi/test_generator.rb +31 -0
- metadata +61 -59
- data/examples/restful/Gemfile +0 -5
- data/examples/restful/Rakefile +0 -25
- data/examples/restful/app.rb +0 -180
- data/examples/restful/webspicy/config.rb +0 -24
- data/examples/restful/webspicy/formaldef/todo/_one/delete.yml +0 -55
- data/examples/restful/webspicy/formaldef/todo/_one/get.simpler.yml +0 -46
- data/examples/restful/webspicy/formaldef/todo/_one/get.yml +0 -50
- data/examples/restful/webspicy/formaldef/todo/_one/patch.yml +0 -66
- data/examples/restful/webspicy/formaldef/todo/_one/put.yml +0 -65
- data/examples/restful/webspicy/formaldef/todo/get.yml +0 -36
- data/examples/restful/webspicy/formaldef/todo/options.yml +0 -32
- data/examples/restful/webspicy/formaldef/todo/post.csv.yml +0 -43
- data/examples/restful/webspicy/formaldef/todo/post.file.yml +0 -40
- data/examples/restful/webspicy/formaldef/todo/post.yml +0 -51
- data/examples/restful/webspicy/formaldef/todo/todos.csv +0 -4
- 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_not_removed.rb +0 -21
- data/examples/restful/webspicy/support/todo_removed.rb +0 -20
- 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 -30
- data/examples/website/specification/get-https.yml +0 -30
- data/lib/webspicy/checker.rb +0 -10
- data/lib/webspicy/mocker.rb +0 -88
- data/lib/webspicy/openapi/generator.rb +0 -127
- data/lib/webspicy/rspec/checker.rb +0 -2
- data/lib/webspicy/rspec/checker/rspec_checker.rb +0 -24
- data/lib/webspicy/rspec/support/rspec_runnable.rb +0 -27
- data/lib/webspicy/rspec/tester.rb +0 -4
- data/lib/webspicy/rspec/tester/rspec_asserter.rb +0 -121
- data/lib/webspicy/rspec/tester/rspec_matchers.rb +0 -114
- data/lib/webspicy/rspec/tester/rspec_tester.rb +0 -63
- data/spec/unit/mocker/test_mocker.rb +0 -32
- data/spec/unit/openapi/test_generator.rb +0 -28
@@ -1,51 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: |-
|
3
|
-
Todo
|
4
|
-
|
5
|
-
url: |-
|
6
|
-
/todo/
|
7
|
-
|
8
|
-
services:
|
9
|
-
- method: |-
|
10
|
-
POST
|
11
|
-
|
12
|
-
description: |-
|
13
|
-
Creates a new todo item
|
14
|
-
|
15
|
-
preconditions:
|
16
|
-
- Must be authenticated
|
17
|
-
|
18
|
-
input_schema: |-
|
19
|
-
Todo
|
20
|
-
|
21
|
-
output_schema: |-
|
22
|
-
Todo
|
23
|
-
|
24
|
-
error_schema: |-
|
25
|
-
ErrorSchema
|
26
|
-
|
27
|
-
examples:
|
28
|
-
|
29
|
-
- description: |-
|
30
|
-
when requested with a non existing ID
|
31
|
-
params:
|
32
|
-
id: 3
|
33
|
-
description: "Hello World"
|
34
|
-
expected:
|
35
|
-
content_type: application/json
|
36
|
-
status: 201
|
37
|
-
assert:
|
38
|
-
- "pathFD('', id: 3)"
|
39
|
-
|
40
|
-
counterexamples:
|
41
|
-
|
42
|
-
- description: |-
|
43
|
-
when requested while the id already exists
|
44
|
-
params:
|
45
|
-
id: 1
|
46
|
-
description: "Hello World"
|
47
|
-
expected:
|
48
|
-
content_type: application/json
|
49
|
-
status: 409
|
50
|
-
assert:
|
51
|
-
- "pathFD('', error: 'Identifier already in use')"
|
@@ -1,20 +0,0 @@
|
|
1
|
-
@import webspicy/scalars
|
2
|
-
|
3
|
-
Todo = {
|
4
|
-
id : Integer
|
5
|
-
description : String
|
6
|
-
}
|
7
|
-
|
8
|
-
TodoPatch = {
|
9
|
-
id : Integer
|
10
|
-
description :? String
|
11
|
-
}
|
12
|
-
|
13
|
-
TodoPut = {
|
14
|
-
id : Integer
|
15
|
-
description : String
|
16
|
-
}
|
17
|
-
|
18
|
-
ErrorSchema = {
|
19
|
-
error: String
|
20
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative 'must_be_authenticated'
|
2
|
-
class MustBeAnAdmin < MustBeAuthenticated
|
3
|
-
include Webspicy::Precondition
|
4
|
-
|
5
|
-
def self.match(service, pre)
|
6
|
-
MustBeAnAdmin.new(:admin) if pre =~ /Must be an admin/
|
7
|
-
end
|
8
|
-
|
9
|
-
def counterexamples(service)
|
10
|
-
examples = super
|
11
|
-
examples << counterexample(
|
12
|
-
"When authenticated as a normal user",
|
13
|
-
"user",
|
14
|
-
"Admin required",
|
15
|
-
401
|
16
|
-
)
|
17
|
-
examples
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class MustBeAuthenticated
|
2
|
-
include Webspicy::Precondition
|
3
|
-
|
4
|
-
def initialize(role = :user)
|
5
|
-
@role = role
|
6
|
-
end
|
7
|
-
attr_reader :role
|
8
|
-
|
9
|
-
def self.match(service, pre)
|
10
|
-
MustBeAuthenticated.new if pre =~ /Must be authenticated/
|
11
|
-
end
|
12
|
-
|
13
|
-
def instrument(test_case, client)
|
14
|
-
return if test_case.metadata.has_key?(:role)
|
15
|
-
return if test_case.description =~ /When not authenticated at all/
|
16
|
-
test_case.metadata[:role] = role
|
17
|
-
end
|
18
|
-
|
19
|
-
def counterexamples(service)
|
20
|
-
examples = super
|
21
|
-
examples << counterexample(
|
22
|
-
"When not authenticated at all",
|
23
|
-
"~",
|
24
|
-
"Please log in first",
|
25
|
-
401
|
26
|
-
)
|
27
|
-
examples
|
28
|
-
end
|
29
|
-
|
30
|
-
def counterexample(description, role, expected, status = 401)
|
31
|
-
YAML.load <<-YML.gsub(/^\s+[#][ ]/, "")
|
32
|
-
# description: |-
|
33
|
-
# #{description} (#{self.class.name} PRE)
|
34
|
-
# params:
|
35
|
-
# id: 1
|
36
|
-
# dress_params:
|
37
|
-
# false
|
38
|
-
# metadata:
|
39
|
-
# role: #{role}
|
40
|
-
# expected:
|
41
|
-
# content_type: application/json
|
42
|
-
# status: #{status}
|
43
|
-
# assert:
|
44
|
-
# - "pathFD('', error: '#{expected}')"
|
45
|
-
YML
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,20 +0,0 @@
|
|
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
|
@@ -1,59 +0,0 @@
|
|
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')"
|
data/examples/website/config.rb
DELETED
data/examples/website/schema.fio
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
@import webspicy/scalars
|
@@ -1,30 +0,0 @@
|
|
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
|
@@ -1,30 +0,0 @@
|
|
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
|
data/lib/webspicy/checker.rb
DELETED
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
|