assert 0.1.0
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 +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +17 -0
- data/README.rdoc +77 -0
- data/Rakefile +7 -0
- data/assert.gemspec +21 -0
- data/examples/empty_test.rb +5 -0
- data/examples/results_test.rb +25 -0
- data/examples/single_test.rb +9 -0
- data/lib/assert.rb +8 -0
- data/lib/assert/assertions.rb +253 -0
- data/lib/assert/context.rb +196 -0
- data/lib/assert/options.rb +43 -0
- data/lib/assert/rake_tasks.rb +95 -0
- data/lib/assert/result.rb +164 -0
- data/lib/assert/result_set.rb +14 -0
- data/lib/assert/runner.rb +60 -0
- data/lib/assert/setup/autorun.rb +34 -0
- data/lib/assert/setup/helpers.rb +62 -0
- data/lib/assert/setup/suite.rb +12 -0
- data/lib/assert/setup/view.rb +11 -0
- data/lib/assert/suite.rb +128 -0
- data/lib/assert/test.rb +90 -0
- data/lib/assert/version.rb +3 -0
- data/lib/assert/view/base.rb +54 -0
- data/lib/assert/view/terminal.rb +138 -0
- data/test/assertions/assert_block_test.rb +39 -0
- data/test/assertions/assert_instance_of_test.rb +43 -0
- data/test/assertions/assert_kind_of_test.rb +43 -0
- data/test/assertions/assert_not_block_test.rb +39 -0
- data/test/assertions/assert_not_instance_of_test.rb +43 -0
- data/test/assertions/assert_not_kind_of_test.rb +43 -0
- data/test/assertions/assert_not_respond_to_test.rb +43 -0
- data/test/assertions/assert_nothing_raised_test.rb +46 -0
- data/test/assertions/assert_raises_test.rb +49 -0
- data/test/assertions/assert_respond_to_test.rb +43 -0
- data/test/assertions_test.rb +334 -0
- data/test/context/class_methods_test.rb +314 -0
- data/test/context_test.rb +288 -0
- data/test/fixtures/inherited_stuff.rb +36 -0
- data/test/fixtures/sample_context.rb +13 -0
- data/test/helper.rb +52 -0
- data/test/irb.rb +10 -0
- data/test/options_test.rb +78 -0
- data/test/result_set_test.rb +89 -0
- data/test/result_test.rb +255 -0
- data/test/runner_test.rb +33 -0
- data/test/suite_test.rb +200 -0
- data/test/test/running_test.rb +327 -0
- data/test/test_test.rb +184 -0
- data/test/view_test.rb +35 -0
- metadata +155 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Assertions::AssertRaisesTest < Assert::Context
|
4
|
+
desc "the assert_raises helper run in a test"
|
5
|
+
setup do
|
6
|
+
fail_desc = @fail_desc = "assert raises fail desc"
|
7
|
+
@test = Factory.test do
|
8
|
+
assert_raises(StandardError, RuntimeError){ raise(StandardError) } # pass
|
9
|
+
assert_raises(StandardError, RuntimeError, fail_desc){ raise(Exception) } # fail
|
10
|
+
assert_raises(RuntimeError, fail_desc){ raise(StandardError) } # fail
|
11
|
+
assert_raises(RuntimeError, fail_desc){ true } # fail
|
12
|
+
assert_raises(fail_desc){ true } # fail
|
13
|
+
end
|
14
|
+
@test.run
|
15
|
+
end
|
16
|
+
subject{ @test }
|
17
|
+
|
18
|
+
should "have 3 total results" do
|
19
|
+
assert_equal 5, subject.result_count
|
20
|
+
end
|
21
|
+
should "have 1 pass result" do
|
22
|
+
assert_equal 1, subject.result_count(:pass)
|
23
|
+
end
|
24
|
+
should "have 4 fail results" do
|
25
|
+
assert_equal 4, subject.result_count(:fail)
|
26
|
+
end
|
27
|
+
|
28
|
+
class FailMessageTest < AssertRaisesTest
|
29
|
+
desc "with a failed result"
|
30
|
+
setup do
|
31
|
+
@expected = [
|
32
|
+
"#{@fail_desc}\nStandardError or RuntimeError exception expected, not:",
|
33
|
+
"#{@fail_desc}\nRuntimeError exception expected, not:",
|
34
|
+
"#{@fail_desc}\nRuntimeError exception expected but nothing was raised.",
|
35
|
+
"#{@fail_desc}\nAn exception expected but nothing was raised."
|
36
|
+
]
|
37
|
+
@fail_messages = @test.fail_results.collect(&:message)
|
38
|
+
end
|
39
|
+
subject{ @fail_messages }
|
40
|
+
|
41
|
+
should "have a fail message with an explanation of what failed and my fail description" do
|
42
|
+
subject.each_with_index do |message, n|
|
43
|
+
assert_match /^#{@expected[n]}/, message
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Assertions::AssertRespondToTest < Assert::Context
|
4
|
+
desc "the assert_respond_to helper run in a test"
|
5
|
+
setup do
|
6
|
+
fail_desc = @fail_desc = "assert respond to fail desc"
|
7
|
+
fail_args = @fail_args = [ "1", :abs, fail_desc ]
|
8
|
+
@test = Factory.test do
|
9
|
+
assert_respond_to(1, :abs) # pass
|
10
|
+
assert_respond_to(*fail_args) # fail
|
11
|
+
end
|
12
|
+
@test.run
|
13
|
+
end
|
14
|
+
subject{ @test }
|
15
|
+
|
16
|
+
should "have 2 total results" do
|
17
|
+
assert_equal 2, subject.result_count
|
18
|
+
end
|
19
|
+
should "have 1 pass result" do
|
20
|
+
assert_equal 1, subject.result_count(:pass)
|
21
|
+
end
|
22
|
+
should "have 1 fail result" do
|
23
|
+
assert_equal 1, subject.result_count(:fail)
|
24
|
+
end
|
25
|
+
|
26
|
+
class FailMessageTest < AssertRespondToTest
|
27
|
+
desc "with a failed result"
|
28
|
+
setup do
|
29
|
+
@expected = [
|
30
|
+
"Expected #{@fail_args[0].inspect} (#{@fail_args[0].class}) to",
|
31
|
+
"respond to ##{@fail_args[1]}.\n#{@fail_args[2]}"
|
32
|
+
].join(" ")
|
33
|
+
@fail_message = @test.fail_results.first.message
|
34
|
+
end
|
35
|
+
subject{ @fail_message }
|
36
|
+
|
37
|
+
should "have a fail message with an explanation of what failed and my fail description" do
|
38
|
+
assert_equal @expected, subject
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,334 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Assertions::BasicTest < Assert::Context
|
4
|
+
|
5
|
+
desc "An assert context"
|
6
|
+
setup do
|
7
|
+
@context_class = Factory.context_class
|
8
|
+
@context = @context_class.new
|
9
|
+
end
|
10
|
+
subject{ @context }
|
11
|
+
|
12
|
+
INSTANCE_METHODS = [
|
13
|
+
:assert_block, :assert_not_block, :refute_block,
|
14
|
+
:assert_raises, :assert_raise, :assert_nothing_raised, :assert_not_raises, :assert_not_raise,
|
15
|
+
:assert_kind_of, :assert_not_kind_of, :refute_kind_of,
|
16
|
+
:assert_instance_of, :assert_not_instance_of, :refute_instance_of,
|
17
|
+
:assert_respond_to, :assert_not_respond_to, :refute_respond_to,
|
18
|
+
:assert_same, :assert_not_same, :refute_same,
|
19
|
+
:assert_equal, :assert_not_equal, :refute_equal,
|
20
|
+
:assert_match, :assert_not_match, :assert_no_match, :refute_match
|
21
|
+
]
|
22
|
+
INSTANCE_METHODS.each do |method|
|
23
|
+
should "respond to the instance method ##{method}" do
|
24
|
+
assert_respond_to subject, method
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class IgnoredTest < BasicTest
|
29
|
+
desc "ignored assertions helpers"
|
30
|
+
setup do
|
31
|
+
@tests = Assert::Assertions::IGNORED_ASSERTION_HELPERS.collect do |helper|
|
32
|
+
Factory.test("ignored assertion helper #{helper}", @context_class) do
|
33
|
+
self.send(helper, "doesn't matter")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@expected_messages = Assert::Assertions::IGNORED_ASSERTION_HELPERS.collect do |helper|
|
37
|
+
[ "The assertion helper '#{helper}' is not supported. Please use ",
|
38
|
+
"another helper or the basic assert."
|
39
|
+
].join
|
40
|
+
end
|
41
|
+
@results = @tests.collect(&:run).flatten
|
42
|
+
end
|
43
|
+
subject{ @results }
|
44
|
+
|
45
|
+
should "have an ignored result for each helper in the constant" do
|
46
|
+
subject.each do |result|
|
47
|
+
assert_kind_of Assert::Result::Ignore, result
|
48
|
+
end
|
49
|
+
assert_equal(Assert::Assertions::IGNORED_ASSERTION_HELPERS.size, subject.size)
|
50
|
+
end
|
51
|
+
should "have a custom ignore message for each helper in the constant" do
|
52
|
+
assert_equal(@expected_messages, subject.collect(&:message))
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
=begin
|
60
|
+
module Assert::Assertions
|
61
|
+
|
62
|
+
class AssertSameTest < BasicTest
|
63
|
+
|
64
|
+
setup do
|
65
|
+
klass = Class.new
|
66
|
+
object = klass.new
|
67
|
+
@test = Assert::Test.new("assert same test", lambda do
|
68
|
+
assert_same(object, object) # pass
|
69
|
+
assert_same(object, klass.new) # fail
|
70
|
+
end, @context_klass)
|
71
|
+
@test.run
|
72
|
+
end
|
73
|
+
subject{ @test }
|
74
|
+
|
75
|
+
should "have 2 total results" do
|
76
|
+
assert_equal 2, subject.result_count
|
77
|
+
end
|
78
|
+
|
79
|
+
should "have 1 pass result" do
|
80
|
+
assert_equal 1, subject.result_count(:pass)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "have 1 fail result" do
|
84
|
+
assert_equal 1, subject.result_count(:fail)
|
85
|
+
end
|
86
|
+
|
87
|
+
class MessagesTest < AssertSameTest
|
88
|
+
|
89
|
+
setup do
|
90
|
+
klass = Class.new
|
91
|
+
args = [ klass.new, klass.new, "assert same shoudn't fail!" ]
|
92
|
+
@test = Assert::Test.new("assert same message test", lambda do
|
93
|
+
assert_same(*args)
|
94
|
+
end, @context_klass)
|
95
|
+
@expected_message = "Expected #{args[0].inspect} (#{args[0].object_id}) to be the same as #{args[1]} (#{args[1].object_id}).\n#{args[2]}"
|
96
|
+
@test.run
|
97
|
+
@message = @test.fail_results.first.message
|
98
|
+
end
|
99
|
+
subject{ @message }
|
100
|
+
|
101
|
+
should "have the correct failure message" do
|
102
|
+
assert_equal @expected_message, subject
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class AssertNotSameTest < BasicTest
|
110
|
+
|
111
|
+
setup do
|
112
|
+
klass = Class.new
|
113
|
+
object = klass.new
|
114
|
+
@test = Assert::Test.new("assert not same test", lambda do
|
115
|
+
assert_not_same(object, object) # fail
|
116
|
+
assert_not_same(object, klass.new) # pass
|
117
|
+
end, @context_klass)
|
118
|
+
@test.run
|
119
|
+
end
|
120
|
+
subject{ @test }
|
121
|
+
|
122
|
+
should "have 2 total results" do
|
123
|
+
assert_equal 2, subject.result_count
|
124
|
+
end
|
125
|
+
|
126
|
+
should "have 1 pass result" do
|
127
|
+
assert_equal 1, subject.result_count(:pass)
|
128
|
+
end
|
129
|
+
|
130
|
+
should "have 1 fail result" do
|
131
|
+
assert_equal 1, subject.result_count(:fail)
|
132
|
+
end
|
133
|
+
|
134
|
+
class MessagesTest < AssertNotSameTest
|
135
|
+
|
136
|
+
setup do
|
137
|
+
klass = Class.new
|
138
|
+
object = klass.new
|
139
|
+
args = [ object, object, "assert not same shoudn't fail!" ]
|
140
|
+
@test = Assert::Test.new("assert not same message test", lambda do
|
141
|
+
assert_not_same(*args)
|
142
|
+
end, @context_klass)
|
143
|
+
@expected_message = "#{args[0].inspect} (#{args[0].object_id}) not expected to be the same as #{args[1]} (#{args[1].object_id}).\n#{args[2]}"
|
144
|
+
@test.run
|
145
|
+
@message = @test.fail_results.first.message
|
146
|
+
end
|
147
|
+
subject{ @message }
|
148
|
+
|
149
|
+
should "have the correct failure message" do
|
150
|
+
assert_equal @expected_message, subject
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
class AssertEqualTest < BasicTest
|
158
|
+
|
159
|
+
setup do
|
160
|
+
@test = Assert::Test.new("assert equal test", lambda do
|
161
|
+
assert_equal(1, 1) # pass
|
162
|
+
assert_equal(1, 2) # fail
|
163
|
+
end, @context_klass)
|
164
|
+
@test.run
|
165
|
+
end
|
166
|
+
subject{ @test }
|
167
|
+
|
168
|
+
should "have 2 total results" do
|
169
|
+
assert_equal 2, subject.result_count
|
170
|
+
end
|
171
|
+
|
172
|
+
should "have 1 pass result" do
|
173
|
+
assert_equal 1, subject.result_count(:pass)
|
174
|
+
end
|
175
|
+
|
176
|
+
should "have 1 fail result" do
|
177
|
+
assert_equal 1, subject.result_count(:fail)
|
178
|
+
end
|
179
|
+
|
180
|
+
class MessagesTest < AssertEqualTest
|
181
|
+
|
182
|
+
setup do
|
183
|
+
args = [ 1, 2, "assert equal shoudn't fail!" ]
|
184
|
+
@test = Assert::Test.new("assert equal message test", lambda do
|
185
|
+
assert_equal(*args)
|
186
|
+
end, @context_klass)
|
187
|
+
@expected_message = "Expected #{args[0].inspect}, not #{args[1].inspect}.\n#{args[2]}"
|
188
|
+
@test.run
|
189
|
+
@message = @test.fail_results.first.message
|
190
|
+
end
|
191
|
+
subject{ @message }
|
192
|
+
|
193
|
+
should "have the correct failure message" do
|
194
|
+
assert_equal @expected_message, subject
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
class AssertNotEqualTest < BasicTest
|
202
|
+
|
203
|
+
setup do
|
204
|
+
@test = Assert::Test.new("assert not equal test", lambda do
|
205
|
+
assert_not_equal(1, 1) # fail
|
206
|
+
assert_not_equal(1, 2) # pass
|
207
|
+
end, @context_klass)
|
208
|
+
@test.run
|
209
|
+
end
|
210
|
+
subject{ @test }
|
211
|
+
|
212
|
+
should "have 2 total results" do
|
213
|
+
assert_equal 2, subject.result_count
|
214
|
+
end
|
215
|
+
|
216
|
+
should "have 1 pass result" do
|
217
|
+
assert_equal 1, subject.result_count(:pass)
|
218
|
+
end
|
219
|
+
|
220
|
+
should "have 1 fail result" do
|
221
|
+
assert_equal 1, subject.result_count(:fail)
|
222
|
+
end
|
223
|
+
|
224
|
+
class MessagesTest < AssertNotEqualTest
|
225
|
+
|
226
|
+
setup do
|
227
|
+
args = [ 1, 1, "assert not equal shoudn't fail!" ]
|
228
|
+
@test = Assert::Test.new("assert not equal message test", lambda do
|
229
|
+
assert_not_equal(*args)
|
230
|
+
end, @context_klass)
|
231
|
+
@expected_message = "#{args[0].inspect} not expected to be equal to #{args[1].inspect}.\n#{args[2]}"
|
232
|
+
@test.run
|
233
|
+
@message = @test.fail_results.first.message
|
234
|
+
end
|
235
|
+
subject{ @message }
|
236
|
+
|
237
|
+
should "have the correct failure message" do
|
238
|
+
assert_equal @expected_message, subject
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
class AssertMatchTest < BasicTest
|
246
|
+
|
247
|
+
setup do
|
248
|
+
@test = Assert::Test.new("assert match test", lambda do
|
249
|
+
assert_match("a string", /a/) # pass
|
250
|
+
assert_match("a string", "not") # fail
|
251
|
+
end, @context_klass)
|
252
|
+
@test.run
|
253
|
+
end
|
254
|
+
subject{ @test }
|
255
|
+
|
256
|
+
should "have 2 total results" do
|
257
|
+
assert_equal 2, subject.result_count
|
258
|
+
end
|
259
|
+
|
260
|
+
should "have 1 pass result" do
|
261
|
+
assert_equal 1, subject.result_count(:pass)
|
262
|
+
end
|
263
|
+
|
264
|
+
should "have 1 fail result" do
|
265
|
+
assert_equal 1, subject.result_count(:fail)
|
266
|
+
end
|
267
|
+
|
268
|
+
class MessagesTest < AssertMatchTest
|
269
|
+
|
270
|
+
setup do
|
271
|
+
args = [ "a string", "not", "assert match shoudn't fail!" ]
|
272
|
+
@test = Assert::Test.new("assert match message test", lambda do
|
273
|
+
assert_match(*args)
|
274
|
+
end, @context_klass)
|
275
|
+
@expected_message = "Expected #{args[0].inspect} to match #{args[1].inspect}.\n#{args[2]}"
|
276
|
+
@test.run
|
277
|
+
@message = @test.fail_results.first.message
|
278
|
+
end
|
279
|
+
subject{ @message }
|
280
|
+
|
281
|
+
should "have the correct failure message" do
|
282
|
+
assert_equal @expected_message, subject
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
class AssertNotMatchTest < BasicTest
|
290
|
+
|
291
|
+
setup do
|
292
|
+
@test = Assert::Test.new("assert not match test", lambda do
|
293
|
+
assert_not_match("a string", /a/) # fail
|
294
|
+
assert_not_match("a string", "not") # pass
|
295
|
+
end, @context_klass)
|
296
|
+
@test.run
|
297
|
+
end
|
298
|
+
subject{ @test }
|
299
|
+
|
300
|
+
should "have 2 total results" do
|
301
|
+
assert_equal 2, subject.result_count
|
302
|
+
end
|
303
|
+
|
304
|
+
should "have 1 pass result" do
|
305
|
+
assert_equal 1, subject.result_count(:pass)
|
306
|
+
end
|
307
|
+
|
308
|
+
should "have 1 fail result" do
|
309
|
+
assert_equal 1, subject.result_count(:fail)
|
310
|
+
end
|
311
|
+
|
312
|
+
class MessagesTest < AssertNotMatchTest
|
313
|
+
|
314
|
+
setup do
|
315
|
+
args = [ "a string", /a/, "assert not match shoudn't fail!" ]
|
316
|
+
@test = Assert::Test.new("assert not match message test", lambda do
|
317
|
+
assert_not_match(*args)
|
318
|
+
end, @context_klass)
|
319
|
+
@expected_message = "#{args[0].inspect} not expected to match #{args[1].inspect}.\n#{args[2]}"
|
320
|
+
@test.run
|
321
|
+
@message = @test.fail_results.first.message
|
322
|
+
end
|
323
|
+
subject{ @message }
|
324
|
+
|
325
|
+
should "have the correct failure message" do
|
326
|
+
assert_equal @expected_message, subject
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
=end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Context::ClassMethodsTest < Assert::Context
|
4
|
+
desc "Assert context class"
|
5
|
+
setup do
|
6
|
+
@test = Factory.test
|
7
|
+
@context_class = @test.context_class
|
8
|
+
end
|
9
|
+
subject{ @context_class }
|
10
|
+
|
11
|
+
CLASS_METHODS = [
|
12
|
+
:setup_once, :before_once, :teardown_once, :after_once,
|
13
|
+
:setup, :before, :teardown, :after,
|
14
|
+
:setup_blocks, :all_setup_blocks, :teardown_blocks, :all_teardown_blocks,
|
15
|
+
:desc, :description, :descriptions, :full_description,
|
16
|
+
:subject,
|
17
|
+
:should
|
18
|
+
]
|
19
|
+
CLASS_METHODS.each do |class_method|
|
20
|
+
should "respond to the class method ##{class_method}" do
|
21
|
+
assert_respond_to subject, class_method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
teardown do
|
26
|
+
TEST_ASSERT_SUITE.clear
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
class SetupOnceTest < ClassMethodsTest
|
32
|
+
desc "setup_once method"
|
33
|
+
setup do
|
34
|
+
setup_block = @setup_block = lambda{ something_once = true }
|
35
|
+
@context_class = Factory.context_class do
|
36
|
+
setup_once(&setup_block)
|
37
|
+
end
|
38
|
+
@setup_blocks = Assert.suite.setup_blocks
|
39
|
+
end
|
40
|
+
subject{ @setup_blocks }
|
41
|
+
|
42
|
+
should "add the block to the suite's collection of setup blocks" do
|
43
|
+
assert_includes subject, @setup_block
|
44
|
+
end
|
45
|
+
|
46
|
+
teardown do
|
47
|
+
Assert.suite.setup_blocks.reject!{|b| b == @setup_block }
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
class TeardownOnceTest < ClassMethodsTest
|
55
|
+
desc "teardown_once method"
|
56
|
+
setup do
|
57
|
+
teardown_block = @teardown_block = lambda{ something_once = true }
|
58
|
+
@context_class = Factory.context_class do
|
59
|
+
teardown_once(&teardown_block)
|
60
|
+
end
|
61
|
+
@teardown_blocks = Assert.suite.teardown_blocks
|
62
|
+
end
|
63
|
+
subject{ @teardown_blocks }
|
64
|
+
|
65
|
+
should "add the block to the suite's collection of teardown blocks" do
|
66
|
+
assert_includes subject, @teardown_block
|
67
|
+
end
|
68
|
+
|
69
|
+
teardown do
|
70
|
+
Assert.suite.teardown_blocks.reject!{|b| b == @teardown_block }
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class SetupTest < ClassMethodsTest
|
78
|
+
desc "setup method"
|
79
|
+
setup do
|
80
|
+
setup_block = @setup_block = lambda{ @something = true }
|
81
|
+
@context_class = Factory.context_class do
|
82
|
+
setup(&setup_block)
|
83
|
+
end
|
84
|
+
@setup_blocks = @context_class.setup_blocks
|
85
|
+
end
|
86
|
+
subject{ @setup_blocks }
|
87
|
+
|
88
|
+
should "add the block to the context's collection of setup blocks" do
|
89
|
+
assert_includes subject, @setup_block
|
90
|
+
end
|
91
|
+
should "raise an ArgumentError when no block is passed" do
|
92
|
+
assert_raises ArgumentError do
|
93
|
+
@context_class.setup
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
class TeardownTest < ClassMethodsTest
|
102
|
+
desc "teardown method"
|
103
|
+
setup do
|
104
|
+
teardown_block = @teardown_block = lambda{ @something = false }
|
105
|
+
@context_class = Factory.context_class do
|
106
|
+
teardown(&teardown_block)
|
107
|
+
end
|
108
|
+
@teardown_blocks = @context_class.teardown_blocks
|
109
|
+
end
|
110
|
+
subject{ @teardown_blocks }
|
111
|
+
|
112
|
+
should "add the block to the context's collection of teardown blocks" do
|
113
|
+
assert_includes subject, @teardown_block
|
114
|
+
end
|
115
|
+
should "raise an ArgumentError when no block is passed" do
|
116
|
+
assert_raises ArgumentError do
|
117
|
+
@context_class.teardown
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class AllSetupBlocksTest < ClassMethodsTest
|
126
|
+
desc "all_setup_blocks method"
|
127
|
+
setup do
|
128
|
+
parent_block = @parent_block = lambda{ @parent_something = true }
|
129
|
+
@parent_class = Factory.context_class do
|
130
|
+
setup(&parent_block)
|
131
|
+
end
|
132
|
+
setup_block = @setup_block = lambda{ @something = true }
|
133
|
+
@context_class = Factory.context_class(@parent_class) do
|
134
|
+
setup(&setup_block)
|
135
|
+
end
|
136
|
+
@setup_blocks = @context_class.all_setup_blocks
|
137
|
+
end
|
138
|
+
subject{ @setup_blocks }
|
139
|
+
|
140
|
+
should "return a collection containing both context's setup blocks" do
|
141
|
+
assert_kind_of Array, subject
|
142
|
+
assert_includes subject, @parent_block
|
143
|
+
assert_includes subject, @setup_block
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
class AllTeardownBlocksTest < ClassMethodsTest
|
151
|
+
desc "all_teardown_blocks method"
|
152
|
+
setup do
|
153
|
+
parent_block = @parent_block = lambda{ @parent_something = false }
|
154
|
+
@parent_class = Factory.context_class do
|
155
|
+
teardown(&parent_block)
|
156
|
+
end
|
157
|
+
teardown_block = @teardown_block = lambda{ @something = false }
|
158
|
+
@context_class = Factory.context_class(@parent_class) do
|
159
|
+
teardown(&teardown_block)
|
160
|
+
end
|
161
|
+
@teardown_blocks = @context_class.all_teardown_blocks
|
162
|
+
end
|
163
|
+
subject{ @teardown_blocks }
|
164
|
+
|
165
|
+
should "return a collection containing both context's setup blocks" do
|
166
|
+
assert_kind_of Array, subject
|
167
|
+
assert_includes subject, @parent_block
|
168
|
+
assert_includes subject, @teardown_block
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
class DescTest < ClassMethodsTest
|
176
|
+
desc "desc method"
|
177
|
+
setup do
|
178
|
+
descs = @descs = [ "something amazing", "it really is" ]
|
179
|
+
@context_class = Factory.context_class do
|
180
|
+
descs.each do |text|
|
181
|
+
desc text
|
182
|
+
end
|
183
|
+
end
|
184
|
+
@descriptions = @context_class.descriptions
|
185
|
+
end
|
186
|
+
subject{ @descriptions }
|
187
|
+
|
188
|
+
should "return a collection containing any descriptions defined on the class" do
|
189
|
+
assert_kind_of Array, subject
|
190
|
+
@descs.each do |text|
|
191
|
+
assert_includes subject, text
|
192
|
+
end
|
193
|
+
end
|
194
|
+
should "raise an error when no description is provided" do
|
195
|
+
assert_raises ArgumentError do
|
196
|
+
@context_class.desc
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
class FullDescriptionTest < ClassMethodsTest
|
205
|
+
desc "full_description method"
|
206
|
+
setup do
|
207
|
+
parent_text = @parent_desc = "parent description"
|
208
|
+
@parent_class = Factory.context_class do
|
209
|
+
desc parent_text
|
210
|
+
end
|
211
|
+
text = @desc = "and the description for this context"
|
212
|
+
@context_class = Factory.context_class(@parent_class) do
|
213
|
+
desc text
|
214
|
+
end
|
215
|
+
@full_description = @context_class.full_description
|
216
|
+
end
|
217
|
+
subject{ @full_description }
|
218
|
+
|
219
|
+
should "return a string of all the inherited descriptions" do
|
220
|
+
assert_kind_of String, subject
|
221
|
+
assert_match @parent_desc, subject
|
222
|
+
assert_match @desc, subject
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
class SubjectTest < ClassMethodsTest
|
230
|
+
desc "subject method"
|
231
|
+
setup do
|
232
|
+
subject_block = @subject_block = lambda{ @something }
|
233
|
+
@context_class = Factory.context_class do
|
234
|
+
subject(&subject_block)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
subject{ @subject_block }
|
238
|
+
|
239
|
+
should "set the subject block on the context class" do
|
240
|
+
assert_equal subject, @context_class.subject_block
|
241
|
+
end
|
242
|
+
should "raise an ArgumentError when no block is passed" do
|
243
|
+
assert_raises ArgumentError do
|
244
|
+
@context_class.subject
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
class SubjectBlockTest < ClassMethodsTest
|
253
|
+
desc "subject_block method"
|
254
|
+
setup do
|
255
|
+
parent_block = @parent_block = lambda{ @something }
|
256
|
+
@parent_class = Factory.context_class do
|
257
|
+
subject(&parent_block)
|
258
|
+
end
|
259
|
+
@context_class = Factory.context_class(@parent_class)
|
260
|
+
end
|
261
|
+
subject{ @parent_block }
|
262
|
+
|
263
|
+
should "default to it's parents subject block" do
|
264
|
+
assert_equal subject, @context_class.subject_block
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
class ShouldTest < ClassMethodsTest
|
271
|
+
desc "should method"
|
272
|
+
setup do
|
273
|
+
should_desc = "be true"
|
274
|
+
should_block = @should_block = lambda{ assert(true) }
|
275
|
+
@context_class = Factory.context_class do
|
276
|
+
should(should_desc, &should_block)
|
277
|
+
end
|
278
|
+
@method_name = "test: should #{should_desc}"
|
279
|
+
@context = @context_class.new(Factory.test("something", @context_class))
|
280
|
+
end
|
281
|
+
subject{ @context }
|
282
|
+
|
283
|
+
should "define a test method named after the should desc" do
|
284
|
+
assert_respond_to subject, @method_name
|
285
|
+
assert_equal subject.instance_eval(&@should_block), subject.send(@method_name)
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
class ShouldEventuallyTest < ClassMethodsTest
|
293
|
+
desc "should_eventually method"
|
294
|
+
setup do
|
295
|
+
should_desc = @should_desc = "be true"
|
296
|
+
should_block = @should_block = lambda{ assert(true) }
|
297
|
+
@context_class = Factory.context_class do
|
298
|
+
should_eventually(should_desc, &should_block)
|
299
|
+
end
|
300
|
+
@method_name = "test: should #{@should_desc}"
|
301
|
+
@context = @context_class.new(Factory.test("something", @context_class))
|
302
|
+
end
|
303
|
+
subject{ @context }
|
304
|
+
|
305
|
+
should "define a test method named after the should desc that raises a test skipped" do
|
306
|
+
assert_respond_to subject, @method_name
|
307
|
+
assert_raises(Assert::Result::TestSkipped) do
|
308
|
+
subject.send(@method_name)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|