riot 0.12.2 → 0.12.3

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/CHANGELOG CHANGED
@@ -1,3 +1,30 @@
1
+ == 0.12.3
2
+
3
+ ==== Going nuts with context helpers: should_not, asserts/denies_topic arguments [achiu]
4
+
5
+ This works now: `should_not("do something")` as an alias for `denies`
6
+
7
+ You can now pass arguments to `asserts`, `denies`, `should`, and `should_not`.
8
+
9
+ context "Playing with hashes" do
10
+ setup do
11
+ { "foo" => "bar" }
12
+ end
13
+
14
+ asserts(:[], "foo").equals("bar")
15
+ should(:[], "foo").equals("bar")
16
+ denies(:[], "foo").equals("goo")
17
+ should_not(:[], "foo").equals("goo")
18
+ end # Playing with hashes
19
+
20
+ ==== Exit gracefully if a child process exited with failing status [timgaleckas]
21
+
22
+ No tests will run in this situation.
23
+
24
+ ==== No status displayed if no tests run [timgaleckas]
25
+
26
+ ==== Adding a `denies_topic` macro to Context [Mon-Ouie]
27
+
1
28
  == 0.12.2
2
29
 
3
30
  ==== RDoc'ed the hell out of everything [jaknowlden]
@@ -37,7 +37,7 @@ module Riot
37
37
  the_reporter = reporter.new
38
38
  the_reporter.summarize do
39
39
  root_contexts.each { |ctx| ctx.run(the_reporter) }
40
- end
40
+ end unless root_contexts.empty?
41
41
  the_reporter
42
42
  end
43
43
 
@@ -100,7 +100,16 @@ module Riot
100
100
  Riot.reporter = Riot::PrettyDotMatrixReporter
101
101
  end
102
102
 
103
- at_exit { exit(run.success?) unless Riot.alone? }
103
+ # Making sure to account for Riot being run as part of a larger rake task (or something similar).
104
+ # If a child process exited with a failing status, probably don't want to run Riot tests; just exit
105
+ # with the child status.
106
+ at_exit do
107
+ unless Riot.alone?
108
+ status = $?.exitstatus unless ($?.nil? || $?.success?)
109
+ exit(status || run.success?)
110
+ end
111
+ end
112
+
104
113
  end # Riot
105
114
 
106
115
  # A little bit of monkey-patch so we can have +context+ available anywhere.
@@ -115,3 +124,9 @@ class Object
115
124
  end
116
125
  alias_method :describe, :context
117
126
  end # Object
127
+
128
+ class Array
129
+ def extract_options!
130
+ last.is_a?(::Hash) ? pop : {}
131
+ end
132
+ end
@@ -80,13 +80,17 @@ module Riot
80
80
  #
81
81
  # asserts(:size).equals(2)
82
82
  #
83
+ # Or with arguments:
84
+ #
85
+ # asserts(:foo,1,2).equals(3)
86
+ #
83
87
  # Passing a Symbol to +asserts+ enables this behaviour. For more information on
84
88
  # assertion macros, see {Riot::AssertionMacro}.
85
89
  #
86
90
  # @param [String, Symbol] what description of test or property to inspect on the topic
87
91
  # @return [Riot::Assertion]
88
- def asserts(what, &definition)
89
- new_assertion("asserts", what, &definition)
92
+ def asserts(*what, &definition)
93
+ new_assertion("asserts", *what, &definition)
90
94
  end
91
95
 
92
96
  # Same as #asserts, except it uses the phrase "should" in the report output. Sometimes you feel like a
@@ -94,10 +98,14 @@ module Riot
94
98
  #
95
99
  # should("ensure expected") { "bar" }.equals("bar")
96
100
  #
101
+ # #should also has the same shortcuts available to #asserts:
102
+ #
103
+ # should(:bar,1,2).equals(3)
104
+ #
97
105
  # @param [String, Symbol] what description of test or property to inspect on the topic
98
106
  # @return [Riot::Assertion]
