baretest 0.1.0 → 0.2.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/LICENSE.txt +52 -0
- data/MANIFEST.txt +50 -31
- data/README.rdoc +260 -0
- data/bin/baretest +82 -24
- data/doc/baretest.rdoc +98 -0
- data/doc/mocking_stubbing_test_doubles.rdoc +5 -0
- data/doc/quickref.rdoc +261 -0
- data/doc/writing_tests.rdoc +148 -0
- data/examples/test.rake +58 -30
- data/examples/tests/irb_mode/failures.rb +26 -0
- data/examples/tests/mock_developer/test/helper/mocks.rb +0 -0
- data/examples/tests/mock_developer/test/setup.rb +57 -0
- data/examples/tests/mock_developer/test/suite/mock_demo.rb +19 -0
- data/examples/tests/overview/test.rb +89 -0
- data/examples/tests/variations/variations_01.rb +14 -0
- data/examples/tests/variations/variations_02.rb +19 -0
- data/examples/tests/variations/variations_03.rb +19 -0
- data/lib/baretest/assertion/context.rb +20 -0
- data/lib/baretest/assertion/failure.rb +22 -0
- data/lib/baretest/assertion/skip.rb +21 -0
- data/lib/{test → baretest}/assertion/support.rb +174 -39
- data/lib/baretest/assertion.rb +182 -0
- data/lib/baretest/irb_mode.rb +263 -0
- data/lib/{test/assertion/failure.rb → baretest/layout.rb} +6 -5
- data/lib/baretest/mocha.rb +18 -0
- data/lib/baretest/run/cli.rb +104 -0
- data/lib/{test → baretest}/run/errors.rb +12 -7
- data/lib/{test → baretest}/run/minimal.rb +8 -3
- data/lib/baretest/run/profile.rb +151 -0
- data/lib/{test → baretest}/run/spec.rb +10 -4
- data/lib/baretest/run/tap.rb +44 -0
- data/lib/baretest/run/xml.rb +80 -0
- data/lib/{test → baretest}/run.rb +31 -18
- data/lib/baretest/setup.rb +15 -0
- data/lib/baretest/skipped/assertion.rb +20 -0
- data/lib/baretest/skipped/suite.rb +49 -0
- data/lib/baretest/skipped.rb +15 -0
- data/lib/baretest/suite.rb +234 -0
- data/lib/baretest/utilities.rb +43 -0
- data/lib/{test → baretest}/version.rb +12 -3
- data/lib/baretest.rb +112 -0
- data/test/external/bootstraptest.rb +1 -1
- data/test/setup.rb +1 -1
- data/test/{lib/test → suite/lib/baretest}/assertion/support.rb +78 -24
- data/test/suite/lib/baretest/assertion.rb +192 -0
- data/test/{lib/test → suite/lib/baretest}/irb_mode.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/cli.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/errors.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/interactive.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/spec.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/tap.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run/xml.rb +0 -0
- data/test/{lib/test → suite/lib/baretest}/run.rb +63 -61
- data/test/{lib/test → suite/lib/baretest}/suite.rb +77 -54
- data/test/{lib/test.rb → suite/lib/baretest.rb} +37 -37
- metadata +61 -40
- data/README.markdown +0 -229
- data/examples/test.rb +0 -93
- data/lib/test/assertion.rb +0 -117
- data/lib/test/debug.rb +0 -34
- data/lib/test/irb_mode.rb +0 -104
- data/lib/test/run/cli.rb +0 -79
- data/lib/test/run/interactive.rb +0 -60
- data/lib/test/run/tap.rb +0 -32
- data/lib/test/run/xml.rb +0 -56
- data/lib/test/suite.rb +0 -95
- data/lib/test.rb +0 -118
- data/test/lib/test/assertion.rb +0 -142
- data/test/lib/test/debug.rb +0 -63
data/test/setup.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.expand_path("#{__FILE__}/../../lib"))
|
2
|
-
require '
|
2
|
+
require 'baretest'
|
@@ -6,26 +6,28 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
module
|
9
|
+
module BareTest
|
10
10
|
class Assertion
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
class Context
|
12
|
+
# used here to test for failure
|
13
|
+
def fails # :nodoc:
|
14
|
+
failed = false
|
15
|
+
begin
|
16
|
+
failed = !yield
|
17
|
+
rescue ::BareTest::Assertion::Failure
|
18
|
+
failed = true
|
19
|
+
end
|
20
|
+
unless failed then
|
21
|
+
failure "Expected the block to fail, but it returned a true value."
|
22
|
+
end
|
23
|
+
|
24
|
+
true
|
21
25
|
end
|
22
|
-
|
23
|
-
true
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
|
30
|
+
BareTest.suite "BareTest" do
|
29
31
|
suite "Assertion" do
|
30
32
|
suite "Support" do
|
31
33
|
suite "#raises" do
|
@@ -40,7 +42,7 @@ Test.define "Test" do
|
|
40
42
|
assert "Should fail when used without argument and the block doesn't raise." do
|
41
43
|
begin
|
42
44
|
raises do "nothing raised -> should fail" end
|
43
|
-
rescue ::
|
45
|
+
rescue ::BareTest::Assertion::Failure
|
44
46
|
true
|
45
47
|
else
|
46
48
|
false
|
@@ -50,7 +52,7 @@ Test.define "Test" do
|
|
50
52
|
assert "Should fail when the block raises an exception not derived from the provided exception-class." do
|
51
53
|
begin
|
52
54
|
raises(TypeError) do raise ArgumentError, "different class -> should fail" end
|
53
|
-
rescue ::
|
55
|
+
rescue ::BareTest::Assertion::Failure
|
54
56
|
true
|
55
57
|
else
|
56
58
|
false
|
@@ -66,7 +68,7 @@ Test.define "Test" do
|
|
66
68
|
assert "Should fail when the block raises." do
|
67
69
|
begin
|
68
70
|
raises_nothing do raise "anything" end
|
69
|
-
rescue ::
|
71
|
+
rescue ::BareTest::Assertion::Failure
|
70
72
|
true
|
71
73
|
else
|
72
74
|
false
|
@@ -123,6 +125,12 @@ Test.define "Test" do
|
|
123
125
|
within_delta(3.0, 3.03, 0.02)
|
124
126
|
end
|
125
127
|
end
|
128
|
+
|
129
|
+
assert "Should fail with invalid input." do
|
130
|
+
fails do
|
131
|
+
within_delta(nil, nil, 0.02)
|
132
|
+
end
|
133
|
+
end
|
126
134
|
end # within_delta
|
127
135
|
|
128
136
|
suite "#equal_unordered" do
|
@@ -141,6 +149,12 @@ Test.define "Test" do
|
|
141
149
|
equal_unordered([1,2,3], [3,1,2,2])
|
142
150
|
end
|
143
151
|
end
|
152
|
+
|
153
|
+
assert "Should fail with invalid input." do
|
154
|
+
fails do
|
155
|
+
equal_unordered(nil, nil)
|
156
|
+
end
|
157
|
+
end
|
144
158
|
end # equal_unordered
|
145
159
|
|
146
160
|
suite "#same" do
|
@@ -154,6 +168,14 @@ Test.define "Test" do
|
|
154
168
|
same("a", "b")
|
155
169
|
end
|
156
170
|
end
|
171
|
+
|
172
|
+
assert "Should fail with invalid input." do
|
173
|
+
fails do
|
174
|
+
x = Class.new do undef equal? end # really, who does that?
|
175
|
+
y = x.new
|
176
|
+
equal_unordered(y, y)
|
177
|
+
end
|
178
|
+
end
|
157
179
|
end # same
|
158
180
|
|
159
181
|
suite "#order_equal" do
|
@@ -166,6 +188,14 @@ Test.define "Test" do
|
|
166
188
|
order_equal(1, 1.1)
|
167
189
|
end
|
168
190
|
end
|
191
|
+
|
192
|
+
assert "Should fail with invalid input." do
|
193
|
+
fails do
|
194
|
+
x = Class.new do undef == end
|
195
|
+
y = x.new
|
196
|
+
order_equal(y, y)
|
197
|
+
end
|
198
|
+
end
|
169
199
|
end # order_equal
|
170
200
|
|
171
201
|
suite "#hash_key_equal" do
|
@@ -178,6 +208,14 @@ Test.define "Test" do
|
|
178
208
|
hash_key_equal("foo", "bar")
|
179
209
|
end
|
180
210
|
end
|
211
|
+
|
212
|
+
assert "Should fail with invalid input." do
|
213
|
+
fails do
|
214
|
+
x = Class.new do undef eql? end
|
215
|
+
y = x.new
|
216
|
+
hash_key_equal(y, y)
|
217
|
+
end
|
218
|
+
end
|
181
219
|
end # hash_key_equal
|
182
220
|
|
183
221
|
suite "#case_equal" do
|
@@ -190,6 +228,14 @@ Test.define "Test" do
|
|
190
228
|
case_equal(String, [])
|
191
229
|
end
|
192
230
|
end
|
231
|
+
|
232
|
+
assert "Should fail with invalid input." do
|
233
|
+
fails do
|
234
|
+
x = Class.new do undef === end
|
235
|
+
y = x.new
|
236
|
+
case_equal(y, y)
|
237
|
+
end
|
238
|
+
end
|
193
239
|
end # case_equal
|
194
240
|
|
195
241
|
suite "#kind_of" do
|
@@ -209,32 +255,40 @@ Test.define "Test" do
|
|
209
255
|
end
|
210
256
|
|
211
257
|
suite "#failure_with_optional_message" do
|
212
|
-
assert "Should raise a
|
213
|
-
raises(::
|
258
|
+
assert "Should raise a BareTest::Assertion::Failure" do
|
259
|
+
raises(::BareTest::Assertion::Failure) do
|
214
260
|
failure_with_optional_message "With %s", "Without message", "message"
|
215
261
|
end
|
216
262
|
end
|
217
263
|
|
218
264
|
assert "Should use the string with message if message is given" do
|
219
|
-
raises(::
|
265
|
+
raises(::BareTest::Assertion::Failure, :with_message => "With message") do
|
220
266
|
failure_with_optional_message "With %s", "Without message", "message"
|
221
267
|
end
|
222
268
|
end
|
223
269
|
|
224
270
|
assert "Should use the string without message if no message is given" do
|
225
|
-
raises(::
|
271
|
+
raises(::BareTest::Assertion::Failure, :with_message => "Without message") do
|
226
272
|
failure_with_optional_message "With %s", "Without message", nil
|
227
273
|
end
|
228
274
|
end
|
229
275
|
end
|
230
276
|
|
231
277
|
suite "#failure" do
|
232
|
-
assert "Should raise a
|
233
|
-
raises(::
|
278
|
+
assert "Should raise a BareTest::Assertion::Failure." do
|
279
|
+
raises(::BareTest::Assertion::Failure) do
|
234
280
|
failure "Should raise that exception."
|
235
281
|
end
|
236
282
|
end
|
237
283
|
end
|
284
|
+
|
285
|
+
suite "#skip" do
|
286
|
+
assert "Should raise a BareTest::Assertion::Skip." do
|
287
|
+
raises(::BareTest::Assertion::Skip) do
|
288
|
+
skip "Should raise that exception."
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
238
292
|
end # Support
|
239
293
|
end # Assertion
|
240
|
-
end #
|
294
|
+
end # BareTest
|
@@ -0,0 +1,192 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2009 by Stefan Rusterholz.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#++
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
BareTest.suite "BareTest" do
|
10
|
+
suite "Assertion" do
|
11
|
+
suite "::new" do
|
12
|
+
assert "Should return a ::BareTest::Assertion instance" do
|
13
|
+
::BareTest::Assertion.new(nil, "description") { nil }.class ==
|
14
|
+
::BareTest::Assertion
|
15
|
+
end
|
16
|
+
|
17
|
+
assert "Should expect exactly 2 arguments" do
|
18
|
+
raises(ArgumentError) { ::BareTest::Assertion.new() } &&
|
19
|
+
raises(ArgumentError) { ::BareTest::Assertion.new(nil) } &&
|
20
|
+
raises(ArgumentError) { ::BareTest::Assertion.new(nil, "foo", "bar") }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
suite "#status" do
|
25
|
+
assert "A new Assertion should have a status of nil" do
|
26
|
+
::BareTest::Assertion.new(nil, "description") {}.status.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
assert "Executing an assertion with a block that returns true should be :success" do
|
30
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { true }
|
31
|
+
assertion_success.execute
|
32
|
+
assertion_success.status == :success
|
33
|
+
end
|
34
|
+
|
35
|
+
assert "Executing an assertion with a block that returns false should be :failure" do
|
36
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { false }
|
37
|
+
assertion_success.execute
|
38
|
+
assertion_success.status == :failure
|
39
|
+
end
|
40
|
+
|
41
|
+
assert "Executing an assertion with a block that raises a Failure should be :failure" do
|
42
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { raise ::BareTest::Assertion::Failure, "just fail" }
|
43
|
+
assertion_success.execute
|
44
|
+
assertion_success.status == :failure
|
45
|
+
end
|
46
|
+
|
47
|
+
assert "Executing an assertion with a block that raises should be :error" do
|
48
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { raise }
|
49
|
+
assertion_success.execute
|
50
|
+
assertion_success.status == :error
|
51
|
+
end
|
52
|
+
|
53
|
+
assert "Executing an assertion without a block should be :pending" do
|
54
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description")
|
55
|
+
assertion_success.execute
|
56
|
+
|
57
|
+
same :expected => :pending, :actual => assertion_success.status
|
58
|
+
end
|
59
|
+
|
60
|
+
assert "Executing an assertion with a block that raises a Skip should be :skipped" do
|
61
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { raise ::BareTest::Assertion::Skip, "just skip" }
|
62
|
+
assertion_success.execute
|
63
|
+
assertion_success.status == :skipped
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
suite "meta information" do
|
68
|
+
assert "An assertion should have a valid line number and file" do
|
69
|
+
suite = ::BareTest::Suite.new
|
70
|
+
assertion = suite.assert do true end
|
71
|
+
|
72
|
+
assertion[0].line && assertion[0].file
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
suite "#exception" do
|
77
|
+
assert "An assertion that doesn't raise should have nil as exception" do
|
78
|
+
assertion_success = ::BareTest::Assertion.new(nil, "description") { true }
|
79
|
+
assertion_success.execute
|
80
|
+
same :expected => nil, :actual => assertion_success.exception
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
suite "#description" do
|
85
|
+
assert "An assertion should have a description" do
|
86
|
+
description = "The assertion description"
|
87
|
+
assertion = ::BareTest::Assertion.new(nil, description) { true }
|
88
|
+
same :expected => description, :actual => assertion.description
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
suite "#suite" do
|
93
|
+
assert "An assertion can belong to a suite" do
|
94
|
+
suite = ::BareTest::Suite.new
|
95
|
+
assertion = ::BareTest::Assertion.new(suite, "") { true }
|
96
|
+
same :expected => suite, :actual => assertion.suite
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
suite "#block" do
|
101
|
+
assert "An assertion can have a block" do
|
102
|
+
block = proc { true }
|
103
|
+
assertion = ::BareTest::Assertion.new(nil, "", &block)
|
104
|
+
same :expected => block, :actual => assertion.block
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
suite "#setup" do
|
109
|
+
assert "Should run all enclosing suite's setup blocks, outermost first" do
|
110
|
+
executed = []
|
111
|
+
block1 = proc { executed << :block1 }
|
112
|
+
block2 = proc { executed << :block2 }
|
113
|
+
suite1 = ::BareTest::Suite.new("block1") do setup(&block1) end
|
114
|
+
suite2 = ::BareTest::Suite.new("suite2", suite1) do setup(&block2) end
|
115
|
+
assertion = ::BareTest::Assertion.new(suite2, "assertion")
|
116
|
+
|
117
|
+
raises_nothing do assertion.setup end &&
|
118
|
+
equal([:block1, :block2], executed)
|
119
|
+
end
|
120
|
+
|
121
|
+
assert "Should fail if setup raises an exception" do
|
122
|
+
block = proc { raise "Some error" }
|
123
|
+
suite = ::BareTest::Suite.new("block") do setup(&block) end
|
124
|
+
assertion = ::BareTest::Assertion.new(suite, "assertion") do true end
|
125
|
+
|
126
|
+
assertion.execute
|
127
|
+
|
128
|
+
equal(:error, assertion.status, "assertion.status")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
suite "#teardown" do
|
133
|
+
assert "Should run all enclosing suite's teardown blocks, innermost first" do
|
134
|
+
executed = []
|
135
|
+
block1 = proc { executed << :block1 }
|
136
|
+
block2 = proc { executed << :block2 }
|
137
|
+
suite1 = ::BareTest::Suite.new("block1") do teardown(&block1) end
|
138
|
+
suite2 = ::BareTest::Suite.new("suite2", suite1) do teardown(&block2) end
|
139
|
+
assertion = ::BareTest::Assertion.new(suite2, "assertion")
|
140
|
+
|
141
|
+
raises_nothing do assertion.teardown end &&
|
142
|
+
equal([:block2, :block1], executed)
|
143
|
+
end
|
144
|
+
|
145
|
+
assert "Should fail if teardown raises an exception" do
|
146
|
+
block = proc { raise "Some error" }
|
147
|
+
suite = ::BareTest::Suite.new("block") do teardown(&block) end
|
148
|
+
assertion = ::BareTest::Assertion.new(suite, "assertion") do true end
|
149
|
+
|
150
|
+
assertion.execute
|
151
|
+
|
152
|
+
assertion.status == :error
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
suite "#execute" do
|
157
|
+
assert "Execute will run the assertion's block" do
|
158
|
+
this = self # needed because touch is called in the block of another assertion, so otherwise it'd be local to that assertion
|
159
|
+
assertion = ::BareTest::Assertion.new(nil, "") { this.touch(:execute) }
|
160
|
+
assertion.execute
|
161
|
+
touched(:execute)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
suite "#to_s" do
|
166
|
+
assert "Assertion should have a to_s which contains the classname and the description" do
|
167
|
+
description = "the description"
|
168
|
+
assertion = ::BareTest::Assertion.new(nil, description)
|
169
|
+
print_string = assertion.to_s
|
170
|
+
|
171
|
+
print_string.include?(assertion.class.name) &&
|
172
|
+
print_string.include?(description)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
suite "#inspect" do
|
177
|
+
assert "Assertion should have an inspect which contains the classname, the shifted object-id in zero-padded hex, the suite's inspect and the description's inspect" do
|
178
|
+
suite = ::BareTest::Suite.new
|
179
|
+
description = "the description"
|
180
|
+
assertion = ::BareTest::Assertion.new(suite, description)
|
181
|
+
def suite.inspect; "<inspect of suite>"; end
|
182
|
+
|
183
|
+
inspect_string = assertion.inspect
|
184
|
+
|
185
|
+
inspect_string.include?(assertion.class.name) &&
|
186
|
+
inspect_string.include?("%08x" % (assertion.object_id >> 1)) &&
|
187
|
+
inspect_string.include?(suite.inspect) &&
|
188
|
+
inspect_string.include?(description.inspect)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|