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,63 +1,43 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Tester
|
3
3
|
class Client
|
4
|
+
extend Forwardable
|
4
5
|
|
5
6
|
def initialize(scope)
|
6
7
|
@scope = scope
|
7
8
|
end
|
8
9
|
attr_reader :scope
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def_delegators :@scope, *[
|
12
|
+
:config
|
13
|
+
]
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
if ls.size == 0
|
18
|
-
bl.call
|
19
|
-
elsif ls.size > 1
|
20
|
-
_around(ls.first, ls[1..-1], args, &bl)
|
21
|
-
else
|
22
|
-
ls.first.call(*args, &bl)
|
15
|
+
def find_and_call(method, url, mutation)
|
16
|
+
unless tc = scope.find_test_case(method, url)
|
17
|
+
raise Error, "No such service `#{method} #{url}`"
|
23
18
|
end
|
19
|
+
mutated = tc.mutate(mutation)
|
20
|
+
instrumented = instrument(mutated)
|
21
|
+
call(instrumented)
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
_around(tail.first, tail[1..-1], args, &bl)
|
32
|
-
end
|
24
|
+
def instrument(test_case)
|
25
|
+
service = test_case.service
|
26
|
+
service.preconditions.each do |pre|
|
27
|
+
pre.instrument(test_case, self) if pre.respond_to?(:instrument)
|
33
28
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
service.postconditions.each do |post|
|
30
|
+
post.instrument(test_case, self) if post.respond_to?(:instrument)
|
31
|
+
end if test_case.example?
|
32
|
+
service.errconditions.each do |post|
|
33
|
+
post.instrument(test_case, self) if post.respond_to?(:instrument)
|
34
|
+
end if test_case.counterexample?
|
39
35
|
config.listeners(:instrument).each do |i|
|
40
|
-
i.call(
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def before(*args, &bl)
|
45
|
-
args << self
|
46
|
-
config.listeners(:before_each).each do |beach|
|
47
|
-
beach.call(*args, &bl)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def after(*args, &bl)
|
52
|
-
args << self
|
53
|
-
config.listeners(:after_each).each do |aeach|
|
54
|
-
aeach.call(*args, &bl)
|
36
|
+
i.call(test_case, self)
|
55
37
|
end
|
38
|
+
test_case
|
56
39
|
end
|
57
40
|
|
58
41
|
end # class Client
|
59
42
|
end # class Tester
|
60
43
|
end # module Webspicy
|
61
|
-
require_relative 'client/support'
|
62
|
-
require_relative 'client/http_client'
|
63
|
-
require_relative 'client/rack_test_client'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class FileChecker < Tester
|
4
|
+
|
5
|
+
def default_reporter
|
6
|
+
@reporter = Reporter::Composite.new
|
7
|
+
@reporter << Reporter::FileProgress.new
|
8
|
+
@reporter << Reporter::Exceptions.new
|
9
|
+
@reporter << Reporter::FileSummary.new
|
10
|
+
@reporter << Reporter::ErrorCount.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_scope
|
14
|
+
scope.each_specification_file do |spec_file|
|
15
|
+
@specification = load_specification(spec_file)
|
16
|
+
reporter.spec_file_done
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end # class FileChecker
|
21
|
+
end # class Tester
|
22
|
+
end # module Webspicy
|
@@ -1,68 +1,35 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Tester
|
3
3
|
class Invocation
|
4
|
+
extend Forwardable
|
4
5
|
|
5
6
|
def initialize(test_case, response, client)
|
6
7
|
@test_case = test_case
|
7
8
|
@response = response
|
8
9
|
@client = client
|
9
10
|
end
|
10
|
-
|
11
11
|
attr_reader :test_case, :response, :client
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
### Getters on response
|
13
|
+
def_delegators :@client, *[
|
14
|
+
:config
|
15
|
+
]
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
### Query methods
|
26
|
-
|
27
|
-
def done?
|
28
|
-
!response.nil?
|
29
|
-
end
|
30
|
-
|
31
|
-
def is_expected_success?
|
32
|
-
test_case.expected_status.to_i >= 200 && test_case.expected_status.to_i < 300
|
33
|
-
end
|
34
|
-
|
35
|
-
def is_success?
|
36
|
-
response_code >= 200 && response_code < 300
|
37
|
-
end
|
38
|
-
|
39
|
-
def is_empty_response?
|
40
|
-
response_code == 204
|
41
|
-
end
|
17
|
+
def_delegators :@test_case, *[
|
18
|
+
:scope,
|
19
|
+
:specification,
|
20
|
+
:service
|
21
|
+
]
|
42
22
|
|
43
|
-
def
|
44
|
-
|
23
|
+
def raw_output
|
24
|
+
raise NotImplementedError
|
45
25
|
end
|
46
26
|
|
47
|
-
def
|
48
|
-
|
49
|
-
ct = ct.mime_type if ct.respond_to?(:mime_type)
|
50
|
-
case ct
|
51
|
-
when %r{json}
|
52
|
-
raise "Body empty while expected" if response.body.to_s.empty?
|
53
|
-
@loaded_body ||= ::JSON.parse(response.body)
|
54
|
-
else
|
55
|
-
response.body.to_s
|
56
|
-
end
|
27
|
+
def loaded_output
|
28
|
+
raise NotImplementedError
|
57
29
|
end
|
58
30
|
|
59
|
-
def
|
60
|
-
|
61
|
-
begin
|
62
|
-
schema.dress(loaded_body)
|
63
|
-
rescue Finitio::TypeError => ex
|
64
|
-
ex
|
65
|
-
end
|
31
|
+
def output
|
32
|
+
raise NotImplementedError
|
66
33
|
end
|
67
34
|
|
68
35
|
end # class Invocation
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class Reporter
|
4
|
+
include Support::Colorize
|
5
|
+
|
6
|
+
def initialize(io = STDOUT)
|
7
|
+
@io = io
|
8
|
+
end
|
9
|
+
attr_reader :io
|
10
|
+
|
11
|
+
def init(tester)
|
12
|
+
@tester = tester
|
13
|
+
end
|
14
|
+
attr_reader :tester
|
15
|
+
|
16
|
+
[
|
17
|
+
:config,
|
18
|
+
:scope,
|
19
|
+
:client,
|
20
|
+
:spec_file,
|
21
|
+
:specification,
|
22
|
+
:service,
|
23
|
+
:test_case,
|
24
|
+
:invocation,
|
25
|
+
:result
|
26
|
+
].each do |meth|
|
27
|
+
define_method(meth) do |*args, &bl|
|
28
|
+
tester.send(meth, *args, &bl)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
HOOKS = [
|
33
|
+
:before_all,
|
34
|
+
:before_all_done,
|
35
|
+
:before_scope,
|
36
|
+
:scope_done,
|
37
|
+
:before_spec_file,
|
38
|
+
:spec_file_error,
|
39
|
+
:spec_file_done,
|
40
|
+
:before_specification,
|
41
|
+
:specification_done,
|
42
|
+
:before_service,
|
43
|
+
:service_done,
|
44
|
+
:before_test_case,
|
45
|
+
:test_case_done,
|
46
|
+
:before_each,
|
47
|
+
:before_each_done,
|
48
|
+
:before_instrument,
|
49
|
+
:instrument_done,
|
50
|
+
:before_invocation,
|
51
|
+
:invocation_done,
|
52
|
+
:before_assertions,
|
53
|
+
:check_success,
|
54
|
+
:check_failure,
|
55
|
+
:check_error,
|
56
|
+
:assertions_done,
|
57
|
+
:after_each,
|
58
|
+
:after_each_done,
|
59
|
+
:after_all,
|
60
|
+
:after_all_done,
|
61
|
+
:report
|
62
|
+
]
|
63
|
+
|
64
|
+
HOOKS.each do |meth|
|
65
|
+
define_method(meth){|*args, &bl|
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
def plural(word, count)
|
72
|
+
"%d #{word}#{count>1 ? 's' : ''}" % [count]
|
73
|
+
end
|
74
|
+
|
75
|
+
end # class Reporter
|
76
|
+
end # class Tester
|
77
|
+
end # module Webspicy
|
78
|
+
require_relative 'reporter/error_count'
|
79
|
+
require_relative 'reporter/progress'
|
80
|
+
require_relative 'reporter/summary'
|
81
|
+
require_relative 'reporter/documentation'
|
82
|
+
require_relative 'reporter/exceptions'
|
83
|
+
require_relative 'reporter/composite'
|
84
|
+
require_relative 'reporter/file_progress'
|
85
|
+
require_relative 'reporter/file_summary'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class Reporter
|
4
|
+
class Composite < Reporter
|
5
|
+
|
6
|
+
def initialize(*args, &bl)
|
7
|
+
super
|
8
|
+
@reporters = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(reporter)
|
12
|
+
@reporters << reporter
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def init(tester)
|
17
|
+
super
|
18
|
+
@reporters.each do |r|
|
19
|
+
r.init(tester)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
HOOKS.each do |meth|
|
24
|
+
define_method(meth) do |*args, &bl|
|
25
|
+
@reporters.each do |r|
|
26
|
+
r.send(meth, *args, &bl)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find(kind)
|
32
|
+
@reporters.find{|r| r.is_a?(kind) }
|
33
|
+
end
|
34
|
+
|
35
|
+
end # class Composite
|
36
|
+
end # class Reporter
|
37
|
+
end # class Tester
|
38
|
+
end # module Webspicy
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class Reporter
|
4
|
+
class Documentation < Reporter
|
5
|
+
|
6
|
+
module Helpers
|
7
|
+
def spec_file_error_line(spec_file, ex)
|
8
|
+
str = colorize_highlight(spec_file.to_s)
|
9
|
+
str += "\n " + colorize_error("X #{ex.message}")
|
10
|
+
if ex.root_cause && ex.root_cause != ex
|
11
|
+
str += "\n " + colorize_error("#{ex.root_cause.message}")
|
12
|
+
end
|
13
|
+
str
|
14
|
+
end
|
15
|
+
|
16
|
+
def service_line(service, test_case)
|
17
|
+
str = service.to_s + ", " + test_case.to_s
|
18
|
+
str = colorize_highlight(str)
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_success_line(check)
|
22
|
+
" " + colorize_success("v") + " " + check.behavior
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_failure_line(check, ex)
|
26
|
+
" " + colorize_error("F " + ex.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_error_line(check, ex)
|
30
|
+
" " + colorize_error("E " + ex.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
include Helpers
|
34
|
+
|
35
|
+
def spec_file_error(e)
|
36
|
+
io.puts spec_file_error_line(spec_file, e)
|
37
|
+
io.puts
|
38
|
+
end
|
39
|
+
|
40
|
+
def before_test_case
|
41
|
+
io.puts service_line(service, test_case)
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_success(check)
|
45
|
+
io.puts check_success_line(check)
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_failure(check, ex)
|
49
|
+
io.puts check_failure_line(check, ex)
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_error(check, ex)
|
53
|
+
io.puts check_error_line(check, ex)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_case_done
|
57
|
+
io.puts
|
58
|
+
end
|
59
|
+
|
60
|
+
def service_done
|
61
|
+
io.puts
|
62
|
+
end
|
63
|
+
|
64
|
+
end # class Documentation
|
65
|
+
end # class Reporter
|
66
|
+
end # class Tester
|
67
|
+
end # module Webspicy
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class Reporter
|
4
|
+
class ErrorCount < Reporter
|
5
|
+
|
6
|
+
def initialize(*args, &bl)
|
7
|
+
super
|
8
|
+
@error_count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_error(*args, &bl)
|
12
|
+
@error_count += 1
|
13
|
+
end
|
14
|
+
alias :spec_file_error :on_error
|
15
|
+
alias :check_failure :on_error
|
16
|
+
alias :check_error :on_error
|
17
|
+
|
18
|
+
def report
|
19
|
+
@error_count
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class ErrorCount
|
23
|
+
end # class Reporter
|
24
|
+
end # class Tester
|
25
|
+
end # module Webspicy
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Webspicy
|
2
|
+
class Tester
|
3
|
+
class Reporter
|
4
|
+
class Exceptions < Reporter
|
5
|
+
include Documentation::Helpers
|
6
|
+
|
7
|
+
def initialize(*args, &bl)
|
8
|
+
super
|
9
|
+
@spec_file_errors = []
|
10
|
+
@failed_results = []
|
11
|
+
end
|
12
|
+
attr_reader :failed_results, :spec_file_errors
|
13
|
+
|
14
|
+
def spec_file_error(e)
|
15
|
+
@spec_file_errors << spec_file_error_line(spec_file, e)
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_each_done
|
19
|
+
@failed_results << result unless result.success?
|
20
|
+
end
|
21
|
+
|
22
|
+
def report
|
23
|
+
report_spec_file_errors
|
24
|
+
report_failed_results
|
25
|
+
end
|
26
|
+
|
27
|
+
def report_spec_file_errors
|
28
|
+
return if spec_file_errors.empty?
|
29
|
+
io.puts
|
30
|
+
io.puts "Invalid specs:"
|
31
|
+
io.puts
|
32
|
+
spec_file_errors.each do |e|
|
33
|
+
io.puts e
|
34
|
+
end
|
35
|
+
io.puts
|
36
|
+
end
|
37
|
+
|
38
|
+
def report_failed_results
|
39
|
+
return if failed_results.empty?
|
40
|
+
io.puts
|
41
|
+
io.puts "Exceptions:"
|
42
|
+
io.puts
|
43
|
+
failed_results.each_with_index do |result,i|
|
44
|
+
io.puts service_line(result.service, result.test_case)
|
45
|
+
result.failures.each do |(c,e)|
|
46
|
+
io.puts check_failure_line(c,e)
|
47
|
+
end
|
48
|
+
result.errors.each do |(c,e)|
|
49
|
+
io.puts check_error_line(c,e)
|
50
|
+
io.puts e.backtrace.join("\n").gsub(/^/, " ") if e.backtrace
|
51
|
+
end
|
52
|
+
io.puts
|
53
|
+
end
|
54
|
+
io.puts
|
55
|
+
end
|
56
|
+
|
57
|
+
end # class Exceptions
|
58
|
+
end # class Reporter
|
59
|
+
end # class Tester
|
60
|
+
end # module Webspicy
|