99
- def should(what, &definition)
100
- new_assertion("should", what, &definition)
107
+ def should(*what, &definition)
108
+ new_assertion("should", *what, &definition)
101
109
  end
102
110
 
103
111
  # Like an assertion, but expects negative results.
@@ -115,13 +123,39 @@ module Riot
115
123
  #
116
124
  # denies(:size).equals(2)
117
125
  #
126
+ # the shorcut can also pass additional arguments to the method like:
127
+ #
128
+ # denies(:foo,1,3).equals(2)
129
+ #
118
130
  # Passing a Symbol to +denies+ enables this behaviour. For more information on
119
131
  # assertion macros, see {Riot::AssertionMacro}.
120
132
  #
121
133
  # @param [String, Symbol] what description of test or property to inspect on the topic
122
134
  # @return [Riot::Assertion]
123
- def denies(what, &definition)
124
- new_assertion("denies", what, true, &definition)
135
+ def denies(*what, &definition)
136
+ what << {:negative => true}
137
+ new_assertion "denies", *what, &definition
138
+ end
139
+
140
+ # This is the negative form of #should. This is exactly like denies. Just here for syntactic sugar.
141
+ #
142
+ # A basic eample is:
143
+ #
144
+ # should_not("have size equal 2") { topic.size == 2 }
145
+ #
146
+ # In addition, the #denies shortcut as available as well:
147
+ #
148
+ # should_not(:size).equals 3
149
+ #
150
+ # Or passing in arguments
151
+ #
152
+ # should_not(:foo,1,2).equals(2)
153
+ #
154
+ # @param [String,Symbol] what description or property to inspect on the topic
155
+ # @return [Riot::Assertion]
156
+ def should_not(*what, &definition)
157
+ what << {:negative => true}
158
+ new_assertion "should not", *what, &definition
125
159
  end
126
160
 
127
161
  # Makes an assertion on the topic itself, e.g.
@@ -133,19 +167,25 @@ module Riot
133
167
  def asserts_topic(what="that it")
134
168
  asserts(what) { topic }
135
169
  end
136
- private
137
- def new_assertion(scope, what, negative=false, &definition)
138
- if what.kind_of?(Symbol)
139
- definition ||= proc { topic.send(what) }
140
- description = "#{scope} ##{what}"
141
- elsif what.kind_of?(Array)
142
- definition ||= proc { topic.send(*what) }
143
- description = "#{scope} ##{what.first} with argument(s): #{what[1..-1]}"
144
- else
145
- description = "#{scope} #{what}"
146
- end
147
170
 
148
- (@assertions << assertion_class.new(description, negative, &definition)).last
171
+ # Makes a negative assertion on the topic itself, e.g.
172
+ #
173
+ # denies_topic.matches(/^ab+/)
174
+ #
175
+ # @param [String] what description of test
176
+ # @return [Riot::Assertion]
177
+ def denies_topic(what="that it")
178
+ denies(what) { topic }
149
179
  end
180
+ private
181
+
182
+ def new_assertion(scope, *args, &definition)
183
+ options = args.extract_options!
184
+ definition ||= proc { topic.send(*args) }
185
+ description = "#{scope} #{args.first}"
186
+ description << " with arguments(s): #{args.slice(1, args.length)}" if args.size > 1
187
+ (@assertions << assertion_class.new(description, options[:negative], &definition)).last
188
+ end
189
+
150
190
  end # AssertionHelpers
151
191
  end # Riot
@@ -1,4 +1,4 @@
1
1
  module Riot
2
- VERSION = "0.12.2"
2
+ VERSION = "0.12.3"
3
3
  end
4
4
 
@@ -19,3 +19,23 @@ context "The asserts_topic shortcut" do
19
19
  asserts(:to_s).equals("asserts get some")
20
20
  end
21
21
  end # The asserts_topic shortcut
