baretest 0.2.4 → 0.4.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +6 -6
- data/MANIFEST.txt +40 -18
- data/README.rdoc +8 -1
- data/bin/baretest +126 -118
- data/doc/baretest.rdoc +1 -1
- data/doc/mocking_stubbing_test_doubles.rdoc +31 -3
- data/doc/news/news-0.3.0.rdoc +7 -0
- data/doc/quickref.rdoc +74 -28
- data/doc/whats_going_on.rdoc +5 -0
- data/doc/writing_tests.rdoc +25 -13
- data/examples/components/rack-test.rb +17 -0
- data/examples/{tests/irb_mode → irb_mode}/failures.rb +0 -0
- data/examples/rake/test.rake +40 -0
- data/examples/tests/01_basics_I.rb +34 -0
- data/examples/tests/02_basics_II_helpers.rb +25 -0
- data/examples/tests/03_basics_III_setup_and_teardown.rb +53 -0
- data/examples/tests/04_advanced_I_dependencies.rb +31 -0
- data/examples/tests/05_advanced_II_tags.rb +12 -0
- data/examples/tests/06_advanced_III_requires.rb +21 -0
- data/examples/tests/07_advanced_IV_components.rb +48 -0
- data/examples/tests/08_expert_I_setup_variants.rb +46 -0
- data/lib/baretest.rb +142 -21
- data/lib/baretest/assertion.rb +83 -92
- data/lib/baretest/assertion/context.rb +9 -0
- data/lib/baretest/assertion/support.rb +88 -61
- data/lib/baretest/commandline.rb +268 -0
- data/lib/baretest/formatter.rb +58 -0
- data/lib/baretest/invalidselectors.rb +24 -0
- data/lib/baretest/irb_mode.rb +100 -58
- data/lib/baretest/persistence.rb +94 -0
- data/lib/baretest/run.rb +138 -37
- data/lib/baretest/run/cli.rb +97 -43
- data/lib/baretest/run/minimal.rb +2 -1
- data/lib/baretest/run/none.rb +21 -0
- data/lib/baretest/run/xml.rb +21 -19
- data/lib/baretest/setup.rb +2 -0
- data/lib/baretest/status.rb +93 -0
- data/lib/baretest/suite.rb +185 -59
- data/lib/baretest/uid.rb +51 -0
- data/lib/baretest/use/mocha.rb +24 -0
- data/lib/baretest/use/rack_test.rb +9 -0
- data/lib/baretest/use/rr.rb +17 -0
- data/lib/baretest/version.rb +18 -4
- data/lib/command.rb +36 -0
- data/lib/command/argument.rb +11 -0
- data/lib/command/decoratinghash.rb +31 -0
- data/lib/command/definition.rb +294 -0
- data/lib/command/directorynotfounderror.rb +11 -0
- data/lib/command/env.rb +11 -0
- data/lib/command/filenotfounderror.rb +11 -0
- data/lib/command/kernel.rb +14 -0
- data/lib/command/nodirectoryerror.rb +11 -0
- data/lib/command/nofileerror.rb +11 -0
- data/lib/command/option.rb +16 -0
- data/lib/command/parser.rb +145 -0
- data/lib/command/result.rb +11 -0
- data/lib/command/types.rb +33 -0
- data/lib/command/version.rb +28 -0
- data/test/setup.rb +3 -0
- data/test/suite/lib/baretest.rb +0 -178
- data/test/suite/lib/baretest/assertion.rb +133 -112
- data/test/suite/lib/baretest/assertion/context.rb +40 -0
- data/test/suite/lib/baretest/assertion/failure.rb +19 -0
- data/test/suite/lib/baretest/assertion/skip.rb +19 -0
- data/test/suite/lib/baretest/assertion/support.rb +366 -84
- data/test/suite/lib/baretest/run.rb +114 -15
- data/test/suite/lib/baretest/suite.rb +70 -29
- metadata +46 -24
- data/examples/test.rake +0 -65
- data/examples/tests/mock_developer/test/helper/mocks.rb +0 -0
- data/examples/tests/mock_developer/test/setup.rb +0 -57
- data/examples/tests/mock_developer/test/suite/mock_demo.rb +0 -19
- data/examples/tests/overview/test.rb +0 -89
- data/examples/tests/variations/variations_01.rb +0 -14
- data/examples/tests/variations/variations_02.rb +0 -19
- data/examples/tests/variations/variations_03.rb +0 -19
- data/lib/baretest/mocha.rb +0 -18
- data/lib/baretest/rr.rb +0 -16
- data/lib/baretest/run/errors.rb +0 -49
- data/lib/baretest/skipped.rb +0 -15
- data/lib/baretest/skipped/assertion.rb +0 -20
- data/lib/baretest/skipped/suite.rb +0 -49
- data/test/external/bootstraptest.rb +0 -5
- data/test/external/bootstrapwrap.rb +0 -2
- data/test/helper/mocks.rb +0 -0
@@ -6,66 +6,104 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
BareTest.suite
|
10
|
-
suite
|
11
|
-
suite
|
12
|
-
assert
|
13
|
-
::BareTest::Assertion.new(nil,
|
14
|
-
::BareTest::Assertion
|
9
|
+
BareTest.suite 'BareTest' do
|
10
|
+
suite 'Assertion' do
|
11
|
+
suite '::new' do
|
12
|
+
assert 'Returns a ::BareTest::Assertion instance' do
|
13
|
+
instance_of ::BareTest::Assertion, ::BareTest::Assertion.new(nil, 'description') { nil }
|
15
14
|
end
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
suite '#execute' do
|
18
|
+
suite 'An assertion with a block that returns true' do
|
19
|
+
assert 'Returns a Status with status :success' do
|
20
|
+
assertion = ::BareTest::Assertion.new(nil, 'description') do true end
|
21
|
+
status = assertion.execute
|
22
|
+
same(:success, status.status)
|
23
|
+
end
|
21
24
|
end
|
22
|
-
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
suite 'An assertion with a block that returns false' do
|
27
|
+
setup do
|
28
|
+
@assertion = ::BareTest::Assertion.new(nil, 'description') do false end
|
29
|
+
end
|
30
|
+
|
31
|
+
assert 'Returns a Status with status :failure' do
|
32
|
+
status = @assertion.execute
|
33
|
+
same(:failure, status.status)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert 'Returns a Status with failure reason "Assertion failed"' do
|
37
|
+
status = @assertion.execute
|
38
|
+
equal("Assertion failed", status.failure_reason)
|
39
|
+
end
|
27
40
|
end
|
28
41
|
|
29
|
-
assert
|
30
|
-
|
31
|
-
|
32
|
-
|
42
|
+
assert 'Executing an assertion with a block that raises a Failure should be :failure' do
|
43
|
+
assertion = ::BareTest::Assertion.new(nil, 'description') { raise ::BareTest::Assertion::Failure, 'just fail' }
|
44
|
+
status = assertion.execute
|
45
|
+
same(:failure, status.status)
|
33
46
|
end
|
34
47
|
|
35
|
-
assert
|
36
|
-
|
37
|
-
|
38
|
-
|
48
|
+
assert 'Executing an assertion with a block that raises should be :error' do
|
49
|
+
assertion = ::BareTest::Assertion.new(nil, 'description') { raise }
|
50
|
+
status = assertion.execute
|
51
|
+
same(:error, status.status)
|
39
52
|
end
|
40
53
|
|
41
|
-
assert
|
42
|
-
|
43
|
-
|
44
|
-
|
54
|
+
assert 'Executing an assertion without a block should be :pending' do
|
55
|
+
assertion = ::BareTest::Assertion.new(nil, 'description')
|
56
|
+
status = assertion.execute
|
57
|
+
same(:pending, status.status)
|
45
58
|
end
|
46
59
|
|
47
|
-
assert
|
48
|
-
|
49
|
-
|
50
|
-
|
60
|
+
assert 'Executing an assertion with a block that raises a Skip should be :manually_skipped' do
|
61
|
+
assertion = ::BareTest::Assertion.new(nil, 'description') { raise ::BareTest::Assertion::Skip, 'just skip' }
|
62
|
+
status = assertion.execute
|
63
|
+
same(:manually_skipped, status.status)
|
51
64
|
end
|
52
65
|
|
53
|
-
|
54
|
-
|
55
|
-
|
66
|
+
suite "With a skipped assertion" do
|
67
|
+
suite "That is pending" do
|
68
|
+
assert "Has status :manually_skipped" do
|
69
|
+
assertion = ::BareTest::Assertion.new(nil, "", :skip => true)
|
70
|
+
status = assertion.execute
|
56
71
|
|
57
|
-
|
58
|
-
|
72
|
+
equal(:manually_skipped, status.status)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
suite "Given a test that succeeds" do
|
77
|
+
assert "Should have status :skipped" do
|
78
|
+
assertion = ::BareTest::Assertion.new(nil, "", :skip => true) do true end
|
79
|
+
status = assertion.execute
|
80
|
+
|
81
|
+
equal(:manually_skipped, status.status)
|
82
|
+
end
|
83
|
+
end
|
59
84
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
85
|
+
suite "Given a test that fails" do
|
86
|
+
assert "Should have status :skipped" do
|
87
|
+
assertion = ::BareTest::Assertion.new(nil, "", :skip => true) do false end
|
88
|
+
status = assertion.execute
|
89
|
+
|
90
|
+
equal(:manually_skipped, status.status)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
suite "Given a test that errors" do
|
95
|
+
assert "Should have status :skipped" do
|
96
|
+
assertion = ::BareTest::Assertion.new(nil, "", :skip => true) do raise "something" end
|
97
|
+
status = assertion.execute
|
98
|
+
|
99
|
+
equal(:manually_skipped, status.status)
|
100
|
+
end
|
101
|
+
end
|
64
102
|
end
|
65
|
-
end
|
103
|
+
end # '#execute'
|
66
104
|
|
67
|
-
suite
|
68
|
-
assert
|
105
|
+
suite 'meta information' do
|
106
|
+
assert 'An assertion should have a valid line number and file' do
|
69
107
|
suite = ::BareTest::Suite.new
|
70
108
|
assertion = suite.assert do true end
|
71
109
|
|
@@ -73,98 +111,70 @@ BareTest.suite "BareTest" do
|
|
73
111
|
end
|
74
112
|
end
|
75
113
|
|
76
|
-
suite
|
114
|
+
suite '#exception' do
|
77
115
|
assert "An assertion that doesn't raise should have nil as exception" do
|
78
|
-
|
79
|
-
|
80
|
-
same
|
116
|
+
assertion = ::BareTest::Assertion.new(nil, 'description') { true }
|
117
|
+
status = assertion.execute
|
118
|
+
same(nil, status.exception)
|
81
119
|
end
|
82
120
|
end
|
83
121
|
|
84
|
-
suite
|
85
|
-
assert
|
86
|
-
description =
|
122
|
+
suite '#description' do
|
123
|
+
assert 'An assertion should have a description' do
|
124
|
+
description = 'The assertion description'
|
87
125
|
assertion = ::BareTest::Assertion.new(nil, description) { true }
|
88
126
|
same :expected => description, :actual => assertion.description
|
89
127
|
end
|
90
128
|
end
|
91
129
|
|
92
|
-
suite
|
93
|
-
assert
|
130
|
+
suite '#suite' do
|
131
|
+
assert 'An assertion can belong to a suite' do
|
94
132
|
suite = ::BareTest::Suite.new
|
95
|
-
assertion = ::BareTest::Assertion.new(suite,
|
133
|
+
assertion = ::BareTest::Assertion.new(suite, '') { true }
|
96
134
|
same :expected => suite, :actual => assertion.suite
|
97
135
|
end
|
98
136
|
end
|
99
137
|
|
100
|
-
suite
|
101
|
-
assert
|
138
|
+
suite '#block' do
|
139
|
+
assert 'An assertion can have a block' do
|
102
140
|
block = proc { true }
|
103
|
-
assertion = ::BareTest::Assertion.new(nil,
|
141
|
+
assertion = ::BareTest::Assertion.new(nil, '', &block)
|
104
142
|
same :expected => block, :actual => assertion.block
|
105
143
|
end
|
106
144
|
end
|
107
145
|
|
108
|
-
suite
|
109
|
-
assert
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
146
|
+
suite '#setup' do
|
147
|
+
assert 'Fails if setup raises an exception' do
|
148
|
+
setup = proc { raise 'Some error' }
|
149
|
+
assertion = ::BareTest::Assertion.new(nil, 'assertion') do true end
|
150
|
+
status = assertion.execute([setup])
|
125
151
|
|
126
|
-
|
127
|
-
|
128
|
-
equal(:error, assertion.status, "assertion.status")
|
152
|
+
same(:error, status.status, 'status.status')
|
129
153
|
end
|
130
154
|
end
|
131
155
|
|
132
|
-
suite
|
133
|
-
assert
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
156
|
+
suite '#teardown' do
|
157
|
+
assert 'Fails if teardown raises an exception' do
|
158
|
+
teardown = proc { raise 'Some error' }
|
159
|
+
assertion = ::BareTest::Assertion.new(nil, 'assertion') do true end
|
160
|
+
status = assertion.execute(nil, [teardown])
|
151
161
|
|
152
|
-
|
162
|
+
same(:error, status.status, 'status.status')
|
153
163
|
end
|
154
164
|
end
|
155
165
|
|
156
|
-
suite
|
157
|
-
assert "
|
166
|
+
suite '#execute' do
|
167
|
+
assert "Runs the assertion's block" do
|
158
168
|
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,
|
169
|
+
assertion = ::BareTest::Assertion.new(nil, '') { this.touch(:execute) }
|
160
170
|
assertion.execute
|
161
171
|
touched(:execute)
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
165
|
-
suite
|
166
|
-
assert
|
167
|
-
description =
|
175
|
+
suite '#to_s' do
|
176
|
+
assert 'Assertion should have a to_s which contains the classname and the description' do
|
177
|
+
description = 'the description'
|
168
178
|
assertion = ::BareTest::Assertion.new(nil, description)
|
169
179
|
print_string = assertion.to_s
|
170
180
|
|
@@ -173,19 +183,30 @@ BareTest.suite "BareTest" do
|
|
173
183
|
end
|
174
184
|
end
|
175
185
|
|
176
|
-
suite
|
177
|
-
|
178
|
-
suite = ::BareTest::Suite.new
|
179
|
-
|
180
|
-
assertion = ::BareTest::Assertion.new(suite, description)
|
181
|
-
def suite.inspect; "<inspect of suite>"; end
|
186
|
+
suite '#inspect' do
|
187
|
+
setup do
|
188
|
+
@suite = ::BareTest::Suite.new
|
189
|
+
def @suite.inspect; '<inspect of suite>'; end
|
182
190
|
|
183
|
-
|
191
|
+
@description = 'the description'
|
192
|
+
@assertion = ::BareTest::Assertion.new(@suite, @description)
|
193
|
+
@inspect_string = @assertion.inspect
|
194
|
+
end
|
195
|
+
|
196
|
+
assert 'Should contain the classname' do
|
197
|
+
@inspect_string.include?(@assertion.class.name)
|
198
|
+
end
|
199
|
+
|
200
|
+
assert 'Should contain the shifted object-id in zero-padded hex' do
|
201
|
+
@inspect_string.include?('%08x' % (@assertion.object_id >> 1))
|
202
|
+
end
|
203
|
+
|
204
|
+
assert "Should contain the suite's inspect" do
|
205
|
+
@inspect_string.include?(@suite.inspect)
|
206
|
+
end
|
184
207
|
|
185
|
-
|
186
|
-
inspect_string.include?(
|
187
|
-
inspect_string.include?(suite.inspect) &&
|
188
|
-
inspect_string.include?(description.inspect)
|
208
|
+
assert "Should contain the description's inspect" do
|
209
|
+
@inspect_string.include?(@description.inspect)
|
189
210
|
end
|
190
211
|
end
|
191
212
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 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 "Context" do
|
12
|
+
suite "::new" do
|
13
|
+
suite "Expects 1 argument" do
|
14
|
+
assert "Raises ArgumentError with less than 1 argument" do
|
15
|
+
raises ArgumentError do BareTest::Assertion::Context.new end
|
16
|
+
end
|
17
|
+
|
18
|
+
assert "Returns a Context with 1 argument" do
|
19
|
+
kind_of BareTest::Assertion::Context, BareTest::Assertion::Context.new(Object.new)
|
20
|
+
end
|
21
|
+
|
22
|
+
assert "Raises ArgumentError with more than 1 argument" do
|
23
|
+
raises ArgumentError do BareTest::Assertion::Context.new(Object.new, Object.new) end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # ::new
|
27
|
+
|
28
|
+
suite "#__assertion__" do
|
29
|
+
setup do
|
30
|
+
@assertion = Object.new
|
31
|
+
@context = BareTest::Assertion::Context.new(@assertion)
|
32
|
+
end
|
33
|
+
|
34
|
+
assert "Returns the assertion the context was constructed with" do
|
35
|
+
same(@assertion, @context.__assertion__)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end # Context
|
39
|
+
end # Assertion
|
40
|
+
end # BareTest
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 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 "Failure" do
|
12
|
+
assert "Can be raised" do
|
13
|
+
raises BareTest::Assertion::Failure do
|
14
|
+
raise BareTest::Assertion::Failure, "raised"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end # Context
|
18
|
+
end # Assertion
|
19
|
+
end # BareTest
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 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 "Skip" do
|
12
|
+
assert "Can be raised" do
|
13
|
+
raises BareTest::Assertion::Skip do
|
14
|
+
raise BareTest::Assertion::Skip, "raised"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end # Context
|
18
|
+
end # Assertion
|
19
|
+
end # BareTest
|
@@ -6,50 +6,295 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
9
|
+
# FIXME: These tests are actually integration tests and not properly isolated
|
10
|
+
# (they depend on Assertion, Status and their own integration).
|
11
|
+
# Slated to be fixed in version 0.9
|
12
|
+
|
13
|
+
|
29
14
|
|
30
15
|
BareTest.suite "BareTest" do
|
31
16
|
suite "Assertion" do
|
32
17
|
suite "Support" do
|
18
|
+
suite "#yields" do
|
19
|
+
suite "If the expected values are yielded" do
|
20
|
+
setup do
|
21
|
+
@assertion = BareTest::Assertion.new nil, "test" do yields([1,2,3], :each, [], [1],[2],[3]) end
|
22
|
+
@status = @assertion.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
assert "Succeeds" do
|
26
|
+
same(:success, @status.status)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
suite "If different values than expected are yielded" do
|
31
|
+
setup do
|
32
|
+
@assertion = BareTest::Assertion.new nil, "test" do yields([1,2,3], :each, [], [2],[4],[8]) end
|
33
|
+
@status = @assertion.execute
|
34
|
+
end
|
35
|
+
|
36
|
+
assert "Fails" do
|
37
|
+
same(:failure, @status.status)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
suite "#throws" do
|
43
|
+
suite "If the expected symbol is thrown" do
|
44
|
+
setup do
|
45
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
46
|
+
throws :catchme do
|
47
|
+
throw :catchme
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@status = @assertion.execute
|
51
|
+
end
|
52
|
+
|
53
|
+
assert "Succeeds" do
|
54
|
+
same(:success, @status.status)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
suite "If a different symbol than the expected is thrown" do
|
59
|
+
setup do
|
60
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
61
|
+
throws :catchme do
|
62
|
+
throw :something_else
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@status = @assertion.execute
|
66
|
+
end
|
67
|
+
|
68
|
+
assert "Fails" do
|
69
|
+
same(:failure, @status.status)
|
70
|
+
end
|
71
|
+
|
72
|
+
assert "The message states what symbol was expected to be thrown and what was thrown instead" do
|
73
|
+
equal("Expected the code to throw :catchme, but it threw :something_else instead", @status.failure_reason)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
suite "If nothing is thrown" do
|
78
|
+
setup do
|
79
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
80
|
+
throws :catchme do
|
81
|
+
true # don't throw anything, just return
|
82
|
+
end
|
83
|
+
end
|
84
|
+
@status = @assertion.execute
|
85
|
+
end
|
86
|
+
|
87
|
+
assert "Fails" do
|
88
|
+
same(:failure, @status.status)
|
89
|
+
end
|
90
|
+
|
91
|
+
assert "The message states what symbol was expected to be thrown and that nothing was thrown instead" do
|
92
|
+
equal("Expected the code to throw :catchme, but nothing was thrown", @status.failure_reason)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
33
97
|
suite "#raises" do
|
34
|
-
|
35
|
-
|
98
|
+
suite "Used without an argument and a block that raises an exception" do
|
99
|
+
setup do
|
100
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
101
|
+
raises do
|
102
|
+
raise "foo"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
@status = @assertion.execute
|
106
|
+
end
|
107
|
+
|
108
|
+
assert "Succeeds" do
|
109
|
+
same(:success, @status.status)
|
110
|
+
end
|
36
111
|
end
|
37
112
|
|
38
|
-
|
39
|
-
|
113
|
+
suite "Used with an exception class as argument and a block that raises an exception of that class" do
|
114
|
+
setup do
|
115
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
116
|
+
raises(ArgumentError) do
|
117
|
+
raise ArgumentError, "foo"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
@status = @assertion.execute
|
121
|
+
end
|
122
|
+
|
123
|
+
assert "Succeeds" do
|
124
|
+
same(:success, @status.status)
|
125
|
+
end
|
40
126
|
end
|
41
127
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
128
|
+
suite "Used with an exception class and a message string as arguments and a block that raises an exception of that class with that message" do
|
129
|
+
setup do
|
130
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
131
|
+
raises(ArgumentError, "foo") do
|
132
|
+
raise ArgumentError, "foo"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
@status = @assertion.execute
|
136
|
+
end
|
137
|
+
|
138
|
+
assert "Succeeds" do
|
139
|
+
same(:success, @status.status)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
suite "Used with an exception class and a message regex as arguments and a block that raises an exception of that class with a matching message" do
|
144
|
+
setup do
|
145
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
146
|
+
raises(ArgumentError, /fo[aeiou]/) do
|
147
|
+
raise ArgumentError, "foo"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
@status = @assertion.execute
|
151
|
+
end
|
152
|
+
|
153
|
+
assert "Succeeds" do
|
154
|
+
same(:success, @status.status)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
suite "Used with an exception class as argument and a block that raises an exception that is a subclass of that class" do
|
159
|
+
setup do
|
160
|
+
@expected = StandardError
|
161
|
+
@actual = ArgumentError
|
162
|
+
expected = @expected
|
163
|
+
actual = @actual
|
164
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
165
|
+
raises(expected) do
|
166
|
+
raise actual, "foo"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
@status = @assertion.execute
|
170
|
+
end
|
171
|
+
|
172
|
+
guard "Actual exception class is a subclass of expected exception class" do
|
173
|
+
@actual < @expected
|
174
|
+
end
|
175
|
+
|
176
|
+
assert "Fails" do
|
177
|
+
same(:failure, @status.status)
|
178
|
+
end
|
179
|
+
|
180
|
+
assert "The message states what exception-class was expected to be raised and what was raised instead" do
|
181
|
+
equal("Expected the code to raise #{@expected.name}, but it raised #{@actual.name} instead", @status.failure_reason)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
suite "Used with an exception class as argument and a block that raises an exception that is of a different class" do
|
186
|
+
setup do
|
187
|
+
@expected = expected = NameError
|
188
|
+
@actual = actual = ArgumentError
|
189
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
190
|
+
raises(expected) do
|
191
|
+
raise actual, "foo"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
@status = @assertion.execute
|
195
|
+
end
|
196
|
+
|
197
|
+
guard "Actual exception class is a different class than expected exception class" do
|
198
|
+
(@actual <=> @expected).nil?
|
199
|
+
end
|
200
|
+
|
201
|
+
assert "Fails" do
|
202
|
+
same(:failure, @status.status)
|
203
|
+
end
|
204
|
+
|
205
|
+
assert "The message states what message was expected to be raised and what was raised instead" do
|
206
|
+
equal("Expected the code to raise #{@expected.name}, but it raised #{@actual.name} instead", @status.failure_reason)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
suite "Used with an exception class and a message string as arguments and a block that raises an exception of that class but with a different message" do
|
211
|
+
setup do
|
212
|
+
@expected_message = expected_message = "foo"
|
213
|
+
@actual_message = actual_message = "bar"
|
214
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
215
|
+
raises(ArgumentError, expected_message) do
|
216
|
+
raise ArgumentError, actual_message
|
217
|
+
end
|
218
|
+
end
|
219
|
+
@status = @assertion.execute
|
220
|
+
end
|
221
|
+
|
222
|
+
assert "Fails" do
|
223
|
+
same(:failure, @status.status)
|
224
|
+
end
|
225
|
+
|
226
|
+
assert "The message states what exception-class was expected to be raised and what was raised instead" do
|
227
|
+
equal(
|
228
|
+
"Expected the code to raise with the message #{@expected_message.inspect}, but the message was #{@actual_message.inspect}",
|
229
|
+
@status.failure_reason
|
230
|
+
)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
suite "Used with an exception class and a message regex as arguments and a block that raises an exception of that class with a different message" do
|
235
|
+
setup do
|
236
|
+
@expected_message = expected_message = /fo[aeiou]/
|
237
|
+
@actual_message = actual_message = "bar"
|
238
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
239
|
+
raises(ArgumentError, expected_message) do
|
240
|
+
raise ArgumentError, actual_message
|
241
|
+
end
|
242
|
+
end
|
243
|
+
@status = @assertion.execute
|
244
|
+
end
|
245
|
+
|
246
|
+
assert "Fails" do
|
247
|
+
same(:failure, @status.status)
|
248
|
+
end
|
249
|
+
|
250
|
+
assert "The message states what exception-class was expected to be raised and what was raised instead" do
|
251
|
+
equal(
|
252
|
+
"Expected the code to raise with the message #{@expected_message.inspect}, but the message was #{@actual_message.inspect}",
|
253
|
+
@status.failure_reason
|
254
|
+
)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
suite "Used without argument and a block that doesn't raise" do
|
259
|
+
setup do
|
260
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
261
|
+
raises do
|
262
|
+
"nothing raised -> should fail"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
@status = @assertion.execute
|
266
|
+
end
|
267
|
+
|
268
|
+
assert "Fails" do
|
269
|
+
same(:failure, @status.status)
|
270
|
+
end
|
271
|
+
|
272
|
+
assert "The message states what exception-class was expected to be raised and what was raised instead" do
|
273
|
+
equal("Expected the code to raise, but nothing was raised", @status.failure_reason)
|
49
274
|
end
|
50
275
|
end
|
51
276
|
|
52
|
-
|
277
|
+
suite "Used with an exception class as argument and a block that doesn't raise" do
|
278
|
+
setup do
|
279
|
+
@expected = expected = ArgumentError
|
280
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
281
|
+
raises(ArgumentError) do
|
282
|
+
"nothing raised -> should fail"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
@status = @assertion.execute
|
286
|
+
end
|
287
|
+
|
288
|
+
assert "Fails" do
|
289
|
+
same(:failure, @status.status)
|
290
|
+
end
|
291
|
+
|
292
|
+
assert "The message states what exception-class was expected to be raised and that nothing was raised instead" do
|
293
|
+
equal("Expected the code to raise ArgumentError, but nothing was raised", @status.failure_reason)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
assert "Should fail when the block raises an exception not derived from the provided exception-class" do
|
53
298
|
begin
|
54
299
|
raises(TypeError) do raise ArgumentError, "different class -> should fail" end
|
55
300
|
rescue ::BareTest::Assertion::Failure
|
@@ -61,17 +306,37 @@ BareTest.suite "BareTest" do
|
|
61
306
|
end # raises
|
62
307
|
|
63
308
|
suite "#raises_nothing" do
|
64
|
-
|
65
|
-
|
309
|
+
suite "Used with a block that doesn't raise" do
|
310
|
+
setup do
|
311
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
312
|
+
raises_nothing do
|
313
|
+
"nothing raised -> should succeed"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
@status = @assertion.execute
|
317
|
+
end
|
318
|
+
|
319
|
+
assert "Succeeds" do
|
320
|
+
same(:success, @status.status)
|
321
|
+
end
|
66
322
|
end
|
67
323
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
324
|
+
suite "Used with a block that raises" do
|
325
|
+
setup do
|
326
|
+
@assertion = BareTest::Assertion.new nil, "test" do
|
327
|
+
raises_nothing do
|
328
|
+
raise "Something"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
@status = @assertion.execute
|
332
|
+
end
|
333
|
+
|
334
|
+
assert "Fails" do
|
335
|
+
same(:failure, @status.status)
|
336
|
+
end
|
337
|
+
|
338
|
+
assert "The message states that it was not expected to raise anything but that something was raised" do
|
339
|
+
equal("Expected the code to raise nothing, but it raised RuntimeError (Something)", @status.failure_reason)
|
75
340
|
end
|
76
341
|
end
|
77
342
|
end
|
@@ -79,13 +344,13 @@ BareTest.suite "BareTest" do
|
|
79
344
|
suite "#touch/#touched" do
|
80
345
|
suite "When you don't touch(x), touched(x) should fail" do
|
81
346
|
assert "When you don't touch at all, touched(x) should fail" do
|
82
|
-
|
347
|
+
raises ::BareTest::Assertion::Failure do
|
83
348
|
touched :foo1
|
84
349
|
end
|
85
350
|
end
|
86
351
|
|
87
352
|
assert "When you don't touch something else, touched(x) should fail" do
|
88
|
-
|
353
|
+
raises ::BareTest::Assertion::Failure do
|
89
354
|
touch :bar2
|
90
355
|
touched :foo2
|
91
356
|
end
|
@@ -109,68 +374,68 @@ BareTest.suite "BareTest" do
|
|
109
374
|
touch(:foo5)
|
110
375
|
end
|
111
376
|
|
112
|
-
assert "No touch x, touched x should raise
|
113
|
-
|
377
|
+
assert "No touch x, touched x should raise" do
|
378
|
+
raises ::BareTest::Assertion::Failure do touched(:foo5) end
|
114
379
|
end
|
115
380
|
end
|
116
381
|
end # #touch/#touched
|
117
382
|
|
118
383
|
suite "#within_delta" do
|
119
|
-
assert "Should not fail when the value is within the delta
|
384
|
+
assert "Should not fail when the value is within the delta" do
|
120
385
|
within_delta(3.0, 3.01, 0.02)
|
121
386
|
end
|
122
387
|
|
123
|
-
assert "Should fail when the value is not within the delta
|
124
|
-
|
388
|
+
assert "Should fail when the value is not within the delta" do
|
389
|
+
raises ::BareTest::Assertion::Failure do
|
125
390
|
within_delta(3.0, 3.03, 0.02)
|
126
391
|
end
|
127
392
|
end
|
128
393
|
|
129
|
-
assert "Should fail with invalid input
|
130
|
-
|
394
|
+
assert "Should fail with invalid input" do
|
395
|
+
raises ::BareTest::Assertion::Failure do
|
131
396
|
within_delta(nil, nil, 0.02)
|
132
397
|
end
|
133
398
|
end
|
134
399
|
end # within_delta
|
135
400
|
|
136
401
|
suite "#equal_unordered" do
|
137
|
-
assert "Should not fail when the two arrays contain the same items the same number of times
|
402
|
+
assert "Should not fail when the two arrays contain the same items the same number of times" do
|
138
403
|
equal_unordered([1,2,3], [3,1,2])
|
139
404
|
end
|
140
405
|
|
141
|
-
assert "Should fail when the two arrays don't contain the same items
|
142
|
-
|
406
|
+
assert "Should fail when the two arrays don't contain the same items" do
|
407
|
+
raises ::BareTest::Assertion::Failure do
|
143
408
|
equal_unordered([1,2,3], [5,6,1])
|
144
409
|
end
|
145
410
|
end
|
146
411
|
|
147
|
-
assert "Should fail when the two arrays contain the same items a different number of times
|
148
|
-
|
412
|
+
assert "Should fail when the two arrays contain the same items a different number of times" do
|
413
|
+
raises ::BareTest::Assertion::Failure do
|
149
414
|
equal_unordered([1,2,3], [3,1,2,2])
|
150
415
|
end
|
151
416
|
end
|
152
417
|
|
153
|
-
assert "Should fail with invalid input
|
154
|
-
|
418
|
+
assert "Should fail with invalid input" do
|
419
|
+
raises ::BareTest::Assertion::Failure do
|
155
420
|
equal_unordered(nil, nil)
|
156
421
|
end
|
157
422
|
end
|
158
423
|
end # equal_unordered
|
159
424
|
|
160
425
|
suite "#same" do
|
161
|
-
assert "Should not fail when the values are the same object
|
426
|
+
assert "Should not fail when the values are the same object" do
|
162
427
|
a = "foo"
|
163
428
|
same(a, a)
|
164
429
|
end
|
165
430
|
|
166
|
-
assert "Should fail when the values are not the same object
|
167
|
-
|
431
|
+
assert "Should fail when the values are not the same object" do
|
432
|
+
raises ::BareTest::Assertion::Failure do
|
168
433
|
same("a", "b")
|
169
434
|
end
|
170
435
|
end
|
171
436
|
|
172
|
-
assert "Should fail with invalid input
|
173
|
-
|
437
|
+
assert "Should fail with invalid input" do
|
438
|
+
raises ::BareTest::Assertion::Failure do
|
174
439
|
x = Class.new do undef equal? end # really, who does that?
|
175
440
|
y = x.new
|
176
441
|
equal_unordered(y, y)
|
@@ -179,18 +444,18 @@ BareTest.suite "BareTest" do
|
|
179
444
|
end # same
|
180
445
|
|
181
446
|
suite "#order_equal" do
|
182
|
-
assert "Should not fail when the values are equal by
|
447
|
+
assert "Should not fail when the values are equal by ==" do
|
183
448
|
order_equal(1, 1.0)
|
184
449
|
end
|
185
450
|
|
186
|
-
assert "Should fail when the values are not equal by
|
187
|
-
|
451
|
+
assert "Should fail when the values are not equal by ==" do
|
452
|
+
raises ::BareTest::Assertion::Failure do
|
188
453
|
order_equal(1, 1.1)
|
189
454
|
end
|
190
455
|
end
|
191
456
|
|
192
|
-
assert "Should fail with invalid input
|
193
|
-
|
457
|
+
assert "Should fail with invalid input" do
|
458
|
+
raises ::BareTest::Assertion::Failure do
|
194
459
|
x = Class.new do undef == end
|
195
460
|
y = x.new
|
196
461
|
order_equal(y, y)
|
@@ -199,18 +464,18 @@ BareTest.suite "BareTest" do
|
|
199
464
|
end # order_equal
|
200
465
|
|
201
466
|
suite "#hash_key_equal" do
|
202
|
-
assert "Should not fail when the values are the same object
|
467
|
+
assert "Should not fail when the values are the same object" do
|
203
468
|
hash_key_equal("foo", "foo")
|
204
469
|
end
|
205
470
|
|
206
|
-
assert "Should fail when the values are not the same object
|
207
|
-
|
471
|
+
assert "Should fail when the values are not the same object" do
|
472
|
+
raises ::BareTest::Assertion::Failure do
|
208
473
|
hash_key_equal("foo", "bar")
|
209
474
|
end
|
210
475
|
end
|
211
476
|
|
212
|
-
assert "Should fail with invalid input
|
213
|
-
|
477
|
+
assert "Should fail with invalid input" do
|
478
|
+
raises ::BareTest::Assertion::Failure do
|
214
479
|
x = Class.new do undef eql? end
|
215
480
|
y = x.new
|
216
481
|
hash_key_equal(y, y)
|
@@ -219,18 +484,18 @@ BareTest.suite "BareTest" do
|
|
219
484
|
end # hash_key_equal
|
220
485
|
|
221
486
|
suite "#case_equal" do
|
222
|
-
assert "Should not fail when the values are the same object
|
487
|
+
assert "Should not fail when the values are the same object" do
|
223
488
|
case_equal(String, "foo")
|
224
489
|
end
|
225
490
|
|
226
|
-
assert "Should fail when the values are not the same object
|
227
|
-
|
491
|
+
assert "Should fail when the values are not the same object" do
|
492
|
+
raises ::BareTest::Assertion::Failure do
|
228
493
|
case_equal(String, [])
|
229
494
|
end
|
230
495
|
end
|
231
496
|
|
232
|
-
assert "Should fail with invalid input
|
233
|
-
|
497
|
+
assert "Should fail with invalid input" do
|
498
|
+
raises ::BareTest::Assertion::Failure do
|
234
499
|
x = Class.new do undef === end
|
235
500
|
y = x.new
|
236
501
|
case_equal(y, y)
|
@@ -248,12 +513,29 @@ BareTest.suite "BareTest" do
|
|
248
513
|
end
|
249
514
|
|
250
515
|
assert "Should fail when the value is not instance of the given class or subclass" do
|
251
|
-
|
516
|
+
raises ::BareTest::Assertion::Failure do
|
252
517
|
kind_of(String, [])
|
253
518
|
end
|
254
519
|
end
|
255
520
|
end
|
256
521
|
|
522
|
+
suite "#respond_to" do
|
523
|
+
assert "Should not fail when the object responds to all methods required" do
|
524
|
+
obj = Object.new
|
525
|
+
def obj.foo; end
|
526
|
+
def obj.bar; end
|
527
|
+
respond_to(obj, :foo, :bar)
|
528
|
+
end
|
529
|
+
|
530
|
+
assert "Should fail when the object doesn't respond to all methods required" do
|
531
|
+
raises ::BareTest::Assertion::Failure do
|
532
|
+
obj = Object.new
|
533
|
+
def obj.foo; end
|
534
|
+
respond_to(obj, :foo, :bar)
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
257
539
|
suite "#failure_with_optional_message" do
|
258
540
|
assert "Should raise a BareTest::Assertion::Failure" do
|
259
541
|
raises(::BareTest::Assertion::Failure) do
|
@@ -262,30 +544,30 @@ BareTest.suite "BareTest" do
|
|
262
544
|
end
|
263
545
|
|
264
546
|
assert "Should use the string with message if message is given" do
|
265
|
-
raises(::BareTest::Assertion::Failure,
|
547
|
+
raises(::BareTest::Assertion::Failure, "With message") do
|
266
548
|
failure_with_optional_message "With %s", "Without message", "message"
|
267
549
|
end
|
268
550
|
end
|
269
551
|
|
270
552
|
assert "Should use the string without message if no message is given" do
|
271
|
-
raises(::BareTest::Assertion::Failure,
|
553
|
+
raises(::BareTest::Assertion::Failure, "Without message") do
|
272
554
|
failure_with_optional_message "With %s", "Without message", nil
|
273
555
|
end
|
274
556
|
end
|
275
557
|
end
|
276
558
|
|
277
559
|
suite "#failure" do
|
278
|
-
assert "Should raise a BareTest::Assertion::Failure
|
560
|
+
assert "Should raise a BareTest::Assertion::Failure" do
|
279
561
|
raises(::BareTest::Assertion::Failure) do
|
280
|
-
failure "Should raise that exception
|
562
|
+
failure "Should raise that exception"
|
281
563
|
end
|
282
564
|
end
|
283
565
|
end
|
284
566
|
|
285
567
|
suite "#skip" do
|
286
|
-
assert "Should raise a BareTest::Assertion::Skip
|
568
|
+
assert "Should raise a BareTest::Assertion::Skip" do
|
287
569
|
raises(::BareTest::Assertion::Skip) do
|
288
|
-
skip "Should raise that exception
|
570
|
+
skip "Should raise that exception"
|
289
571
|
end
|
290
572
|
end
|
291
573
|
end
|