assert 2.16.5 → 2.18.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.
- checksums.yaml +7 -7
- data/Gemfile +3 -1
- data/README.md +79 -54
- data/assert.gemspec +6 -5
- data/bin/assert +4 -4
- data/lib/assert.rb +8 -18
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +7 -10
- data/lib/assert/assertions.rb +15 -28
- data/lib/assert/cli.rb +41 -57
- data/lib/assert/config.rb +8 -12
- data/lib/assert/config_helpers.rb +6 -10
- data/lib/assert/context.rb +30 -24
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +0 -4
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +5 -9
- data/lib/assert/context_info.rb +2 -6
- data/lib/assert/default_runner.rb +1 -5
- data/lib/assert/default_suite.rb +1 -6
- data/lib/assert/default_view.rb +8 -12
- data/lib/assert/factory.rb +1 -4
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +1 -4
- data/lib/assert/macros/methods.rb +5 -11
- data/lib/assert/result.rb +19 -34
- data/lib/assert/runner.rb +12 -11
- data/lib/assert/stub.rb +16 -2
- data/lib/assert/suite.rb +3 -7
- data/lib/assert/test.rb +13 -18
- data/lib/assert/utils.rb +8 -12
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +18 -21
- data/lib/assert/view_helpers.rb +6 -17
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +26 -41
- data/test/support/factory.rb +20 -6
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +350 -354
- data/test/system/test_tests.rb +119 -133
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +125 -52
- data/test/unit/assertions/assert_block_tests.rb +34 -37
- data/test/unit/assertions/assert_empty_tests.rb +38 -38
- data/test/unit/assertions/assert_equal_tests.rb +84 -86
- data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
- data/test/unit/assertions/assert_includes_tests.rb +45 -46
- data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
- data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
- data/test/unit/assertions/assert_match_tests.rb +39 -40
- data/test/unit/assertions/assert_nil_tests.rb +35 -38
- data/test/unit/assertions/assert_raises_tests.rb +58 -62
- data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
- data/test/unit/assertions/assert_same_tests.rb +94 -90
- data/test/unit/assertions/assert_true_false_tests.rb +67 -69
- data/test/unit/assertions_tests.rb +17 -19
- data/test/unit/config_helpers_tests.rb +41 -43
- data/test/unit/config_tests.rb +42 -46
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +72 -91
- data/test/unit/context/subject_dsl_tests.rb +18 -51
- data/test/unit/context/suite_dsl_tests.rb +19 -23
- data/test/unit/context/test_dsl_tests.rb +52 -59
- data/test/unit/context_info_tests.rb +19 -21
- data/test/unit/context_tests.rb +175 -178
- data/test/unit/default_runner_tests.rb +4 -10
- data/test/unit/default_suite_tests.rb +54 -59
- data/test/unit/factory_tests.rb +6 -9
- data/test/unit/file_line_tests.rb +34 -40
- data/test/unit/macro_tests.rb +11 -20
- data/test/unit/result_tests.rb +156 -182
- data/test/unit/runner_tests.rb +72 -79
- data/test/unit/suite_tests.rb +62 -63
- data/test/unit/test_tests.rb +143 -147
- data/test/unit/utils_tests.rb +49 -62
- data/test/unit/view_helpers_tests.rb +67 -70
- data/test/unit/view_tests.rb +26 -32
- metadata +54 -47
- data/.assert.rb +0 -3
- data/.gitignore +0 -19
@@ -1,55 +1,53 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "assert/context_info"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "assert/context"
|
5
5
|
|
6
6
|
class Assert::ContextInfo
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Assert::ContextInfo"
|
10
9
|
setup do
|
11
10
|
@caller = caller
|
12
|
-
@klass = Assert::Context
|
13
|
-
@info = Assert::ContextInfo.new(@klass, nil, @caller.first)
|
14
11
|
end
|
15
|
-
subject{
|
12
|
+
subject { info1 }
|
13
|
+
|
14
|
+
let(:context1) { Assert::Context }
|
15
|
+
let(:info1) { Assert::ContextInfo.new(context1, nil, @caller.first) }
|
16
16
|
|
17
17
|
should have_readers :called_from, :klass, :file
|
18
18
|
should have_imeths :test_name
|
19
19
|
|
20
20
|
should "set its klass on init" do
|
21
|
-
|
21
|
+
assert_that(subject.klass).equals(context1)
|
22
22
|
end
|
23
23
|
|
24
24
|
should "set its called_from to the called_from or first caller on init" do
|
25
|
-
info = Assert::ContextInfo.new(
|
26
|
-
|
25
|
+
info = Assert::ContextInfo.new(context1, @caller.first, nil)
|
26
|
+
assert_that(info.called_from).equals(@caller.first)
|
27
27
|
|
28
|
-
info = Assert::ContextInfo.new(
|
29
|
-
|
28
|
+
info = Assert::ContextInfo.new(context1, nil, @caller.first)
|
29
|
+
assert_that(info.called_from).equals(@caller.first)
|
30
30
|
end
|
31
31
|
|
32
32
|
should "set its file from caller info on init" do
|
33
|
-
|
33
|
+
assert_that(subject.file).equals(@caller.first.gsub(/\:[0-9]+.*$/, ""))
|
34
34
|
end
|
35
35
|
|
36
36
|
should "not have any file info if no caller is given" do
|
37
|
-
info = Assert::ContextInfo.new(
|
38
|
-
|
37
|
+
info = Assert::ContextInfo.new(context1)
|
38
|
+
assert_that(info.file).is_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
should "know how to build the contextual test name for a given name" do
|
42
42
|
desc = Factory.string
|
43
43
|
name = Factory.string
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
assert_that(subject.test_name(name)).equals(name)
|
46
|
+
assert_that(subject.test_name("")).equals("")
|
47
|
+
assert_that(subject.test_name(nil)).equals("")
|
48
48
|
|
49
49
|
Assert.stub(subject.klass, :description){ desc }
|
50
|
-
|
50
|
+
assert_that(subject.test_name(name)).equals("#{desc} #{name}")
|
51
51
|
end
|
52
|
-
|
53
52
|
end
|
54
|
-
|
55
53
|
end
|
data/test/unit/context_tests.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "assert/context"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "assert/config"
|
5
|
+
require "assert/result"
|
6
|
+
require "assert/utils"
|
7
7
|
|
8
8
|
class Assert::Context
|
9
|
-
|
10
9
|
class UnitTests < Assert::Context
|
11
10
|
desc "Assert::Context"
|
11
|
+
subject { context1 }
|
12
|
+
|
12
13
|
setup do
|
13
|
-
@test = Factory.test
|
14
|
-
@context_class = @test.context_class
|
15
14
|
@callback_result = nil
|
16
|
-
@test_results = []
|
17
|
-
@result_callback = proc do |result|
|
18
|
-
@callback_result = result
|
19
|
-
@test_results << result
|
20
|
-
end
|
21
|
-
@context = @context_class.new(@test, @test.config, @result_callback)
|
22
15
|
end
|
23
|
-
|
16
|
+
|
17
|
+
let(:test1) { Factory.test }
|
18
|
+
let(:context_class1) { test1.context_class }
|
19
|
+
let(:test_results1) { [] }
|
20
|
+
let(:result_callback1) {
|
21
|
+
proc { |result| @callback_result = result; test_results1 << result }
|
22
|
+
}
|
23
|
+
let(:context1) { context_class1.new(test1, test1.config, result_callback1) }
|
24
|
+
let(:halt_config1) { Assert::Config.new(:halt_on_fail => true) }
|
25
|
+
let(:msg1) { Factory.string }
|
24
26
|
|
25
27
|
# DSL methods
|
26
|
-
should have_cmeths :description, :desc, :describe, :subject, :suite
|
28
|
+
should have_cmeths :description, :desc, :describe, :subject, :suite, :let
|
27
29
|
should have_cmeths :setup_once, :before_once, :startup
|
28
30
|
should have_cmeths :teardown_once, :after_once, :shutdown
|
29
31
|
should have_cmeths :setup, :before, :setups, :run_setups
|
@@ -32,385 +34,380 @@ class Assert::Context
|
|
32
34
|
should have_cmeths :test, :test_eventually, :test_skip
|
33
35
|
should have_cmeths :should, :should_eventually, :should_skip
|
34
36
|
|
35
|
-
should have_imeths :assert, :assert_not, :refute
|
37
|
+
should have_imeths :assert, :assert_not, :refute, :assert_that
|
36
38
|
should have_imeths :pass, :ignore, :fail, :flunk, :skip
|
37
39
|
should have_imeths :pending, :with_backtrace, :subject
|
38
40
|
|
39
41
|
should "collect context info" do
|
40
42
|
test = @__assert_running_test__
|
41
|
-
|
42
|
-
|
43
|
+
assert_that(test.context_info.file).matches(/test\/unit\/context_tests.rb$/)
|
44
|
+
assert_that(test.context_info.klass).equals(self.class)
|
43
45
|
end
|
46
|
+
|
44
47
|
private
|
45
48
|
|
46
|
-
ASSERT_TEST_PATH_REGEX = /\A#{File.join(ROOT_PATH,
|
49
|
+
ASSERT_TEST_PATH_REGEX = /\A#{File.join(ROOT_PATH, "test", "")}/
|
47
50
|
|
48
51
|
def assert_with_bt_set(exp_with_bt, result)
|
49
52
|
with_backtrace(caller) do
|
50
|
-
|
53
|
+
assert_that(result.with_bt_set?).is_true
|
51
54
|
|
52
55
|
exp = Assert::Result::Backtrace.to_s(exp_with_bt+[(result.backtrace.filtered.first)])
|
53
|
-
|
54
|
-
|
56
|
+
assert_that(result.trace).equals(exp)
|
57
|
+
assert_that(result.src_line).equals(exp_with_bt.first)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
def assert_not_with_bt_set(result)
|
59
62
|
with_backtrace(caller) do
|
60
|
-
|
63
|
+
assert_that(result.with_bt_set?).is_false
|
61
64
|
|
62
|
-
|
63
|
-
|
65
|
+
assert_that(result.trace).equals(result.src_line)
|
66
|
+
assert_that(result.src_line).equals(result.backtrace.filtered.first.to_s)
|
64
67
|
end
|
65
68
|
end
|
66
|
-
|
67
69
|
end
|
68
70
|
|
69
71
|
class SkipTests < UnitTests
|
70
72
|
desc "skip method"
|
73
|
+
subject { @result }
|
74
|
+
|
71
75
|
setup do
|
72
|
-
|
73
|
-
begin; @context.skip(@skip_msg); rescue StandardError => @exception; end
|
76
|
+
begin; context1.skip(msg1); rescue StandardError => @exception; end
|
74
77
|
@result = Factory.skip_result(@exception)
|
75
78
|
end
|
76
|
-
subject{ @result }
|
77
79
|
|
78
80
|
should "raise a test skipped exception and set its message" do
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
assert_that(@exception).is_kind_of(Assert::Result::TestSkipped)
|
82
|
+
assert_that(@exception.message).equals(msg1)
|
83
|
+
assert_that(subject.message).equals(msg1)
|
82
84
|
end
|
83
85
|
|
84
86
|
should "not call the result callback" do
|
85
|
-
|
87
|
+
assert_that(@callback_result).is_nil
|
86
88
|
end
|
87
89
|
|
88
90
|
should "use any given called from arg as the exception backtrace" do
|
89
|
-
|
91
|
+
assert_that(@exception.backtrace.size).does_not_equal(1)
|
90
92
|
|
91
93
|
called_from = Factory.string
|
92
|
-
begin;
|
93
|
-
|
94
|
-
|
94
|
+
begin; context1.skip(msg1, called_from); rescue StandardError => exception; end
|
95
|
+
assert_that(exception.backtrace.size).equals(1)
|
96
|
+
assert_that(exception.backtrace.first).equals(called_from)
|
95
97
|
end
|
96
|
-
|
97
98
|
end
|
98
99
|
|
99
100
|
class IgnoreTests < UnitTests
|
100
101
|
desc "ignore method"
|
102
|
+
subject { @result }
|
103
|
+
|
101
104
|
setup do
|
102
|
-
@
|
103
|
-
@result = @context.ignore(@ignore_msg)
|
105
|
+
@result = context1.ignore(msg1)
|
104
106
|
end
|
105
|
-
subject{ @result }
|
106
107
|
|
107
108
|
should "create an ignore result and set its message" do
|
108
|
-
|
109
|
-
|
109
|
+
assert_that(subject).is_kind_of(Assert::Result::Ignore)
|
110
|
+
assert_that(subject.message).equals(msg1)
|
110
111
|
end
|
111
112
|
|
112
113
|
should "call the result callback" do
|
113
|
-
|
114
|
+
assert_that(@callback_result).equals(@result)
|
114
115
|
end
|
115
|
-
|
116
116
|
end
|
117
117
|
|
118
118
|
class PassTests < UnitTests
|
119
119
|
desc "pass method"
|
120
|
+
subject { @result }
|
121
|
+
|
120
122
|
setup do
|
121
|
-
@
|
122
|
-
@result = @context.pass(@pass_msg)
|
123
|
+
@result = context1.pass(msg1)
|
123
124
|
end
|
124
|
-
subject{ @result }
|
125
125
|
|
126
126
|
should "create a pass result and set its message" do
|
127
|
-
|
128
|
-
|
127
|
+
assert_that(subject).is_kind_of(Assert::Result::Pass)
|
128
|
+
assert_that(subject.message).equals(msg1)
|
129
129
|
end
|
130
130
|
|
131
131
|
should "call the result callback" do
|
132
|
-
|
132
|
+
assert_that(@callback_result).equals(@result)
|
133
133
|
end
|
134
|
-
|
135
134
|
end
|
136
135
|
|
137
136
|
class FlunkTests < UnitTests
|
138
137
|
desc "flunk method"
|
138
|
+
subject { @result }
|
139
|
+
|
139
140
|
setup do
|
140
|
-
@
|
141
|
-
@result = @context.flunk(@flunk_msg)
|
141
|
+
@result = context1.flunk(msg1)
|
142
142
|
end
|
143
|
-
subject{ @result }
|
144
143
|
|
145
144
|
should "create a fail result and set its message" do
|
146
|
-
|
147
|
-
|
145
|
+
assert_that(subject).is_kind_of(Assert::Result::Fail)
|
146
|
+
assert_that(subject.message).equals(msg1)
|
148
147
|
end
|
149
148
|
|
150
149
|
should "call the result callback" do
|
151
|
-
|
150
|
+
assert_that(@callback_result).equals(@result)
|
152
151
|
end
|
153
|
-
|
154
152
|
end
|
155
153
|
|
156
154
|
class FailTests < UnitTests
|
157
155
|
desc "fail method"
|
156
|
+
subject { @result }
|
157
|
+
|
158
158
|
setup do
|
159
|
-
@result =
|
159
|
+
@result = context1.fail
|
160
160
|
end
|
161
|
-
subject{ @result }
|
162
161
|
|
163
162
|
should "create a fail result and set its backtrace" do
|
164
|
-
|
165
|
-
|
166
|
-
|
163
|
+
assert_that(subject).is_kind_of(Assert::Result::Fail)
|
164
|
+
assert_that(subject.trace).equals(subject.backtrace.filtered.first.to_s)
|
165
|
+
assert_that(subject.backtrace).is_kind_of(Array)
|
167
166
|
end
|
168
167
|
|
169
168
|
should "set any given result message" do
|
170
|
-
|
171
|
-
result
|
172
|
-
assert_equal fail_msg, result.message
|
169
|
+
result = context1.fail(msg1)
|
170
|
+
assert_that(result.message).equals(msg1)
|
173
171
|
end
|
174
172
|
|
175
173
|
should "call the result callback" do
|
176
|
-
|
174
|
+
assert_that(@callback_result).equals(@result)
|
177
175
|
end
|
178
|
-
|
179
176
|
end
|
180
177
|
|
181
178
|
class HaltOnFailTests < UnitTests
|
182
179
|
desc "failing when halting on fails"
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
@fail_msg = "something failed"
|
187
|
-
end
|
188
|
-
subject{ @result }
|
180
|
+
subject { @result }
|
181
|
+
|
182
|
+
let(:context1) { context_class1.new(test1, halt_config1, result_callback1) }
|
189
183
|
|
190
184
|
should "raise an exception with the failure's message" do
|
191
|
-
begin;
|
192
|
-
|
193
|
-
|
185
|
+
begin; context1.fail(msg1); rescue StandardError => err; end
|
186
|
+
assert_that(err).is_kind_of(Assert::Result::TestFailure)
|
187
|
+
assert_that(err.message).equals(msg1)
|
194
188
|
|
195
189
|
result = Assert::Result::Fail.for_test(Factory.test("something"), err)
|
196
|
-
|
190
|
+
assert_that(result.message).equals(msg1)
|
197
191
|
end
|
198
192
|
|
199
193
|
should "not call the result callback" do
|
200
|
-
|
194
|
+
assert_that(@callback_result).is_nil
|
201
195
|
end
|
202
|
-
|
203
196
|
end
|
204
197
|
|
205
198
|
class AssertTests < UnitTests
|
206
199
|
desc "assert method"
|
207
|
-
|
208
|
-
|
209
|
-
@what_failed = "what failed"
|
210
|
-
end
|
200
|
+
|
201
|
+
let(:what_failed) { Factory.string }
|
211
202
|
|
212
203
|
should "return a pass result given a `true` assertion" do
|
213
|
-
result = subject.assert(true,
|
214
|
-
|
215
|
-
|
204
|
+
result = subject.assert(true, msg1){ what_failed }
|
205
|
+
assert_that(result).is_kind_of(Assert::Result::Pass)
|
206
|
+
assert_that(result.message).equals("")
|
216
207
|
end
|
217
208
|
|
218
209
|
should "return a fail result given a `false` assertion" do
|
219
|
-
result = subject.assert(false,
|
220
|
-
|
210
|
+
result = subject.assert(false, msg1){ what_failed }
|
211
|
+
assert_that(result).is_kind_of(Assert::Result::Fail)
|
221
212
|
end
|
222
213
|
|
223
214
|
should "pp the assertion value in the fail message by default" do
|
224
|
-
exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false,
|
225
|
-
result = subject.assert(false,
|
215
|
+
exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
|
216
|
+
result = subject.assert(false, msg1)
|
226
217
|
|
227
|
-
|
218
|
+
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
228
219
|
end
|
229
220
|
|
230
221
|
should "use a custom fail message if one is given" do
|
231
|
-
result = subject.assert(false,
|
232
|
-
|
222
|
+
result = subject.assert(false, msg1){ what_failed }
|
223
|
+
assert_that(result.message).equals([msg1, what_failed].join("\n"))
|
233
224
|
end
|
234
225
|
|
235
226
|
should "return a pass result given a \"truthy\" assertion" do
|
236
|
-
|
227
|
+
assert_that(subject.assert(34)).is_kind_of(Assert::Result::Pass)
|
237
228
|
end
|
238
229
|
|
239
230
|
should "return a fail result gievn a `nil` assertion" do
|
240
|
-
|
231
|
+
assert_that(subject.assert(nil)).is_kind_of(Assert::Result::Fail)
|
241
232
|
end
|
242
|
-
|
243
233
|
end
|
244
234
|
|
245
235
|
class AssertNotTests < UnitTests
|
246
236
|
desc "assert_not method"
|
247
|
-
setup do
|
248
|
-
@fail_desc = "my fail desc"
|
249
|
-
end
|
250
237
|
|
251
238
|
should "return a pass result given a `false` assertion" do
|
252
|
-
result = subject.assert_not(false,
|
253
|
-
|
254
|
-
|
239
|
+
result = subject.assert_not(false, msg1)
|
240
|
+
assert_that(result).is_kind_of(Assert::Result::Pass)
|
241
|
+
assert_that(result.message).equals("")
|
255
242
|
end
|
256
243
|
|
257
244
|
should "return a fail result given a `true` assertion" do
|
258
|
-
result = subject.assert_not(true,
|
259
|
-
|
245
|
+
result = subject.assert_not(true, msg1)
|
246
|
+
assert_that(result).is_kind_of(Assert::Result::Fail)
|
260
247
|
end
|
261
248
|
|
262
249
|
should "pp the assertion value in the fail message by default" do
|
263
|
-
exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true,
|
264
|
-
result = subject.assert_not(true,
|
250
|
+
exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true, test1.config)}`."
|
251
|
+
result = subject.assert_not(true, msg1)
|
265
252
|
|
266
|
-
|
253
|
+
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
267
254
|
end
|
268
255
|
|
269
256
|
should "return a fail result given a \"truthy\" assertion" do
|
270
|
-
|
257
|
+
assert_that(subject.assert_not(34)).is_kind_of(Assert::Result::Fail)
|
271
258
|
end
|
272
259
|
|
273
260
|
should "return a pass result given a `nil` assertion" do
|
274
|
-
|
261
|
+
assert_that(subject.assert_not(nil)).is_kind_of(Assert::Result::Pass)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
class AssertThatTests < UnitTests
|
266
|
+
desc "`assert_that` method"
|
267
|
+
|
268
|
+
setup do
|
269
|
+
Assert.stub_tap_on_call(Assert::ActualValue, :new) { |_, call|
|
270
|
+
@actual_value_new_call = call
|
271
|
+
}
|
275
272
|
end
|
276
273
|
|
274
|
+
let(:actual_value) { Factory.string }
|
275
|
+
|
276
|
+
should "build an Assert::ActualValue" do
|
277
|
+
assert_instance_of Assert::ActualValue, subject.assert_that(actual_value)
|
278
|
+
assert_equal [actual_value], @actual_value_new_call.pargs
|
279
|
+
assert_equal({ context: context1 }, @actual_value_new_call.kargs)
|
280
|
+
end
|
277
281
|
end
|
278
282
|
|
279
283
|
class SubjectTests < UnitTests
|
280
284
|
desc "subject method"
|
285
|
+
subject { @subject }
|
286
|
+
|
281
287
|
setup do
|
282
|
-
expected =
|
283
|
-
@
|
284
|
-
|
285
|
-
end
|
286
|
-
@context = @context_class.new(@test, @test.config, proc{ |result| })
|
287
|
-
@subject = @context.subject
|
288
|
+
expected = expected1
|
289
|
+
context_class1.subject { @something = expected }
|
290
|
+
@subject = context1.subject
|
288
291
|
end
|
289
|
-
|
292
|
+
|
293
|
+
let(:context_class1) { Factory.modes_off_context_class }
|
294
|
+
let(:context1) { context_class1.new(test1, test1.config, proc{ |result| }) }
|
295
|
+
let(:expected1) { Factory.string }
|
290
296
|
|
291
297
|
should "instance evaluate the block set with the class setup method" do
|
292
|
-
|
298
|
+
assert_that(subject).equals(expected1)
|
293
299
|
end
|
294
|
-
|
295
300
|
end
|
296
301
|
|
297
302
|
class PendingTests < UnitTests
|
298
303
|
desc "`pending` method"
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
end
|
304
|
+
|
305
|
+
let(:block2) { proc { fail; pass; } }
|
306
|
+
let(:block1) { block = block2; proc { pending(&block) } } # test nesting
|
303
307
|
|
304
308
|
should "make fails skips and make passes fails" do
|
305
|
-
|
306
|
-
|
307
|
-
|
309
|
+
context1.fail "not affected"
|
310
|
+
context1.pass
|
311
|
+
context1.pending(&block1)
|
308
312
|
|
309
|
-
|
310
|
-
norm_fail, norm_pass, pending_fail, pending_pass =
|
313
|
+
assert_that(test_results1.size).equals(4)
|
314
|
+
norm_fail, norm_pass, pending_fail, pending_pass = test_results1
|
311
315
|
|
312
|
-
|
313
|
-
|
316
|
+
assert_that(norm_fail).is_kind_of(Assert::Result::Fail)
|
317
|
+
assert_that(norm_pass).is_kind_of(Assert::Result::Pass)
|
314
318
|
|
315
|
-
|
316
|
-
|
319
|
+
assert_that(pending_fail).is_kind_of(Assert::Result::Skip)
|
320
|
+
assert_that(pending_fail.message).includes("Pending fail")
|
317
321
|
|
318
|
-
|
319
|
-
|
322
|
+
assert_that(pending_pass).is_kind_of(Assert::Result::Fail)
|
323
|
+
assert_that(pending_pass.message).includes("Pending pass")
|
320
324
|
end
|
321
|
-
|
322
325
|
end
|
323
326
|
|
324
327
|
class PendingWithHaltOnFailTests < PendingTests
|
325
328
|
desc "when halting on fails"
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
end
|
330
|
-
subject{ @result }
|
329
|
+
subject { @result }
|
330
|
+
|
331
|
+
let(:context1) { context_class1.new(test1, halt_config1, result_callback1) }
|
331
332
|
|
332
333
|
should "make fails skips and stop the test" do
|
333
|
-
begin;
|
334
|
-
|
335
|
-
|
334
|
+
begin; context1.pending(&block1); rescue StandardError => err; end
|
335
|
+
assert_that(err).is_kind_of(Assert::Result::TestSkipped)
|
336
|
+
assert_that(err.message).includes("Pending fail")
|
336
337
|
|
337
|
-
|
338
|
+
assert_that(test_results1.size).equals(0) # it halted before the pending pass
|
338
339
|
end
|
339
|
-
|
340
340
|
end
|
341
341
|
|
342
342
|
class WithBacktraceTests < UnitTests
|
343
343
|
desc "`with_backtrace` method"
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
end
|
344
|
+
|
345
|
+
let(:from_bt1) { ["called_from_here", Factory.string] }
|
346
|
+
let(:from_block1) { proc { ignore; fail; pass; skip "todo"; } }
|
348
347
|
|
349
348
|
should "alter non-error block results' bt with given bt's first line" do
|
350
|
-
|
349
|
+
context1.fail "not affected"
|
351
350
|
begin
|
352
|
-
|
351
|
+
context1.with_backtrace(from_bt1, &from_block1)
|
353
352
|
rescue Assert::Result::TestSkipped => e
|
354
|
-
|
353
|
+
test_results1 << Assert::Result::Skip.for_test(test1, e)
|
355
354
|
end
|
356
355
|
|
357
|
-
|
358
|
-
norm_fail, with_ignore, with_fail, with_pass,
|
356
|
+
assert_that(test_results1.size).equals(5)
|
357
|
+
norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
|
359
358
|
|
360
359
|
assert_not_with_bt_set norm_fail
|
361
360
|
|
362
|
-
exp = [
|
361
|
+
exp = [from_bt1.first]
|
363
362
|
assert_with_bt_set exp, with_ignore
|
364
363
|
assert_with_bt_set exp, with_fail
|
365
364
|
assert_with_bt_set exp, with_pass
|
366
365
|
assert_with_bt_set exp, with_ignore
|
367
366
|
end
|
368
|
-
|
369
367
|
end
|
370
368
|
|
371
369
|
class WithNestedBacktraceTests < UnitTests
|
372
370
|
desc "`with_backtrace` method nested"
|
373
|
-
setup do
|
374
|
-
@from_bt1 = ['called_from_here 1', Factory.string]
|
375
|
-
@from_bt2 = from_bt2 = ['called_from_here 2', Factory.string]
|
376
371
|
|
377
|
-
|
378
|
-
|
379
|
-
|
372
|
+
let(:from_bt1) { ["called_from_here 1", Factory.string] }
|
373
|
+
let(:from_bt2) { ["called_from_here 2", Factory.string] }
|
374
|
+
let(:from_block2) { proc { ignore; fail; pass; skip "todo"; } }
|
375
|
+
let(:from_block1) {
|
376
|
+
from_bt = from_bt2
|
377
|
+
from_block = from_block2
|
378
|
+
proc { with_backtrace(from_bt, &from_block) }
|
379
|
+
}
|
380
380
|
|
381
381
|
should "alter non-error block results' bt with nested wbt accrued first lines" do
|
382
|
-
|
382
|
+
context1.fail "not affected"
|
383
383
|
begin
|
384
|
-
|
384
|
+
context1.with_backtrace(from_bt1, &from_block1)
|
385
385
|
rescue Assert::Result::TestSkipped => e
|
386
|
-
|
386
|
+
test_results1 << Assert::Result::Skip.for_test(test1, e)
|
387
387
|
end
|
388
388
|
|
389
|
-
|
390
|
-
norm_fail, with_ignore, with_fail, with_pass,
|
389
|
+
assert_that(test_results1.size).equals(5)
|
390
|
+
norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
|
391
391
|
|
392
392
|
assert_not_with_bt_set norm_fail
|
393
393
|
|
394
|
-
exp = [
|
394
|
+
exp = [from_bt1.first, from_bt2.first]
|
395
395
|
assert_with_bt_set exp, with_ignore
|
396
396
|
assert_with_bt_set exp, with_fail
|
397
397
|
assert_with_bt_set exp, with_pass
|
398
398
|
assert_with_bt_set exp, with_ignore
|
399
399
|
end
|
400
|
-
|
401
400
|
end
|
402
401
|
|
403
402
|
class InspectTests < UnitTests
|
404
403
|
desc "inspect method"
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
end
|
409
|
-
subject{ @inspect }
|
404
|
+
subject { inspect1 }
|
405
|
+
|
406
|
+
let(:inspect1) { context1.inspect }
|
410
407
|
|
411
408
|
should "just show the name of the class" do
|
412
|
-
|
409
|
+
exp = "#<#{context1.class}>"
|
410
|
+
assert_that(subject).equals(exp)
|
413
411
|
end
|
414
412
|
end
|
415
|
-
|
416
413
|
end
|