22
+
23
+ context "The denies_topic shortcut" do
24
+ setup do
25
+ Riot::Context.new("foo") {}.denies_topic
26
+ end
27
+
28
+ should("return an Assertion") { topic }.kind_of(Riot::Assertion)
29
+
30
+ should("return the actual topic as the result of evaling the assertion") do
31
+ (situation = Riot::Situation.new).instance_variable_set(:@_topic, "bar")
32
+ topic.equals("not bar").run(situation)
33
+ end.equals([:pass, %Q{is equal to "not bar" when it is "bar"}])
34
+
35
+ asserts(:to_s).equals("denies that it")
36
+
37
+ context "with an explicit description" do
38
+ setup { Riot::Context.new("foo") {}.denies_topic("get some") }
39
+ asserts(:to_s).equals("denies get some")
40
+ end
41
+ end # The denies_topic shortcut
@@ -2,7 +2,7 @@ require 'teststrap'
2
2
 
3
3
  context "an assertion made with arguments" do
4
4
  setup do
5
- Riot::Context.new("foo") {}.asserts([:[], 0])
5
+ Riot::Context.new("foo") {}.asserts(:[], 0)
6
6
  end
7
7
 
8
8
  should("pass its argument to send, with the first argument as method name") do
@@ -10,3 +10,14 @@ context "an assertion made with arguments" do
10
10
  topic.equals(1).run(situation).first
11
11
  end.equals(:pass)
12
12
  end # assertion made with arguments
13
+
14
+ context "a should made with arguments" do
15
+ setup do
16
+ Riot::Context.new("foo") {}.should(:[], 0)
17
+ end
18
+
19
+ should("pass its argument to send, with the first argument as method name") do
20
+ (situation = Riot::Situation.new).instance_variable_set(:@_topic, [1, 2])
21
+ topic.equals(1).run(situation).first
22
+ end.equals(:pass)
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'teststrap'
2
+
3
+ context "a negative assertion made with arguments" do
4
+ setup do
5
+ Riot::Context.new("foo") {}.denies(:[], 0)
6
+ end
7
+
8
+ should("pass its argument to send, with the first argument as method name") do
9
+ (situation = Riot::Situation.new).instance_variable_set(:@_topic, [1, 2])
10
+ topic.equals(1).run(situation).first
11
+ end.equals(:fail)
12
+ end # assertion made with arguments
13
+
14
+ context "a negative assertion made with arguments" do
15
+ setup do
16
+ Riot::Context.new("foo") {}.should_not(:[], 0)
17
+ end
18
+
19
+ should("pass its argument to send, with the first argument as method name") do
20
+ (situation = Riot::Situation.new).instance_variable_set(:@_topic, [1, 2])
21
+ topic.equals(1).run(situation).first
22
+ end.equals(:fail)
23
+ end # assertion made with arguments
@@ -2,24 +2,52 @@ require 'teststrap'
2
2
 
3
3
  context "Using denies" do
4
4
 
5
- helper(:denial_context) do |&assertion_block|
5
+ helper(:denial_context) do |actual|
6
6
  report = Riot::Context.new("Apple Jackie") do
7
- denies("with false", &assertion_block)
7
+ denies("with false") { actual }
8
8
  end.run(MockReporter.new)
9
9
 
10
10
  [report.passes, report.failures, report.errors]
11
11
  end # denial_context
12
12
 
13
13
  asserts("result when returning false from the assertion block") do
14
- denial_context { false }
14
+ denial_context(false)
15
15
  end.equals([1,0,0])
16
16
 
17
17
  asserts("result when returning true from the assertion block") do
18
- denial_context { true }
18
+ denial_context(true)
19
19
  end.equals([0,1,0])
20
20
 
21
21
  asserts("result when assertion block has an exception") do
22
- denial_context { raise Exception }
23
- end.equals([0,0,1])
22
+ Riot::Context.new("Apple Jackie") do
23
+ denies("with false") { raise Exception }
24
+ end.run(MockReporter.new).errors
25
+ end.equals(1)
24
26
 
25
27
  end # Using denies
