riot 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG +16 -0
- data/VERSION +1 -1
- data/lib/riot.rb +1 -0
- data/lib/riot/context.rb +10 -27
- data/lib/riot/middleware.rb +40 -0
- data/riot.gemspec +5 -2
- data/test/core/chained_context_middleware_test.rb +49 -0
- data/test/core/context_middleware_test.rb +29 -16
- metadata +6 -3
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
*0.11.1*
|
2
|
+
|
3
|
+
* Middleware can now acts more like you would expect. Middleware now know the next neighbor in the chain and can do stuff to the context before and after the user-defined context is prepared. Removes support for the handle? method. Now we act more like a Rack app. [jaknowlden]
|
4
|
+
|
5
|
+
class MyMiddleware < Riot::ContextMiddleware
|
6
|
+
register
|
7
|
+
|
8
|
+
def call(context)
|
9
|
+
context.setup { "fooberries" }
|
10
|
+
|
11
|
+
middleware.call(context)
|
12
|
+
|
13
|
+
context.hookup { "furberries" } if context.option(:barns)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
1
17
|
*0.11.0*
|
2
18
|
|
3
19
|
* Added option to Context#setup which puts the specific setup block at the beginning of the setups to be called for a context. Also useful for middlewares. [jaknowlden]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.11.
|
1
|
+
0.11.1
|
data/lib/riot.rb
CHANGED
data/lib/riot/context.rb
CHANGED
@@ -1,31 +1,10 @@
|
|
1
1
|
module Riot
|
2
2
|
RootContext = Struct.new(:setups, :teardowns, :detailed_description)
|
3
3
|
|
4
|
-
class ContextMiddleware
|
5
|
-
# Registers the current middleware class with Riot so that it may be included in the set of middlewares
|
6
|
-
# Riot will poke before executing a Context.
|
7
|
-
#
|
8
|
-
# class MyContextMiddleware < Riot::ContextMiddleware
|
9
|
-
# register
|
10
|
-
# def handle?(context); ...; end
|
11
|
-
# def prepare(context); ...; end
|
12
|
-
# end
|
13
|
-
def self.register; Context.middlewares << self.new; end
|
14
|
-
|
15
|
-
# Called prior to a Context being executed. If this method returns true, +call+ will be called. This
|
16
|
-
# methods expects to receive an instance of the Context to be executed. Generally, you will inspect
|
17
|
-
# various aspects of the Context to determine if this middleware is meant to be used.
|
18
|
-
def handle?(context); false; end
|
19
|
-
|
20
|
-
# The meat of the middleware. Because you have access to the Context, you can add your own setups,
|
21
|
-
# hookups, etc. +call+ will be called before any tests are run, but after the Context is configured.
|
22
|
-
def call(context); end
|
23
|
-
end
|
24
|
-
|
25
4
|
module ContextClassOverrides
|
26
5
|
def assertion_class; Assertion; end
|
27
6
|
def situation_class; Situation; end
|
28
|
-
end
|
7
|
+
end # ContextClassOverrides
|
29
8
|
|
30
9
|
module ContextOptions
|
31
10
|
# Set options for the specific context. These options will generally be used for context middleware.
|
@@ -43,7 +22,7 @@ module Riot
|
|
43
22
|
def option(key) options[key]; end
|
44
23
|
private
|
45
24
|
def options; @options ||= {}; end
|
46
|
-
end
|
25
|
+
end # ContextOptions
|
47
26
|
|
48
27
|
# You make your assertions within a Context. The context stores setup and teardown blocks, and allows for
|
49
28
|
# nesting and refactoring into helpers. Extension developers may also configure ContextMiddleware objects
|
@@ -71,8 +50,7 @@ module Riot
|
|
71
50
|
@parent = parent || RootContext.new([],[], "")
|
72
51
|
@description = description
|
73
52
|
@contexts, @setups, @assertions, @teardowns = [], [], [], []
|
74
|
-
|
75
|
-
prepare_middleware
|
53
|
+
prepare_middleware(&definition)
|
76
54
|
end
|
77
55
|
|
78
56
|
# Create a new test context.
|
@@ -201,14 +179,18 @@ module Riot
|
|
201
179
|
runnables.each { |runnable| reporter.report(runnable.to_s, runnable.run(situation)) }
|
202
180
|
end
|
203
181
|
|
182
|
+
# Prints the full description from the context tree
|
204
183
|
def detailed_description
|
205
184
|
"#{parent.detailed_description} #{description}".strip
|
206
185
|
end
|
207
186
|
|
208
187
|
private
|
209
188
|
|
210
|
-
def prepare_middleware
|
211
|
-
|
189
|
+
def prepare_middleware(&context_definition)
|
190
|
+
last_middleware = AllImportantMiddleware.new(&context_definition)
|
191
|
+
Context.middlewares.inject(last_middleware) do |last_middleware, middleware|
|
192
|
+
middleware.new(last_middleware)
|
193
|
+
end.call(self)
|
212
194
|
end
|
213
195
|
|
214
196
|
def runnables
|
@@ -232,4 +214,5 @@ module Riot
|
|
232
214
|
(@assertions << assertion_class.new(description, &definition)).last
|
233
215
|
end
|
234
216
|
end # Context
|
217
|
+
|
235
218
|
end # Riot
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Riot
|
2
|
+
|
3
|
+
class ContextMiddleware
|
4
|
+
# Registers the current middleware class with Riot so that it may be included in the set of middlewares
|
5
|
+
# Riot will poke before executing a Context.
|
6
|
+
#
|
7
|
+
# class MyContextMiddleware < Riot::ContextMiddleware
|
8
|
+
# register
|
9
|
+
# def call(context)
|
10
|
+
# context.setup { ... }
|
11
|
+
# middleware.call(context) # this can go anywhere
|
12
|
+
# context.hookup { ... }
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
def self.register; Context.middlewares << self; end
|
16
|
+
|
17
|
+
attr_reader :middleware # Theoretically, the next middleware in the stack
|
18
|
+
|
19
|
+
def initialize(middleware)
|
20
|
+
@middleware = middleware
|
21
|
+
end
|
22
|
+
|
23
|
+
# The meat. Because you have access to the Context, you can add your own setups,
|
24
|
+
# hookups, etc. +call+ will be called before any tests are run, but after the Context is configured.
|
25
|
+
def call(context)
|
26
|
+
raise "You should implement call yourself"
|
27
|
+
end
|
28
|
+
end # ContextMiddleware
|
29
|
+
|
30
|
+
# Special middleware used by Context directly. It will always be the last in the chain and is the actual
|
31
|
+
# place where the user's runtime context is processed.
|
32
|
+
class AllImportantMiddleware < ContextMiddleware
|
33
|
+
def initialize(&context_definition)
|
34
|
+
@context_definition = context_definition
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(context) context.instance_eval(&@context_definition); end
|
38
|
+
end # AllImportantMiddleware
|
39
|
+
|
40
|
+
end # Riot
|
data/riot.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{riot}
|
8
|
-
s.version = "0.11.
|
8
|
+
s.version = "0.11.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin 'Gus' Knowlden"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-13}
|
13
13
|
s.description = %q{An extremely fast, expressive, and context-driven unit-testing framework. A replacement for all other testing frameworks. Protest the slow test.}
|
14
14
|
s.email = %q{gus@gusg.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
"lib/riot/assertion_macros/size.rb",
|
44
44
|
"lib/riot/context.rb",
|
45
45
|
"lib/riot/message.rb",
|
46
|
+
"lib/riot/middleware.rb",
|
46
47
|
"lib/riot/reporter.rb",
|
47
48
|
"lib/riot/rr.rb",
|
48
49
|
"lib/riot/runnable.rb",
|
@@ -70,6 +71,7 @@ Gem::Specification.new do |s|
|
|
70
71
|
"test/core/assertion_macros/same_elements_test.rb",
|
71
72
|
"test/core/assertion_macros/size_test.rb",
|
72
73
|
"test/core/assertion_test.rb",
|
74
|
+
"test/core/chained_context_middleware_test.rb",
|
73
75
|
"test/core/context_middleware_test.rb",
|
74
76
|
"test/core/context_test.rb",
|
75
77
|
"test/core/context_with_options_test.rb",
|
@@ -109,6 +111,7 @@ Gem::Specification.new do |s|
|
|
109
111
|
"test/core/assertion_macros/same_elements_test.rb",
|
110
112
|
"test/core/assertion_macros/size_test.rb",
|
111
113
|
"test/core/assertion_test.rb",
|
114
|
+
"test/core/chained_context_middleware_test.rb",
|
112
115
|
"test/core/context_middleware_test.rb",
|
113
116
|
"test/core/context_test.rb",
|
114
117
|
"test/core/context_with_options_test.rb",
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "Chaining ContextMiddleware" do
|
4
|
+
|
5
|
+
teardown { Riot::Context.middlewares.clear }
|
6
|
+
|
7
|
+
context("when middleware halts the call chain") do
|
8
|
+
hookup do
|
9
|
+
Class.new(Riot::ContextMiddleware) do
|
10
|
+
register
|
11
|
+
def initialize(middleware); end
|
12
|
+
def call(context) "whoops"; end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
setup do
|
17
|
+
situation = Riot::Situation.new
|
18
|
+
Riot::Context.new("Foo") do
|
19
|
+
setup { "foo" }
|
20
|
+
end.local_run(MockReporter.new, situation)
|
21
|
+
situation
|
22
|
+
end
|
23
|
+
|
24
|
+
asserts("situation topic") { topic.topic }.nil
|
25
|
+
end # when middleware halts the call chain
|
26
|
+
|
27
|
+
context("when middleware continues the call chain") do
|
28
|
+
hookup do
|
29
|
+
Class.new(Riot::ContextMiddleware) do
|
30
|
+
register
|
31
|
+
def call(context)
|
32
|
+
context.setup { ["foo"] }
|
33
|
+
middleware.call(context)
|
34
|
+
context.hookup { topic << "baz" }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
setup do
|
40
|
+
situation = Riot::Situation.new
|
41
|
+
Riot::Context.new("Foo") do
|
42
|
+
hookup { topic << "bar" }
|
43
|
+
end.local_run(MockReporter.new, situation)
|
44
|
+
situation
|
45
|
+
end
|
46
|
+
|
47
|
+
asserts("situation topic") { topic.topic }.equals(%w[foo bar baz])
|
48
|
+
end # when middleware halts the call chain
|
49
|
+
end # Chaining ContextMiddleware
|
@@ -1,24 +1,28 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
3
|
context "ContextMiddleware" do
|
4
|
-
setup { Riot::ContextMiddleware.new }
|
4
|
+
setup { Riot::ContextMiddleware.new("") }
|
5
5
|
teardown { Riot::Context.middlewares.clear }
|
6
6
|
|
7
|
-
asserts("
|
8
|
-
|
7
|
+
asserts("#call on the base class") do
|
8
|
+
topic.call("Foo")
|
9
|
+
end.raises(RuntimeError, "You should implement call yourself")
|
9
10
|
|
10
11
|
context "registration" do
|
11
12
|
setup { Class.new(Riot::ContextMiddleware) { register } }
|
12
13
|
asserts("registered middlewares list") { Riot::Context.middlewares }.size(1)
|
13
|
-
asserts("registered middleware") { Riot::Context.middlewares.first }.kind_of(
|
14
|
+
asserts("registered middleware") { Riot::Context.middlewares.first }.kind_of(Class)
|
14
15
|
end # registration
|
15
16
|
|
16
17
|
context "that is not meant to be used" do
|
17
18
|
hookup do
|
18
19
|
Class.new(Riot::ContextMiddleware) do
|
19
20
|
register
|
20
|
-
def handle?(context) context.description == "Bar"; end
|
21
|
-
def call(context)
|
21
|
+
# def handle?(context) context.description == "Bar"; end
|
22
|
+
def call(context)
|
23
|
+
context.setup { "fooberries" } if context.description == "Bar"
|
24
|
+
middleware.call(context)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
@@ -33,8 +37,11 @@ context "ContextMiddleware" do
|
|
33
37
|
hookup do
|
34
38
|
Class.new(Riot::ContextMiddleware) do
|
35
39
|
register
|
36
|
-
def handle?(context); true; end
|
37
|
-
def call(context)
|
40
|
+
# def handle?(context); true; end
|
41
|
+
def call(context)
|
42
|
+
context.setup { "fooberries" }
|
43
|
+
middleware.call(context)
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
@@ -49,16 +56,20 @@ context "ContextMiddleware" do
|
|
49
56
|
hookup do
|
50
57
|
Class.new(Riot::ContextMiddleware) do
|
51
58
|
register
|
52
|
-
def
|
53
|
-
|
59
|
+
def call(context)
|
60
|
+
context.setup { topic + "berries" }
|
61
|
+
middleware.call(context)
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
66
|
hookup do
|
58
67
|
Class.new(Riot::ContextMiddleware) do
|
59
68
|
register
|
60
|
-
def
|
61
|
-
|
69
|
+
def call(context)
|
70
|
+
context.setup { "foo" }
|
71
|
+
middleware.call(context)
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
@@ -69,12 +80,14 @@ context "ContextMiddleware" do
|
|
69
80
|
asserts("tests passed") { topic.passes }.equals(1)
|
70
81
|
end # that are not exclusive
|
71
82
|
|
72
|
-
context "has access to options" do
|
83
|
+
context "has access to options after context setup" do
|
73
84
|
hookup do
|
74
85
|
Class.new(Riot::ContextMiddleware) do
|
75
86
|
register
|
76
|
-
def
|
77
|
-
|
87
|
+
def call(context)
|
88
|
+
middleware.call(context)
|
89
|
+
context.setup { "fooberries" } if context.option(:foo) == "bar"
|
90
|
+
end
|
78
91
|
end
|
79
92
|
end
|
80
93
|
|
@@ -86,5 +99,5 @@ context "ContextMiddleware" do
|
|
86
99
|
end
|
87
100
|
|
88
101
|
asserts("tests passed") { topic.passes }.equals(1)
|
89
|
-
end # has access to options
|
102
|
+
end # has access to options after context setup
|
90
103
|
end # ContextMiddleware
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 11
|
8
|
-
-
|
9
|
-
version: 0.11.
|
8
|
+
- 1
|
9
|
+
version: 0.11.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Justin 'Gus' Knowlden
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-13 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/riot/assertion_macros/size.rb
|
78
78
|
- lib/riot/context.rb
|
79
79
|
- lib/riot/message.rb
|
80
|
+
- lib/riot/middleware.rb
|
80
81
|
- lib/riot/reporter.rb
|
81
82
|
- lib/riot/rr.rb
|
82
83
|
- lib/riot/runnable.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- test/core/assertion_macros/same_elements_test.rb
|
105
106
|
- test/core/assertion_macros/size_test.rb
|
106
107
|
- test/core/assertion_test.rb
|
108
|
+
- test/core/chained_context_middleware_test.rb
|
107
109
|
- test/core/context_middleware_test.rb
|
108
110
|
- test/core/context_test.rb
|
109
111
|
- test/core/context_with_options_test.rb
|
@@ -167,6 +169,7 @@ test_files:
|
|
167
169
|
- test/core/assertion_macros/same_elements_test.rb
|
168
170
|
- test/core/assertion_macros/size_test.rb
|
169
171
|
- test/core/assertion_test.rb
|
172
|
+
- test/core/chained_context_middleware_test.rb
|
170
173
|
- test/core/context_middleware_test.rb
|
171
174
|
- test/core/context_test.rb
|
172
175
|
- test/core/context_with_options_test.rb
|