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