28
+
29
+ context "Using should_not" do
30
+
31
+ helper(:denial_context) do |actual|
32
+ report = Riot::Context.new("Apple Jackie") do
33
+ should_not("with false") { actual }
34
+ end.run(MockReporter.new)
35
+
36
+ [report.passes, report.failures, report.errors]
37
+ end # denial_context
38
+
39
+ asserts("result when returning false from the assertion block") do
40
+ denial_context(false)
41
+ end.equals([1,0,0])
42
+
43
+ asserts("result when returning true from the assertion block") do
44
+ denial_context(true)
45
+ end.equals([0,1,0])
46
+
47
+ asserts("result when assertion block has an exception") do
48
+ Riot::Context.new("Apple Jackie") do
49
+ should_not("with false") { raise Exception }
50
+ end.run(MockReporter.new).errors
51
+ end.equals(1)
52
+
53
+ end # Using should_not
@@ -2,35 +2,35 @@ require 'teststrap'
2
2
 
3
3
  context "A negative assertion test" do
4
4
 
5
- helper(:negative_assertion) do |&definition|
6
- Riot::Assertion.new("foo", true, &definition)
5
+ helper(:negative_assertion) do |definition|
6
+ Riot::Assertion.new("foo", true) { definition }
7
7
  end
8
8
 
9
9
  asserts("response when evaluated with false result") do
10
- negative_assertion { false }.run(Riot::Situation.new)
10
+ negative_assertion(false).run(Riot::Situation.new)
11
11
  end.equals([:pass, ""])
12
12
 
13
13
  asserts("response when evaluated with nil result") do
14
- negative_assertion { false }.run(Riot::Situation.new)
14
+ negative_assertion(false).run(Riot::Situation.new)
15
15
  end.equals([:pass, ""])
16
16
 
17
17
  asserts("response when evaluated with true result") do
18
- negative_assertion { true }.run(Riot::Situation.new)
18
+ negative_assertion(true).run(Riot::Situation.new)
19
19
  end.equals([:fail, "Expected non-true but got true instead", nil, nil])
20
20
 
21
21
  asserts("response when evaluated with \"bar\" result") do
22
- negative_assertion { "bar" }.run(Riot::Situation.new)
22
+ negative_assertion("bar").run(Riot::Situation.new)
23
23
  end.equals([:fail, "Expected non-true but got \"bar\" instead", nil, nil])
24
24
 
25
25
  asserts("response when evaluated with 0 result") do
26
- negative_assertion { 0 }.run(Riot::Situation.new)
26
+ negative_assertion(0).run(Riot::Situation.new)
27
27
  end.equals([:fail, "Expected non-true but got 0 instead", nil, nil])
28
28
 
29
29
  helper(:big_exception) { @exception ||= Exception.new("blah") }
30
30
 
31
31
  asserts("response when evaluation errors") do
32
32
  exception = big_exception # :\
33
- negative_assertion { raise exception }.run(Riot::Situation.new)
33
+ Riot::Assertion.new("foo", true) { raise exception }.run(Riot::Situation.new)
34
34
  end.equals { [:error, big_exception] }
35
35
 
36
36
  end # A negative assertion test
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: riot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.12.2
5
+ version: 0.12.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Justin 'Gus' Knowlden
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-27 00:00:00 -06:00
13
+ date: 2011-03-10 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -97,6 +97,7 @@ files:
97
97
  - test/core/context/asserts_with_arguments_test.rb
98
98
  - test/core/context/context_test.rb
99
99
  - test/core/context/context_with_options_test.rb
100
+ - test/core/context/denies_with_arguments_test.rb
100
101
  - test/core/context/deny_test.rb
101
102
  - test/core/context/helper_test.rb
102
103
  - test/core/context/hookup_test.rb
@@ -168,6 +169,7 @@ test_files:
168
169
  - test/core/context/asserts_with_arguments_test.rb
169
170
  - test/core/context/context_test.rb
170
171
  - test/core/context/context_with_options_test.rb
172
+ - test/core/context/denies_with_arguments_test.rb
171
173
  - test/core/context/deny_test.rb
172
174
  - test/core/context/helper_test.rb
173
175
  - test/core/context/hookup_test.rb