webspicy 0.16.2 → 0.20.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 +9 -3
- 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 +18 -9
- data/lib/webspicy/configuration.rb +57 -8
- data/lib/webspicy/configuration/scope.rb +22 -16
- data/lib/webspicy/formaldoc.fio +7 -5
- data/lib/webspicy/specification.rb +10 -9
- data/lib/webspicy/specification/condition.rb +48 -0
- data/lib/webspicy/specification/err.rb +18 -0
- data/lib/webspicy/specification/oldies.rb +4 -0
- data/lib/webspicy/specification/oldies/bridge.rb +29 -0
- data/lib/webspicy/specification/oldies/errcondition.rb +22 -0
- data/lib/webspicy/specification/{postcondition.rb → oldies/postcondition.rb} +6 -0
- data/lib/webspicy/specification/{precondition.rb → oldies/precondition.rb} +6 -2
- data/lib/webspicy/specification/post.rb +20 -0
- data/lib/webspicy/specification/post/missing_condition_impl.rb +15 -0
- data/lib/webspicy/specification/post/unexpected_condition_impl.rb +15 -0
- data/lib/webspicy/specification/pre.rb +19 -0
- data/lib/webspicy/specification/{precondition → pre}/global_request_headers.rb +4 -4
- data/lib/webspicy/specification/{precondition → pre}/robust_to_invalid_input.rb +5 -5
- data/lib/webspicy/specification/service.rb +58 -24
- data/lib/webspicy/specification/test_case.rb +10 -17
- data/lib/webspicy/support.rb +32 -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 +180 -60
- data/lib/webspicy/tester/asserter.rb +9 -4
- data/lib/webspicy/tester/assertions.rb +8 -9
- data/lib/webspicy/tester/client.rb +4 -50
- data/lib/webspicy/tester/failure.rb +6 -0
- data/lib/webspicy/tester/fakeses.rb +41 -0
- data/lib/webspicy/tester/fakeses/email.rb +38 -0
- data/lib/webspicy/tester/fakesmtp.rb +39 -0
- data/lib/webspicy/tester/fakesmtp/email.rb +27 -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 +74 -0
- data/lib/webspicy/tester/reporter/error_count.rb +25 -0
- data/lib/webspicy/tester/reporter/exceptions.rb +62 -0
- data/lib/webspicy/tester/reporter/file_progress.rb +25 -0
- data/lib/webspicy/tester/reporter/file_summary.rb +43 -0
- data/lib/webspicy/tester/reporter/progress.rb +30 -0
- data/lib/webspicy/tester/reporter/summary.rb +63 -0
- data/lib/webspicy/tester/result.rb +142 -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/invocation_succeeded.rb +13 -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/{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/configuration/scope/test_each_service.rb +2 -2
- data/spec/unit/configuration/scope/test_each_specification.rb +7 -7
- data/spec/unit/specification/{precondition → pre}/test_global_request_headers.rb +9 -4
- data/spec/unit/specification/test_condition.rb +44 -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/fakeses/test_email.rb +40 -0
- 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 +90 -67
- 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 -30
- data/examples/website/specification/get-https.yml +0 -30
- 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
@@ -1,13 +1,12 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Specification
|
3
3
|
class Service
|
4
|
+
include Support::DataObject
|
4
5
|
|
5
6
|
def initialize(raw)
|
6
|
-
|
7
|
+
super(raw)
|
7
8
|
bind_examples
|
8
9
|
bind_counterexamples
|
9
|
-
@preconditions = compile_preconditions
|
10
|
-
@postconditions = compile_postconditions
|
11
10
|
end
|
12
11
|
attr_accessor :specification
|
13
12
|
|
@@ -15,6 +14,10 @@ module Webspicy
|
|
15
14
|
new(raw)
|
16
15
|
end
|
17
16
|
|
17
|
+
def config
|
18
|
+
specification.config
|
19
|
+
end
|
20
|
+
|
18
21
|
def method
|
19
22
|
@raw[:method]
|
20
23
|
end
|
@@ -24,7 +27,7 @@ module Webspicy
|
|
24
27
|
end
|
25
28
|
|
26
29
|
def preconditions
|
27
|
-
@preconditions
|
30
|
+
@preconditions ||= compile_preconditions
|
28
31
|
end
|
29
32
|
|
30
33
|
def has_preconditions?
|
@@ -32,23 +35,31 @@ module Webspicy
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def postconditions
|
35
|
-
@postconditions
|
38
|
+
@postconditions ||= compile_postconditions
|
36
39
|
end
|
37
40
|
|
38
41
|
def has_postconditions?
|
39
42
|
!postconditions.empty?
|
40
43
|
end
|
41
44
|
|
45
|
+
def errconditions
|
46
|
+
@errconditions ||= compile_errconditions
|
47
|
+
end
|
48
|
+
|
49
|
+
def has_errconditions?
|
50
|
+
!errconditions.empty?
|
51
|
+
end
|
52
|
+
|
42
53
|
def default_example
|
43
54
|
@raw[:default_example]
|
44
55
|
end
|
45
56
|
|
46
57
|
def examples
|
47
|
-
@raw[:examples]
|
58
|
+
@raw[:examples] || []
|
48
59
|
end
|
49
60
|
|
50
61
|
def counterexamples
|
51
|
-
@raw[:counterexamples]
|
62
|
+
@raw[:counterexamples] || []
|
52
63
|
end
|
53
64
|
|
54
65
|
def generated_counterexamples
|
@@ -76,49 +87,72 @@ module Webspicy
|
|
76
87
|
input_schema.dress(params)
|
77
88
|
end
|
78
89
|
|
79
|
-
def to_info
|
80
|
-
@raw
|
81
|
-
end
|
82
|
-
|
83
90
|
def to_s
|
84
91
|
"#{method} #{specification.url}"
|
85
92
|
end
|
86
93
|
|
87
94
|
private
|
88
95
|
|
89
|
-
def scope
|
90
|
-
Webspicy.current_scope
|
91
|
-
end
|
92
|
-
|
93
96
|
def compile_preconditions
|
94
97
|
@raw[:preconditions] = [@raw[:preconditions]] if @raw[:preconditions].is_a?(String)
|
95
|
-
compile_conditions(@raw[:preconditions] ||= [],
|
98
|
+
compile_conditions(@raw[:preconditions] ||= [], config.preconditions)
|
96
99
|
end
|
97
100
|
|
98
101
|
def compile_postconditions
|
99
102
|
@raw[:postconditions] = [@raw[:postconditions]] if @raw[:postconditions].is_a?(String)
|
100
|
-
compile_conditions(@raw[:postconditions] ||= [],
|
103
|
+
compile_conditions(@raw[:postconditions] ||= [], config.postconditions)
|
104
|
+
end
|
105
|
+
|
106
|
+
def compile_errconditions
|
107
|
+
@raw[:errconditions] = [@raw[:errconditions]] if @raw[:errconditions].is_a?(String)
|
108
|
+
compile_conditions(@raw[:errconditions] ||= [], config.errconditions)
|
101
109
|
end
|
102
110
|
|
103
111
|
def compile_conditions(descriptions, conditions)
|
104
112
|
# Because we want pre & post to be able to match in all cases
|
105
113
|
# we need at least one condition
|
106
|
-
descriptions = [
|
107
|
-
|
108
|
-
|
109
|
-
|
114
|
+
descriptions = [Condition::MATCH_ALL] if descriptions.empty?
|
115
|
+
mapping = {}
|
116
|
+
instances = conditions.map{|c|
|
117
|
+
instance = nil
|
118
|
+
descr = descriptions.find do |d|
|
119
|
+
instance = c.match(self, d)
|
120
|
+
end
|
121
|
+
instance.tap{|i|
|
122
|
+
mapping[descr] ||= i if i
|
123
|
+
i.matching_description = descr if i.respond_to?(:matching_description=)
|
124
|
+
}
|
125
|
+
}.compact
|
126
|
+
mapped = descriptions
|
127
|
+
.select{|d| mapping[d] }
|
128
|
+
.map{|d| mapping[d] }
|
129
|
+
unmapped = descriptions
|
130
|
+
.reject{|d| mapping[d] }
|
131
|
+
.select{|d| d.strip =~ /^(\(\w+\))?\(x\)/ }
|
132
|
+
.map{|d|
|
133
|
+
Postcondition::MissingConditionImpl.new.tap{|mc|
|
134
|
+
mc.matching_description = d
|
135
|
+
}
|
136
|
+
}
|
137
|
+
unexpected = descriptions
|
138
|
+
.select{|d| mapping[d] }
|
139
|
+
.select{|d| d.strip =~ /^(\(\w+\))?\( \)/ }
|
140
|
+
.map{|d|
|
141
|
+
Postcondition::UnexpectedConditionImpl.new.tap{|mc|
|
142
|
+
mc.matching_description = d
|
143
|
+
}
|
110
144
|
}
|
111
|
-
|
145
|
+
mapped + unmapped + unexpected
|
112
146
|
end
|
113
147
|
|
114
148
|
def bind_examples
|
115
|
-
|
149
|
+
examples.each do |ex|
|
116
150
|
ex.bind(self, false)
|
117
151
|
end
|
118
152
|
end
|
119
153
|
|
120
154
|
def bind_counterexamples
|
121
|
-
|
155
|
+
counterexamples.each do |ex|
|
122
156
|
ex.bind(self, true)
|
123
157
|
end
|
124
158
|
end
|
@@ -1,23 +1,25 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Specification
|
3
3
|
class TestCase
|
4
|
+
include Support::DataObject
|
4
5
|
|
5
6
|
def initialize(raw)
|
6
|
-
|
7
|
+
super(raw)
|
7
8
|
@counterexample = nil
|
8
9
|
end
|
9
10
|
attr_reader :service
|
10
11
|
attr_reader :counterexample
|
11
12
|
|
12
|
-
attr_accessor :raw
|
13
|
-
protected :raw, :raw=
|
14
|
-
|
15
13
|
def bind(service, counterexample)
|
16
14
|
@service = service
|
17
15
|
@counterexample = counterexample
|
18
16
|
self
|
19
17
|
end
|
20
18
|
|
19
|
+
def example?
|
20
|
+
!@counterexample
|
21
|
+
end
|
22
|
+
|
21
23
|
def counterexample?
|
22
24
|
!!@counterexample
|
23
25
|
end
|
@@ -87,6 +89,10 @@ module Webspicy
|
|
87
89
|
expected_status === status
|
88
90
|
end
|
89
91
|
|
92
|
+
def has_expected_status?
|
93
|
+
not expected[:status].nil?
|
94
|
+
end
|
95
|
+
|
90
96
|
def expected_error
|
91
97
|
expected[:error]
|
92
98
|
end
|
@@ -111,19 +117,6 @@ module Webspicy
|
|
111
117
|
!assert.empty?
|
112
118
|
end
|
113
119
|
|
114
|
-
def to_info
|
115
|
-
@raw
|
116
|
-
end
|
117
|
-
|
118
|
-
def instrument(client)
|
119
|
-
service.preconditions.each do |pre|
|
120
|
-
pre.instrument(self, client)
|
121
|
-
end
|
122
|
-
service.postconditions.each do |post|
|
123
|
-
post.instrument(self, client) if post.respond_to?(:instrument)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
120
|
def mutate(override)
|
128
121
|
m = self.dup
|
129
122
|
m.raw = self.raw.merge(override)
|
data/lib/webspicy/support.rb
CHANGED
@@ -1,2 +1,34 @@
|
|
1
|
+
module Webspicy
|
2
|
+
module Support
|
3
|
+
|
4
|
+
SORL_OPTS = { max: 5, wait: 0.05, raise: false }
|
5
|
+
|
6
|
+
def sooner_or_later(opts = nil, &bl)
|
7
|
+
opts = SORL_OPTS.merge(opts || {})
|
8
|
+
left, wait_ms = opts[:max], opts[:wait]
|
9
|
+
r = _sooner_or_later(&bl)
|
10
|
+
until (r && !r.is_a?(Tester::Failure)) || left == 0
|
11
|
+
sleep(wait_ms)
|
12
|
+
wait_ms, left = wait_ms*2, left - 1
|
13
|
+
r = _sooner_or_later(&bl)
|
14
|
+
end
|
15
|
+
raise r if r.is_a?(Tester::Failure)
|
16
|
+
raise TimeoutError, "Timeout on sooner-or-later" if r.nil? && opts[:raise]
|
17
|
+
r
|
18
|
+
end
|
19
|
+
module_function :sooner_or_later
|
20
|
+
|
21
|
+
def _sooner_or_later(&bl)
|
22
|
+
bl.call
|
23
|
+
rescue Tester::Failure => ex
|
24
|
+
ex
|
25
|
+
end
|
26
|
+
module_function :_sooner_or_later
|
27
|
+
|
28
|
+
end # module Support
|
29
|
+
end # module Webspicy
|
30
|
+
require_relative 'support/data_object'
|
1
31
|
require_relative 'support/status_range'
|
2
32
|
require_relative 'support/colorize'
|
33
|
+
require_relative 'support/world'
|
34
|
+
require_relative 'support/hooks'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Webspicy
|
2
|
+
module Support
|
3
|
+
module DataObject
|
4
|
+
|
5
|
+
def initialize(raw)
|
6
|
+
@raw = raw
|
7
|
+
end
|
8
|
+
attr_accessor :raw
|
9
|
+
protected :raw, :raw=
|
10
|
+
|
11
|
+
def method_missing(name, *args, &bl)
|
12
|
+
if @raw.has_key?(name) && args.empty? && bl.nil?
|
13
|
+
@raw[name]
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_info
|
20
|
+
@raw
|
21
|
+
end
|
22
|
+
|
23
|
+
end # module DataObject
|
24
|
+
end # module Support
|
25
|
+
end # module Webspicy
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Webspicy
|
2
|
+
module Support
|
3
|
+
module Hooks
|
4
|
+
|
5
|
+
class Object
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
attr_accessor :config
|
10
|
+
include Hooks
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.for(config)
|
14
|
+
Object.new(config)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fire_around(*args, &bl)
|
18
|
+
ls = config.listeners(:around_each)
|
19
|
+
if ls.size == 0
|
20
|
+
bl.call
|
21
|
+
elsif ls.size > 1
|
22
|
+
_fire_around(ls.first, ls[1..-1], args, &bl)
|
23
|
+
else
|
24
|
+
ls.first.call(*args, &bl)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def _fire_around(head, tail, args, &bl)
|
29
|
+
head.call(*args) do
|
30
|
+
if tail.empty?
|
31
|
+
bl.call
|
32
|
+
else
|
33
|
+
_fire_around(tail.first, tail[1..-1], args, &bl)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
private :_fire_around
|
38
|
+
|
39
|
+
def fire_before_each(*args, &bl)
|
40
|
+
config.listeners(:before_each).each do |beach|
|
41
|
+
beach.call(*args, &bl)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def fire_after_each(*args, &bl)
|
46
|
+
config.listeners(:after_each).each do |aeach|
|
47
|
+
aeach.call(*args, &bl)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def fire_before_all(*args, &bl)
|
52
|
+
config.listeners(:before_all).each do |beach|
|
53
|
+
beach.call(*args, &bl)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def fire_after_all(*args, &bl)
|
58
|
+
config.listeners(:after_all).each do |aeach|
|
59
|
+
aeach.call(*args, &bl)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end # module Hooks
|
64
|
+
end # module Support
|
65
|
+
end # module Webspicy
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Webspicy
|
2
|
+
module Support
|
3
|
+
class World < OpenStruct
|
4
|
+
|
5
|
+
def initialize(folder, config = nil)
|
6
|
+
super({})
|
7
|
+
@folder = folder
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
attr_reader :folder, :config
|
11
|
+
|
12
|
+
def method_missing(name, *args, &bl)
|
13
|
+
return super if name =~ /=$/
|
14
|
+
file = ['json', 'yml', 'yaml', 'rb']
|
15
|
+
.map{|e| folder/"#{name}.#{e}" }
|
16
|
+
.find{|f| f.file? }
|
17
|
+
data = case file && file.ext
|
18
|
+
when /json/
|
19
|
+
JSON.parse(file.read, object_class: OpenStruct)
|
20
|
+
when /ya?ml/
|
21
|
+
JSON.parse(file.load.to_json, object_class: OpenStruct)
|
22
|
+
when /rb/
|
23
|
+
::Kernel.eval(file.read).tap{|x|
|
24
|
+
x.config = self.config if x.is_a?(Item)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
self.send(:"#{name}=", data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_data(which)
|
31
|
+
case which
|
32
|
+
when Hash
|
33
|
+
OpenStruct.new(which)
|
34
|
+
when Array
|
35
|
+
which.map{|x| to_data(x) }
|
36
|
+
else
|
37
|
+
which
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Item
|
42
|
+
attr_accessor :config
|
43
|
+
end # module Item
|
44
|
+
|
45
|
+
end # class World
|
46
|
+
end # module Support
|
47
|
+
end # module Webspicy
|
data/lib/webspicy/tester.rb
CHANGED
@@ -1,89 +1,209 @@
|
|
1
1
|
module Webspicy
|
2
2
|
class Tester
|
3
|
-
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
class FailFast < Exception; end
|
4
6
|
|
5
7
|
def initialize(config)
|
6
8
|
@config = Configuration.dress(config)
|
7
|
-
@
|
9
|
+
@scope = nil
|
10
|
+
@hooks = nil
|
11
|
+
@client = nil
|
12
|
+
@spec_file = nil
|
13
|
+
@specification = nil
|
14
|
+
@service = nil
|
15
|
+
@test_case = nil
|
16
|
+
@invocation = nil
|
17
|
+
@invocation_error = nil
|
18
|
+
@reporter = default_reporter
|
8
19
|
end
|
9
|
-
attr_reader :config
|
20
|
+
attr_reader :config, :scope, :hooks, :client
|
21
|
+
attr_reader :specification, :spec_file
|
22
|
+
attr_reader :service, :test_case
|
23
|
+
attr_reader :invocation, :invocation_error, :result
|
24
|
+
attr_reader :reporter
|
25
|
+
|
26
|
+
def_delegators :@config, *[
|
27
|
+
:world
|
28
|
+
]
|
10
29
|
|
11
|
-
def
|
12
|
-
|
13
|
-
options = RSpec::Core::ConfigurationOptions.new(config.rspec_options)
|
14
|
-
conf = RSpec::Core::Configuration.new
|
15
|
-
RSpec::Core::Runner.new(options, conf).run(err, out)
|
30
|
+
def failfast?
|
31
|
+
config.failfast
|
16
32
|
end
|
17
33
|
|
18
|
-
|
34
|
+
def default_reporter
|
35
|
+
@reporter = Reporter::Composite.new
|
36
|
+
#@reporter << Reporter::Progress.new
|
37
|
+
@reporter << Reporter::Documentation.new
|
38
|
+
@reporter << Reporter::Exceptions.new
|
39
|
+
@reporter << Reporter::Summary.new
|
40
|
+
@reporter << Reporter::ErrorCount.new
|
41
|
+
end
|
19
42
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
def call
|
44
|
+
reporter.init(self)
|
45
|
+
begin
|
46
|
+
run_config
|
47
|
+
rescue FailFast
|
48
|
+
end
|
49
|
+
reporter.report
|
50
|
+
reporter.find(Reporter::ErrorCount).report
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_and_call(method, url, mutation)
|
54
|
+
unless tc = scope.find_test_case(method, url)
|
55
|
+
raise Error, "No such service `#{method} #{url}`"
|
56
|
+
end
|
57
|
+
mutated = tc.mutate(mutation)
|
58
|
+
fork_tester(test_case: mutated) do |t|
|
59
|
+
instrumented = t.instrument_test_case
|
60
|
+
t.client.call(instrumented)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def run_config
|
67
|
+
config.each_scope do |scope|
|
68
|
+
@scope = scope
|
69
|
+
@hooks = Support::Hooks.for(scope.config)
|
70
|
+
@client = scope.get_client
|
71
|
+
reporter.before_all
|
72
|
+
@hooks.fire_before_all(self)
|
73
|
+
reporter.before_all_done
|
74
|
+
reporter.before_scope
|
75
|
+
run_scope
|
76
|
+
reporter.scope_done
|
77
|
+
reporter.after_all
|
78
|
+
@hooks.fire_after_all(self)
|
79
|
+
reporter.after_all_done
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_scope
|
84
|
+
scope.each_specification_file do |spec_file|
|
85
|
+
@specification = load_specification(spec_file)
|
86
|
+
if @specification
|
87
|
+
reporter.before_specification
|
88
|
+
run_specification
|
89
|
+
reporter.specification_done
|
90
|
+
reporter.spec_file_done
|
91
|
+
elsif failfast?
|
92
|
+
raise FailFast
|
42
93
|
end
|
43
94
|
end
|
44
|
-
self
|
45
95
|
end
|
46
96
|
|
47
|
-
def
|
97
|
+
def load_specification(spec_file)
|
98
|
+
@spec_file = spec_file
|
99
|
+
reporter.before_spec_file
|
100
|
+
Webspicy.specification(spec_file.load, spec_file, scope)
|
101
|
+
rescue *PASSTHROUGH_EXCEPTIONS
|
102
|
+
raise
|
103
|
+
rescue Exception => e
|
104
|
+
reporter.spec_file_error(e)
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def run_specification
|
109
|
+
scope.each_service(specification) do |service|
|
110
|
+
@service = service
|
111
|
+
reporter.before_service
|
112
|
+
run_service
|
113
|
+
reporter.service_done
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def run_service
|
48
118
|
scope.each_testcase(service) do |test_case|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
119
|
+
@test_case = test_case
|
120
|
+
reporter.before_test_case
|
121
|
+
run_test_case
|
122
|
+
reporter.test_case_done
|
54
123
|
end
|
55
124
|
end
|
56
125
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
client.before(test_case)
|
63
|
-
test_case.instrument(client)
|
64
|
-
client.instrument(test_case)
|
65
|
-
@response = client.call(test_case)
|
66
|
-
@invocation = Tester::Invocation.new(test_case, @response, client)
|
67
|
-
example.run
|
68
|
-
client.after(test_case, @invocation)
|
69
|
-
@invocation
|
70
|
-
end
|
71
|
-
end
|
126
|
+
def run_test_case
|
127
|
+
hooks.fire_around(self) do
|
128
|
+
reporter.before_each
|
129
|
+
hooks.fire_before_each(self)
|
130
|
+
reporter.before_each_done
|
72
131
|
|
73
|
-
|
74
|
-
|
75
|
-
|
132
|
+
reporter.before_instrument
|
133
|
+
instrument_test_case
|
134
|
+
reporter.instrument_done
|
76
135
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
136
|
+
call_test_case_target
|
137
|
+
|
138
|
+
reporter.before_assertions
|
139
|
+
check_invocation
|
140
|
+
reporter.assertions_done
|
141
|
+
|
142
|
+
reporter.after_each
|
143
|
+
hooks.fire_after_each(self)
|
144
|
+
reporter.after_each_done
|
145
|
+
|
146
|
+
raise FailFast if !result.success? and failfast?
|
81
147
|
end
|
82
148
|
end
|
83
149
|
|
150
|
+
def call_test_case_target
|
151
|
+
reporter.before_invocation
|
152
|
+
@invocation = client.call(test_case)
|
153
|
+
reporter.invocation_done
|
154
|
+
rescue *PASSTHROUGH_EXCEPTIONS
|
155
|
+
raise
|
156
|
+
rescue => ex
|
157
|
+
@invocation_error = ex
|
158
|
+
reporter.invocation_done
|
159
|
+
end
|
160
|
+
|
161
|
+
def instrument_test_case
|
162
|
+
service = test_case.service
|
163
|
+
service.preconditions.each do |pre|
|
164
|
+
instrument_one(pre)
|
165
|
+
end
|
166
|
+
service.postconditions.each do |post|
|
167
|
+
instrument_one(post)
|
168
|
+
end if test_case.example?
|
169
|
+
service.errconditions.each do |err|
|
170
|
+
instrument_one(err)
|
171
|
+
end if test_case.counterexample?
|
172
|
+
config.listeners(:instrument).each do |i|
|
173
|
+
i.call(self)
|
174
|
+
end
|
175
|
+
test_case
|
176
|
+
end
|
177
|
+
|
178
|
+
def instrument_one(condition)
|
179
|
+
condition.bind(self).instrument
|
180
|
+
rescue ArgumentError
|
181
|
+
raise "#{condition.class} implements old PRE/POST contract"
|
182
|
+
end
|
183
|
+
|
184
|
+
def check_invocation
|
185
|
+
@result = Result.from(self)
|
186
|
+
end
|
187
|
+
|
188
|
+
def fork_tester(binding = {})
|
189
|
+
yield dup.tap{|t|
|
190
|
+
binding.each_pair do |k,v|
|
191
|
+
t.send(:"#{k}=", v)
|
192
|
+
end
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
attr_writer :test_case
|
199
|
+
|
84
200
|
end # class Tester
|
85
201
|
end # module Webspicy
|
202
|
+
require_relative 'tester/reporter'
|
86
203
|
require_relative 'tester/client'
|
87
204
|
require_relative 'tester/invocation'
|
205
|
+
require_relative 'tester/result'
|
206
|
+
require_relative 'tester/failure'
|
88
207
|
require_relative 'tester/assertions'
|
89
208
|
require_relative 'tester/asserter'
|
209
|
+
require_relative 'tester/file_checker'
|