riot 0.12.4 → 0.12.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/CHANGELOG +18 -0
- data/README.markdown +30 -12
- data/lib/riot/assertion_macro.rb +0 -1
- data/lib/riot/assertion_macros/any.rb +4 -0
- data/lib/riot/assertion_macros/assigns.rb +3 -1
- data/lib/riot/assertion_macros/exists.rb +4 -0
- data/lib/riot/context.rb +4 -4
- data/lib/riot/context_helpers.rb +3 -3
- data/lib/riot/context_options.rb +3 -3
- data/lib/riot/message.rb +8 -6
- data/lib/riot/situation.rb +1 -1
- data/lib/riot/version.rb +1 -1
- data/test/core/context/context_with_options_test.rb +3 -0
- data/test/core/reports/dot_matrix_reporter_test.rb +4 -4
- data/test/teststrap.rb +1 -1
- metadata +2 -19
- data/lib/riot/assertion_macros/not_borat.rb +0 -32
- data/test/core/assertion_macros/not_borat_test.rb +0 -21
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
== 0.12.5
|
2
|
+
|
3
|
+
==== Remove doc for some deprecated macros: not, exists, any [charlietanskley]
|
4
|
+
|
5
|
+
==== Deprecate two more macros [charlietanskley]
|
6
|
+
|
7
|
+
==== make riot run -w clean. None of those pesky warnings [achiu]
|
8
|
+
|
9
|
+
==== Use #inspect for printing arguments in error results [Mon-Ouie]
|
10
|
+
|
11
|
+
==== Move BlankSlate into Riot namespace [Mon-Ouie]
|
12
|
+
|
13
|
+
==== Setting options in a sub-context don't leak back into the parent context [skade]
|
14
|
+
|
15
|
+
==== Remove deprecated `not!` macro [charlietanksley]
|
16
|
+
|
17
|
+
==== Fix all warnings so riot runs `-w` clean
|
18
|
+
|
1
19
|
== 0.12.4
|
2
20
|
|
3
21
|
==== Adding Riot.plain! option for not printing output in color [c00lryguy,
|
data/README.markdown
CHANGED
@@ -12,16 +12,19 @@ In contrast to other popular Ruby testing frameworks such as Test::Unit, [Should
|
|
12
12
|
|
13
13
|
In Riot, tests reside in `contexts`. Within these, a `topic` object is defined through a `setup` block. The actual assertions are then made with an `asserts` or `denies` block.
|
14
14
|
|
15
|
+
```ruby
|
15
16
|
context "An empty Array" do
|
16
17
|
setup { Array.new }
|
17
18
|
asserts("it is empty") { topic.empty? }
|
18
19
|
denies("it has any elements") { topic.any? }
|
19
20
|
end # An Array
|
21
|
+
```
|
20
22
|
|
21
23
|
As you can see, the setup block doesn't use any instance variables to save the object under test — rather, the return value of the block is used as the `topic`. This object can then be accessed in the assertions using the `topic` attribute. Furthermore, at their very basic level, assertions need only return a boolean. When using `asserts`, `true` indicates a pass while `false` indicates a fail; subsequently, when using `denies`, `true` indicates a failure whereas `false` indicates success.
|
22
24
|
|
23
25
|
Of course, you can nest contexts as well; the `setup` blocks are executed outside-in; as in, the parents' setups are run before the current context allowing for a setup hierarchy. `teardown` blocks are run inside out; the current context's teardowns are run before any of its parents'. This is what you would expect from other frameworks as well.
|
24
26
|
|
27
|
+
```ruby
|
25
28
|
context "An Array" do
|
26
29
|
setup { Array.new }
|
27
30
|
|
@@ -33,6 +36,7 @@ Of course, you can nest contexts as well; the `setup` blocks are executed outsid
|
|
33
36
|
asserts("returns the element on #first") { topic.first == "foo" }
|
34
37
|
end
|
35
38
|
end # An Array
|
39
|
+
```
|
36
40
|
|
37
41
|
By the way, you can put any kind of ruby object in your context description. Riot will call `to_s` on the actual value before it is used in a reporting context. This fact will become [useful later](http://thumblemonks.github.com/riot/hacking.html#context-middleware) ;)
|
38
42
|
|
@@ -44,37 +48,45 @@ We can do this with assertion macros. You can think of these as special assertio
|
|
44
48
|
|
45
49
|
Let's take this little for instance:
|
46
50
|
|
51
|
+
```ruby
|
47
52
|
context "Yummy things" do
|
48
53
|
setup { ["cookies", "donuts"] }
|
49
54
|
|
50
55
|
asserts("#first") { topic.first }.equals("cookies")
|
51
56
|
end # Yummy things
|
57
|
+
```
|
52
58
|
|
53
59
|
First, how's that for a readable test? Second, you should notice that the assertion block will return the `first` item from the `topic` (which is assumed to be `Enumerable` in this case); if it isn't `Enumerable`, then you have other problems. Since the first element in the array is "cookies", the assertion will pass. Yay!
|
54
60
|
|
55
61
|
But wait, there's more. Riot is about helping you write faster and more readable tests. Notice any duplication in the example above (besides the value "cookies")? I do. How about that `first` notation in the assertion name and reference in the assertion block. Riot provides a shortcut which allows you to reference methods on the topic through the assertion name. Here's another way to write the same test:
|
56
62
|
|
63
|
+
```ruby
|
57
64
|
context "Yummy things" do
|
58
65
|
setup { ["cookies", "donuts"] }
|
59
66
|
|
60
67
|
asserts(:first).equals("cookies")
|
61
68
|
end # Yummy things
|
69
|
+
```
|
62
70
|
|
63
71
|
Now that's real yummy. Want some more? Perhaps you just want to test the topic itself — not a method or attribute of it. You could do this:
|
64
72
|
|
73
|
+
```ruby
|
65
74
|
context "Yummy things" do
|
66
75
|
setup { ["cookies", "donuts"] }
|
67
76
|
|
68
77
|
asserts("topic") { topic }.size(2)
|
69
78
|
end # Yummy things
|
79
|
+
```
|
70
80
|
|
71
81
|
But, as you can probably already guess, that's gross and redundant. To solve this, Riot provides the `asserts_topic` shortcut which is a helper that pretty much just does `asserts("topic") { topic }` for you.
|
72
82
|
|
83
|
+
```ruby
|
73
84
|
context "Yummy things" do
|
74
85
|
setup { ["cookies", "donuts"] }
|
75
86
|
|
76
87
|
asserts_topic.size(2)
|
77
88
|
end # Yummy things
|
89
|
+
```
|
78
90
|
|
79
91
|
Yep, more readable.
|
80
92
|
|
@@ -82,6 +94,7 @@ Yep, more readable.
|
|
82
94
|
|
83
95
|
Way back in the first code example we saw a reference to `denies`; this is what is called the negative assertion. You could probably also call it a counter assertion, but I don't. You can use `denies` with any assertion macro that you can use `asserts` with; it's just that `denies` expects the assertion to fail for the test to pass. For instance:
|
84
96
|
|
97
|
+
```ruby
|
85
98
|
context "My wallet" do
|
86
99
|
setup do
|
87
100
|
Wallet.new(1000) # That's 1000 cents, or $10USD yo
|
@@ -90,6 +103,7 @@ Way back in the first code example we saw a reference to `denies`; this is what
|
|
90
103
|
asserts(:enough_for_lunch?)
|
91
104
|
denies(:enough_for_lunch?)
|
92
105
|
end # My wallet
|
106
|
+
```
|
93
107
|
|
94
108
|
One of those will pass and the other will fail. If $10 is not enough for lunch the `denies` statement will pass; and then you should move to Chicago where it is enough (if only barely).
|
95
109
|
|
@@ -126,10 +140,6 @@ The advantage of using the block is that its innards are evaluated against the s
|
|
126
140
|
* `asserts.nil`
|
127
141
|
* `denies.nil`
|
128
142
|
|
129
|
-
* **Exists**: pretty much the opposite of the `nil` assertion macro. Expects no arguments.
|
130
|
-
* `asserts.exists`
|
131
|
-
* `denies.exists`
|
132
|
-
|
133
143
|
* **Matches**: compares the actual value to a provided regular expression
|
134
144
|
* `asserts.matches(%r{Regex})`
|
135
145
|
* `denies.matches(%r{Regex})`
|
@@ -180,10 +190,6 @@ The advantage of using the block is that its innards are evaluated against the s
|
|
180
190
|
* `asserts.size { Numeric }`
|
181
191
|
* `denies.size { Numeric }`
|
182
192
|
|
183
|
-
* **Any**: checks the result of calling `any?` on the actual value. Expects no arguments.
|
184
|
-
* `asserts.any`
|
185
|
-
* `denies.any`
|
186
|
-
|
187
193
|
* **Empty**: checks the result of calling `empty?` on the actual value. Expects no arguments.
|
188
194
|
* `asserts.empty`
|
189
195
|
* `denies.empty`
|
@@ -194,10 +200,6 @@ The advantage of using the block is that its innards are evaluated against the s
|
|
194
200
|
* `asserts.same_elements { Array }`
|
195
201
|
* `denies.same_elements { Array }`
|
196
202
|
|
197
|
-
* **Not!**: Expects no arguments and simply checks that the actual value is non-truthy. This is different than `exists` which only checks that the actual value is not nil. This assertion was added at the inception of Riot to deal with the fact that Riot didn't yet have negative assertions. I am hereby declaring this macro `@deprecated`. Please stop using it (note to self) because it will be removed someday.
|
198
|
-
* `asserts("i'm confused") { false }.not!`
|
199
|
-
* `denies("i'm not confused?") { true }.not!`
|
200
|
-
|
201
203
|
### Setups, Hookups, and Helpers {#setups-hookups}
|
202
204
|
|
203
205
|
We're not even close to done yet; there's a lot more cool stuff for you to know about. You know about `setup` already; but you may not know that you can call `setup` multiple times within a Context. Well, you can. They run in the order you write them (top-down) and the result of a prior `setup` will be the `topic` for the next setup. In this way you **could** chain together some partitioned setup criteria without ever explicitly setting a variable (instance or local).
|
@@ -213,6 +215,7 @@ This notion about a prior `setup` being the `topic` for a latter `setup` is true
|
|
213
215
|
|
214
216
|
More than likely, however, you'll want to modify something about the topic without changing what the topic for the context is. To do this, Riot provides the `hookup` block, which is just like a `setup` block except that `hookup` will always return the `topic` that was provided to it. It's kind of like calling `Object#tap`. Here's a for-instance:
|
215
217
|
|
218
|
+
```ruby
|
216
219
|
context "A Person" do
|
217
220
|
setup { Person.new(:name => "Master Blasterr") }
|
218
221
|
|
@@ -223,6 +226,7 @@ More than likely, however, you'll want to modify something about the topic witho
|
|
223
226
|
asserts(:valid?) # Yay!
|
224
227
|
end # with valid email
|
225
228
|
end # A complex thing
|
229
|
+
```
|
226
230
|
|
227
231
|
If the point didn't smack you in the face there, think about using `setup` instead of `hookup` in the sub-context. Had you written that as a `setup` block, you'd have to return `topic` after setting the email address, or else the new topic would be the actual email address; and you probably don't want to actually be calling `"master@blast.err".valid?` in the assertion.
|
228
232
|
|
@@ -232,6 +236,7 @@ You can also call `hookup` as many times as you like; the great part is that the
|
|
232
236
|
|
233
237
|
You remember how you used to — or currently do — create instance variables to hold some data that you're going to use in your tests? Well, Riot allows you to still do that yucky stuff, but would rather you use a helper to encapsulate it. For instance, you could do this:
|
234
238
|
|
239
|
+
```ruby
|
235
240
|
context "A greedy monkey" do
|
236
241
|
setup do
|
237
242
|
@a_ripe_banana = Banana.new(:ripe => true)
|
@@ -242,9 +247,11 @@ You remember how you used to — or currently do — create instance var
|
|
242
247
|
|
243
248
|
asserts(:bananas).size(1)
|
244
249
|
end # A greedy monkey
|
250
|
+
```
|
245
251
|
|
246
252
|
Or, you could do this
|
247
253
|
|
254
|
+
```ruby
|
248
255
|
context "A greedy monkey" do
|
249
256
|
helper(:a_ripe_banana) { Banana.new(:ripe => true) }
|
250
257
|
setup { Monkey.new }
|
@@ -253,6 +260,7 @@ Or, you could do this
|
|
253
260
|
|
254
261
|
asserts(:bananas).size(1)
|
255
262
|
end # A greedy monkey
|
263
|
+
```
|
256
264
|
|
257
265
|
"So! What's the difference?", you ask. Nothing really. It's all aesthetic; but, it's a better aesthetic for a couple of reasons. Let me tell you why:
|
258
266
|
|
@@ -263,6 +271,7 @@ Or, you could do this
|
|
263
271
|
|
264
272
|
What's that about (4)? Yes, helpers are really just over-glorified methods, which means you can pass arguments to them. Which means you can build factories with them. Which means those factories can go away when the context is no longer used and they're no longer cluttering up your object space. You want another for instance, eh?
|
265
273
|
|
274
|
+
```ruby
|
266
275
|
context "A greedy monkey" do
|
267
276
|
helper(:make_a_banana) do |color|
|
268
277
|
Banana.new(:color => color)
|
@@ -279,6 +288,7 @@ What's that about (4)? Yes, helpers are really just over-glorified methods, whic
|
|
279
288
|
asserts("green bananas") { topic.bananas.green }.size(1)
|
280
289
|
asserts("blue bananas") { topic.bananas.blue }.size(1)
|
281
290
|
end # A greedy monkey
|
291
|
+
```
|
282
292
|
|
283
293
|
Or you could `make_many_bananas` or whatever. There are also lots of clever ways to get helpers included into a context which you will hopefully see when you read up on Context Middleware and look through the Recipes. Riot Rails makes liberal use of helpers when [setting up a context](http://github.com/thumblemonks/riot-rails/master/lib/riot/action_controller/context_middleware.rb) to test controllers.
|
284
294
|
|
@@ -295,12 +305,15 @@ Running your Riot tests is pretty simple. You can put your test files wherever y
|
|
295
305
|
|
296
306
|
I like the latter and use it often. It means the test directory is loaded into the load path, which means I don't have to be explicit about where to find my `teststrap.rb` file (which you might have named `test_helper.rb` in other projects even though it's a silly name). In your teststrap file you'll put all your common setup; maybe even including your Riot hacks. An out-of-the-box teststrap might look like this:
|
297
307
|
|
308
|
+
```ruby
|
298
309
|
require 'rubygems'
|
299
310
|
require '<my-library>'
|
300
311
|
require 'riot'
|
312
|
+
```
|
301
313
|
|
302
314
|
Of course, you probably want to use rake to run your tests. Here's a basic Rakefile that will find our tests in the test directory or its subdirectories if the filename ends in `_test.rb`:
|
303
315
|
|
316
|
+
```ruby
|
304
317
|
require 'rubygems'
|
305
318
|
|
306
319
|
require 'rake'
|
@@ -316,6 +329,7 @@ Of course, you probably want to use rake to run your tests. Here's a basic Rakef
|
|
316
329
|
end
|
317
330
|
|
318
331
|
task :default => :test
|
332
|
+
```
|
319
333
|
|
320
334
|
And then on the command line you simply run:
|
321
335
|
|
@@ -341,13 +355,16 @@ However, there are a number of things you expect from a test framework when mock
|
|
341
355
|
|
342
356
|
But enough of this hemming and hawing. What's it look like?! In your `teststrap.rb` you need to require in `riot/rr`:
|
343
357
|
|
358
|
+
```ruby
|
344
359
|
# I'm teststrap.rb
|
345
360
|
|
346
361
|
require 'rubygems'
|
347
362
|
require 'riot/rr'
|
363
|
+
```
|
348
364
|
|
349
365
|
Then, in your tests, you use standard RR syntax for all of your mocking needs:
|
350
366
|
|
367
|
+
```ruby
|
351
368
|
require 'teststrap.rb'
|
352
369
|
|
353
370
|
context "A nice Person" do
|
@@ -361,6 +378,7 @@ Then, in your tests, you use standard RR syntax for all of your mocking needs:
|
|
361
378
|
end.equals("Nice haircut")
|
362
379
|
|
363
380
|
end # A nice Person
|
381
|
+
```
|
364
382
|
|
365
383
|
So, if `#say_something_nice` never calls `#make_network_request`, that assertion will fail for that reason first. If it does call `#make_network_request`, but for some reason "Nice haircut" is not returned, the tests will fail for that reason instead. It's like catching two birds with one test.
|
366
384
|
|
data/lib/riot/assertion_macro.rb
CHANGED
@@ -134,7 +134,6 @@ require 'riot/assertion_macros/includes'
|
|
134
134
|
require 'riot/assertion_macros/kind_of'
|
135
135
|
require 'riot/assertion_macros/matches'
|
136
136
|
require 'riot/assertion_macros/nil'
|
137
|
-
require 'riot/assertion_macros/not_borat'
|
138
137
|
require 'riot/assertion_macros/raises'
|
139
138
|
require 'riot/assertion_macros/raises_kind_of'
|
140
139
|
require 'riot/assertion_macros/respond_to'
|
@@ -8,16 +8,20 @@ module Riot
|
|
8
8
|
#
|
9
9
|
# denies("an empty array") { [] }.any
|
10
10
|
# denies("an empty hash") { {} }.any
|
11
|
+
#
|
12
|
+
# @deprecated Please use +asserts.empty+ or +denies.empty+ instead.
|
11
13
|
class AnyMacro < AssertionMacro
|
12
14
|
register :any
|
13
15
|
|
14
16
|
# (see Riot::AssertionMacro#evaluate)
|
15
17
|
def evaluate(actual)
|
18
|
+
warn "any is deprecated; please use asserts.empty or denies.empty instead"
|
16
19
|
any?(actual) ? pass("has items") : fail(expected_message(actual).to_have_items)
|
17
20
|
end
|
18
21
|
|
19
22
|
# (see Riot::AssertionMacro#devaluate)
|
20
23
|
def devaluate(actual)
|
24
|
+
warn "any is deprecated; please use asserts.empty or denies.empty instead"
|
21
25
|
any?(actual) ? fail(expected_message(actual).not_to_have_items) : pass("has items")
|
22
26
|
end
|
23
27
|
private
|
@@ -61,7 +61,9 @@ module Riot
|
|
61
61
|
|
62
62
|
def prepare(actual, *expectings, &block)
|
63
63
|
variable, expected_value = expectings
|
64
|
-
|
64
|
+
var_name = "@#{variable}"
|
65
|
+
var_value = actual.instance_variable_defined?(var_name) ? actual.instance_variable_get(var_name) : nil
|
66
|
+
yield(variable, expected_value, var_value)
|
65
67
|
end
|
66
68
|
end # AssignsMacro
|
67
69
|
end # Riot
|
@@ -13,16 +13,20 @@ module Riot
|
|
13
13
|
# asserts("test") { nil }.nil # same thing
|
14
14
|
#
|
15
15
|
# denies("test") { "foo" }.exists # would fail
|
16
|
+
#
|
17
|
+
# @deprecated Please use +denies.nil+ instead of +asserts.exists+.
|
16
18
|
class ExistsMacro < AssertionMacro
|
17
19
|
register :exists
|
18
20
|
|
19
21
|
# (see Riot::AssertionMacro#evaluate)
|
20
22
|
def evaluate(actual)
|
23
|
+
warn "exists is deprecated; please use denies.nil instead of asserts.exists"
|
21
24
|
actual.nil? ? fail("expected a non-nil value") : pass("does exist")
|
22
25
|
end
|
23
26
|
|
24
27
|
# (see Riot::AssertionMacro#devaluate)
|
25
28
|
def devaluate(actual)
|
29
|
+
warn "exists is deprecated; please use denies.nil instead of asserts.exists"
|
26
30
|
actual.nil? ? pass("does exist") : fail("expected a nil value")
|
27
31
|
end
|
28
32
|
end
|
data/lib/riot/context.rb
CHANGED
@@ -2,7 +2,7 @@ require 'riot/context_options'
|
|
2
2
|
require 'riot/context_helpers'
|
3
3
|
|
4
4
|
module Riot
|
5
|
-
RootContext = Struct.new(:setups, :teardowns, :detailed_description, :
|
5
|
+
RootContext = Struct.new(:setups, :teardowns, :detailed_description, :option_set)
|
6
6
|
|
7
7
|
# Defines the classes {Riot::Context} will use when creating new assertions and situations.
|
8
8
|
module ContextClassOverrides
|
@@ -51,7 +51,7 @@ module Riot
|
|
51
51
|
@parent = parent || RootContext.new([],[], "", {})
|
52
52
|
@description = description
|
53
53
|
@contexts, @setups, @assertions, @teardowns = [], [], [], []
|
54
|
-
@options = @parent.
|
54
|
+
@options = @parent.option_set.dup
|
55
55
|
prepare_middleware(&definition)
|
56
56
|
end
|
57
57
|
|
@@ -115,8 +115,8 @@ module Riot
|
|
115
115
|
# choose. {Riot::AllImportantMiddleware} will always be the last in the chain.
|
116
116
|
def prepare_middleware(&context_definition)
|
117
117
|
last_middleware = AllImportantMiddleware.new(&context_definition)
|
118
|
-
Context.middlewares.inject(last_middleware) do |
|
119
|
-
middleware.new(
|
118
|
+
Context.middlewares.inject(last_middleware) do |previous_middleware, middleware|
|
119
|
+
middleware.new(previous_middleware)
|
120
120
|
end.call(self)
|
121
121
|
end
|
122
122
|
|
data/lib/riot/context_helpers.rb
CHANGED
@@ -81,7 +81,7 @@ module Riot
|
|
81
81
|
# asserts(:size).equals(2)
|
82
82
|
#
|
83
83
|
# Or with arguments:
|
84
|
-
#
|
84
|
+
#
|
85
85
|
# asserts(:foo,1,2).equals(3)
|
86
86
|
#
|
87
87
|
# Passing a Symbol to +asserts+ enables this behaviour. For more information on
|
@@ -178,12 +178,12 @@ module Riot
|
|
178
178
|
denies(what) { topic }
|
179
179
|
end
|
180
180
|
private
|
181
|
-
|
181
|
+
|
182
182
|
def new_assertion(scope, *args, &definition)
|
183
183
|
options = args.extract_options!
|
184
184
|
definition ||= proc { topic.send(*args) }
|
185
185
|
description = "#{scope} #{args.first}"
|
186
|
-
description << " with arguments(s): #{args.slice(1, args.length)}" if args.size > 1
|
186
|
+
description << " with arguments(s): #{args.slice(1, args.length).inspect}" if args.size > 1
|
187
187
|
(@assertions << assertion_class.new(description, options[:negative], &definition)).last
|
188
188
|
end
|
189
189
|
|
data/lib/riot/context_options.rb
CHANGED
@@ -11,7 +11,7 @@ module Riot
|
|
11
11
|
# @param [Object] key the key used to look up the option value later
|
12
12
|
# @param [Object] value the option value to store
|
13
13
|
def set(key, value)
|
14
|
-
|
14
|
+
option_set[key] = value
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns the value of a set option. The key must match exactly, symbols and strings are not
|
@@ -20,13 +20,13 @@ module Riot
|
|
20
20
|
# @param [Object] key the key used to look up the option value
|
21
21
|
# @return [Object]
|
22
22
|
def option(key)
|
23
|
-
|
23
|
+
option_set[key]
|
24
24
|
end
|
25
25
|
|
26
26
|
# Returns the hash of defined options.
|
27
27
|
#
|
28
28
|
# @return [Hash]
|
29
|
-
def
|
29
|
+
def option_set
|
30
30
|
@options ||= {}
|
31
31
|
end
|
32
32
|
|
data/lib/riot/message.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
class BlankSlate
|
2
|
-
instance_methods.each { |meth| undef_method(meth) unless meth.to_s =~ /^(__|object_id)/ }
|
3
|
-
end
|
4
|
-
|
5
1
|
module Riot
|
2
|
+
class BlankSlate
|
3
|
+
instance_methods.each do |meth|
|
4
|
+
undef_method(meth) unless meth.to_s =~ /^(__|object_id)/
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
6
8
|
# A Message is similar in nature (but not implementation) to a string buffer; you put some strings in and
|
7
9
|
# calling {#to_s} will generate a single new string. What's special abnout Message is how you get strings
|
8
10
|
# into it. By convention, any method called on a Message that isn't defined will have its name turned into
|
@@ -12,7 +14,7 @@ module Riot
|
|
12
14
|
# message = Riot::Message.new
|
13
15
|
# message.hello_world.to_s
|
14
16
|
# => "hello world"
|
15
|
-
#
|
17
|
+
#
|
16
18
|
# message.whats_the_news.to_s
|
17
19
|
# => "hello world whats the news"
|
18
20
|
#
|
@@ -101,4 +103,4 @@ module Riot
|
|
101
103
|
self
|
102
104
|
end
|
103
105
|
end # Message
|
104
|
-
end # Riot
|
106
|
+
end # Riot
|
data/lib/riot/situation.rb
CHANGED
data/lib/riot/version.rb
CHANGED
@@ -29,5 +29,8 @@ context "Context with options" do
|
|
29
29
|
|
30
30
|
asserts("option :goo") { topic.option(:goo) }.equals("car")
|
31
31
|
asserts("option \"car\"") { topic.option("car") }.equals(3)
|
32
|
+
asserts("option :goo on parent") do
|
33
|
+
topic.parent.option(:goo)
|
34
|
+
end.equals(nil)
|
32
35
|
end # and with a nested context
|
33
36
|
end # Context with options
|
@@ -16,7 +16,7 @@ context "DotMatrixReporter" do
|
|
16
16
|
end
|
17
17
|
asserts_topic('puts a dot').matches('.')
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
context 'with a failing test' do
|
21
21
|
setup do
|
22
22
|
Riot::Context.new('whatever') do
|
@@ -25,12 +25,12 @@ context "DotMatrixReporter" do
|
|
25
25
|
topic.results(100)
|
26
26
|
@out.string
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
asserts_topic('puts an F').matches('F')
|
30
30
|
asserts_topic("puts the full context + assertion name").matches('whatever asserts nope!')
|
31
31
|
asserts_topic("puts the failure reason").matches(/Expected .* but got false instead/)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
context 'with an error test' do
|
35
35
|
setup do
|
36
36
|
Riot::Context.new('whatever') do
|
@@ -39,7 +39,7 @@ context "DotMatrixReporter" do
|
|
39
39
|
topic.results(100)
|
40
40
|
@out.string
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
asserts_topic('puts an E').matches('E')
|
44
44
|
asserts_topic('puts the full context + assertion name').matches('whatever asserts bang')
|
45
45
|
asserts_topic('puts the exception message').matches('BOOM')
|
data/test/teststrap.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 39
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 12
|
9
|
-
- 4
|
10
|
-
version: 0.12.4
|
5
|
+
version: 0.12.5
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Justin 'Gus' Knowlden
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-09-13 00:00:00 -05:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,9 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
24
|
version: "0"
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -61,7 +53,6 @@ files:
|
|
61
53
|
- lib/riot/assertion_macros/kind_of.rb
|
62
54
|
- lib/riot/assertion_macros/matches.rb
|
63
55
|
- lib/riot/assertion_macros/nil.rb
|
64
|
-
- lib/riot/assertion_macros/not_borat.rb
|
65
56
|
- lib/riot/assertion_macros/raises.rb
|
66
57
|
- lib/riot/assertion_macros/raises_kind_of.rb
|
67
58
|
- lib/riot/assertion_macros/respond_to.rb
|
@@ -97,7 +88,6 @@ files:
|
|
97
88
|
- test/core/assertion_macros/kind_of_test.rb
|
98
89
|
- test/core/assertion_macros/matches_test.rb
|
99
90
|
- test/core/assertion_macros/nil_test.rb
|
100
|
-
- test/core/assertion_macros/not_borat_test.rb
|
101
91
|
- test/core/assertion_macros/raises_kind_of_test.rb
|
102
92
|
- test/core/assertion_macros/raises_test.rb
|
103
93
|
- test/core/assertion_macros/respond_to_test.rb
|
@@ -143,18 +133,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
133
|
requirements:
|
144
134
|
- - ">="
|
145
135
|
- !ruby/object:Gem::Version
|
146
|
-
hash: 3
|
147
|
-
segments:
|
148
|
-
- 0
|
149
136
|
version: "0"
|
150
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
138
|
none: false
|
152
139
|
requirements:
|
153
140
|
- - ">="
|
154
141
|
- !ruby/object:Gem::Version
|
155
|
-
hash: 3
|
156
|
-
segments:
|
157
|
-
- 0
|
158
142
|
version: "0"
|
159
143
|
requirements: []
|
160
144
|
|
@@ -178,7 +162,6 @@ test_files:
|
|
178
162
|
- test/core/assertion_macros/kind_of_test.rb
|
179
163
|
- test/core/assertion_macros/matches_test.rb
|
180
164
|
- test/core/assertion_macros/nil_test.rb
|
181
|
-
- test/core/assertion_macros/not_borat_test.rb
|
182
165
|
- test/core/assertion_macros/raises_kind_of_test.rb
|
183
166
|
- test/core/assertion_macros/raises_test.rb
|
184
167
|
- test/core/assertion_macros/respond_to_test.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Riot
|
2
|
-
# Asserts the result of the test is a non-truthy value. Read the following assertions in the way Borat
|
3
|
-
# learned about humor:
|
4
|
-
#
|
5
|
-
# asserts("you are funny") { false }.not!
|
6
|
-
# should("be funny") { nil }.not!
|
7
|
-
#
|
8
|
-
# Thusly, Borat would say "You are funny ... not!" The above two assertions would pass because the values
|
9
|
-
# are non-truthy.
|
10
|
-
#
|
11
|
-
# You can also apply not to the negative assertion (denies), but I'm not sure how much sense it would make.
|
12
|
-
# It would be kind of like a double negative:
|
13
|
-
#
|
14
|
-
# denies("you are funny") { true }.not!
|
15
|
-
#
|
16
|
-
# @deprecated Please use the denies assertion instead
|
17
|
-
class NotMacro < AssertionMacro
|
18
|
-
register :not!
|
19
|
-
|
20
|
-
# (see Riot::AssertionMacro#evaluate)
|
21
|
-
def evaluate(actual)
|
22
|
-
warn "not! is deprecated; please use the denies assertion instead"
|
23
|
-
actual ? fail("expected to exist ... not!") : pass("does exist ... not!")
|
24
|
-
end
|
25
|
-
|
26
|
-
# (see Riot::AssertionMacro#devaluate)
|
27
|
-
def devaluate(actual)
|
28
|
-
warn "not! is deprecated; please use the denies assertion instead"
|
29
|
-
actual ? pass("does not exist ... not!") : fail("expected to not exist ... not!")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "A not! assertion macro" do
|
4
|
-
helper(:assert_not!) { |o| Riot::Assertion.new("foo") { o }.not! }
|
5
|
-
|
6
|
-
assertion_test_passes("when value is false", "does exist ... not!") { assert_not!(false) }
|
7
|
-
assertion_test_passes("when value is nil", "does exist ... not!") { assert_not!(nil) }
|
8
|
-
assertion_test_fails("when value is not nil or false", "expected to exist ... not!") do
|
9
|
-
assert_not!("funny")
|
10
|
-
end
|
11
|
-
end # A not! assertion macro
|
12
|
-
|
13
|
-
context "A negative not! assertion macro" do
|
14
|
-
helper(:assert_not_not!) { |o| Riot::Assertion.new("foo", true) { o }.not! }
|
15
|
-
|
16
|
-
assertion_test_fails("when value is false", "expected to not exist ... not!") { assert_not_not!(false) }
|
17
|
-
assertion_test_fails("when value is nil", "expected to not exist ... not!") { assert_not_not!(nil) }
|
18
|
-
assertion_test_passes("when value is not nil or false", "does not exist ... not!") do
|
19
|
-
assert_not_not!('borat')
|
20
|
-
end
|
21
|
-
end # A negative not! assertion macro
|