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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +66 -41
  4. data/assert.gemspec +2 -3
  5. data/lib/assert.rb +0 -10
  6. data/lib/assert/actual_value.rb +127 -0
  7. data/lib/assert/assert_runner.rb +0 -3
  8. data/lib/assert/assertions.rb +10 -23
  9. data/lib/assert/cli.rb +30 -46
  10. data/lib/assert/config.rb +0 -4
  11. data/lib/assert/config_helpers.rb +0 -4
  12. data/lib/assert/context.rb +18 -9
  13. data/lib/assert/context/let_dsl.rb +13 -0
  14. data/lib/assert/context/method_missing.rb +19 -0
  15. data/lib/assert/context/setup_dsl.rb +0 -4
  16. data/lib/assert/context/subject_dsl.rb +23 -28
  17. data/lib/assert/context/suite_dsl.rb +0 -4
  18. data/lib/assert/context/test_dsl.rb +0 -4
  19. data/lib/assert/context_info.rb +0 -4
  20. data/lib/assert/default_runner.rb +0 -4
  21. data/lib/assert/default_suite.rb +0 -5
  22. data/lib/assert/default_view.rb +0 -4
  23. data/lib/assert/factory.rb +0 -3
  24. data/lib/assert/file_line.rb +0 -4
  25. data/lib/assert/macro.rb +0 -3
  26. data/lib/assert/macros/methods.rb +4 -10
  27. data/lib/assert/result.rb +2 -17
  28. data/lib/assert/runner.rb +0 -3
  29. data/lib/assert/stub.rb +15 -1
  30. data/lib/assert/suite.rb +0 -4
  31. data/lib/assert/test.rb +2 -7
  32. data/lib/assert/utils.rb +0 -4
  33. data/lib/assert/version.rb +1 -1
  34. data/lib/assert/view.rb +0 -3
  35. data/lib/assert/view_helpers.rb +0 -11
  36. data/log/{.gitkeep → .keep} +0 -0
  37. data/test/helper.rb +23 -29
  38. data/test/support/factory.rb +14 -0
  39. data/test/support/inherited_stuff.rb +0 -2
  40. data/test/system/stub_tests.rb +332 -352
  41. data/test/system/test_tests.rb +98 -124
  42. data/test/unit/actual_value_tests.rb +335 -0
  43. data/test/unit/assert_tests.rb +121 -46
  44. data/test/unit/assertions/assert_block_tests.rb +30 -35
  45. data/test/unit/assertions/assert_empty_tests.rb +33 -35
  46. data/test/unit/assertions/assert_equal_tests.rb +75 -83
  47. data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
  48. data/test/unit/assertions/assert_includes_tests.rb +38 -41
  49. data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
  50. data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
  51. data/test/unit/assertions/assert_match_tests.rb +34 -37
  52. data/test/unit/assertions/assert_nil_tests.rb +30 -35
  53. data/test/unit/assertions/assert_raises_tests.rb +54 -60
  54. data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
  55. data/test/unit/assertions/assert_same_tests.rb +86 -88
  56. data/test/unit/assertions/assert_true_false_tests.rb +60 -66
  57. data/test/unit/assertions_tests.rb +14 -17
  58. data/test/unit/config_helpers_tests.rb +41 -39
  59. data/test/unit/config_tests.rb +38 -37
  60. data/test/unit/context/let_dsl_tests.rb +10 -0
  61. data/test/unit/context/setup_dsl_tests.rb +68 -87
  62. data/test/unit/context/subject_dsl_tests.rb +15 -49
  63. data/test/unit/context/suite_dsl_tests.rb +15 -20
  64. data/test/unit/context/test_dsl_tests.rb +50 -57
  65. data/test/unit/context_info_tests.rb +23 -18
  66. data/test/unit/context_tests.rb +183 -194
  67. data/test/unit/default_runner_tests.rb +1 -7
  68. data/test/unit/default_suite_tests.rb +57 -56
  69. data/test/unit/factory_tests.rb +5 -6
  70. data/test/unit/file_line_tests.rb +33 -39
  71. data/test/unit/macro_tests.rb +14 -18
  72. data/test/unit/result_tests.rb +159 -196
  73. data/test/unit/runner_tests.rb +64 -71
  74. data/test/unit/suite_tests.rb +58 -59
  75. data/test/unit/test_tests.rb +125 -136
  76. data/test/unit/utils_tests.rb +43 -54
  77. data/test/unit/view_helpers_tests.rb +54 -58
  78. data/test/unit/view_tests.rb +22 -27
  79. metadata +15 -10
  80. 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
- subject{ @info }
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
- assert_equal @klass, subject.klass
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(@klass, @caller.first, nil)
26
- assert_equal @caller.first, info.called_from
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(@klass, nil, @caller.first)
29
- assert_equal @caller.first, info.called_from
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
- assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ""), subject.file
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(@klass)
38
- assert_nil info.file
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
- assert_equal name, subject.test_name(name)
46
- assert_equal "", subject.test_name("")
47
- assert_equal "", subject.test_name(nil)
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
- assert_equal "#{desc} #{name}", subject.test_name(name)
57
+ assert_that(subject.test_name(name)).equals("#{desc} #{name}")
51
58
  end
52
-
53
59
  end
54
-
55
60
  end
@@ -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
- # DSL methods
26
- should have_cmeths :description, :desc, :describe, :subject, :suite
27
- should have_cmeths :setup_once, :before_once, :startup
28
- should have_cmeths :teardown_once, :after_once, :shutdown
29
- should have_cmeths :setup, :before, :setups, :run_setups
30
- should have_cmeths :teardown, :after, :teardowns, :run_teardowns
31
- should have_cmeths :around, :arounds, :run_arounds
32
- should have_cmeths :test, :test_eventually, :test_skip
33
- should have_cmeths :should, :should_eventually, :should_skip
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
- assert_match /test\/unit\/context_tests.rb$/, test.context_info.file
42
- assert_equal self.class, test.context_info.klass
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
- assert_true result.with_bt_set?
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
- assert_equal exp, result.trace
54
- assert_equal exp_with_bt.first, result.src_line
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
- assert_false result.with_bt_set?
69
+ assert_that(result.with_bt_set?).is_false
61
70
 
62
- assert_equal result.src_line, result.trace
63
- assert_equal result.backtrace.filtered.first.to_s, result.src_line
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 < UnitTests
77
+ class SkipTests < InitTests
70
78
  desc "skip method"
79
+
71
80
  setup do
72
- @skip_msg = "I need to implement this in the future."
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
- assert_kind_of Assert::Result::TestSkipped, @exception
80
- assert_equal @skip_msg, @exception.message
81
- assert_equal @skip_msg, subject.message
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
- assert_nil @callback_result
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
- assert_not_equal 1, @exception.backtrace.size
96
+ assert_that(@exception.backtrace.size).does_not_equal(1)
90
97
 
91
98
  called_from = Factory.string
92
- begin; @context.skip(@skip_msg, called_from); rescue StandardError => exception; end
93
- assert_equal 1, exception.backtrace.size
94
- assert_equal called_from, exception.backtrace.first
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 < UnitTests
105
+ class IgnoreTests < InitTests
100
106
  desc "ignore method"
107
+
101
108
  setup do
102
- @ignore_msg = "Ignore this for now, will do later."
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
- assert_kind_of Assert::Result::Ignore, subject
109
- assert_equal @ignore_msg, subject.message
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
- assert_equal @result, @callback_result
118
+ assert_that(@callback_result).equals(@result)
114
119
  end
115
-
116
120
  end
117
121
 
118
- class PassTests < UnitTests
122
+ class PassTests < InitTests
119
123
  desc "pass method"
124
+
120
125
  setup do
121
- @pass_msg = "That's right, it works."
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
- assert_kind_of Assert::Result::Pass, subject
128
- assert_equal @pass_msg, subject.message
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
- assert_equal @result, @callback_result
135
+ assert_that(@callback_result).equals(@result)
133
136
  end
134
-
135
137
  end
136
138
 
137
- class FlunkTests < UnitTests
139
+ class FlunkTests < InitTests
138
140
  desc "flunk method"
141
+
139
142
  setup do
140
- @flunk_msg = "It flunked."
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
- assert_kind_of Assert::Result::Fail, subject
147
- assert_equal @flunk_msg, subject.message
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
- assert_equal @result, @callback_result
152
+ assert_that(@callback_result).equals(@result)
152
153
  end
153
-
154
154
  end
155
155
 
156
- class FailTests < UnitTests
156
+ class FailTests < InitTests
157
157
  desc "fail method"
158
+
158
159
  setup do
159
- @result = @context.fail
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
- assert_kind_of Assert::Result::Fail, subject
165
- assert_equal subject.backtrace.filtered.first.to_s, subject.trace
166
- assert_kind_of Array, subject.backtrace
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
- fail_msg = "Didn't work"
171
- result = @context.fail(fail_msg)
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
- assert_equal @result, @callback_result
175
+ assert_that(@callback_result).equals(@result)
177
176
  end
178
-
179
177
  end
180
178
 
181
- class HaltOnFailTests < UnitTests
179
+ class HaltOnFailTests < InitTests
182
180
  desc "failing when halting on fails"
183
- setup do
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; @context.fail(@fail_msg); rescue StandardError => err; end
192
- assert_kind_of Assert::Result::TestFailure, err
193
- assert_equal @fail_msg, err.message
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
- assert_equal @fail_msg, result.message
189
+ assert_that(result.message).equals(msg1)
197
190
  end
198
191
 
199
192
  should "not call the result callback" do
200
- assert_nil @callback_result
193
+ assert_that(@callback_result).is_nil
201
194
  end
202
-
203
195
  end
204
196
 
205
- class AssertTests < UnitTests
197
+ class AssertTests < InitTests
206
198
  desc "assert method"
207
- setup do
208
- @fail_desc = "my fail desc"
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, @fail_desc){ @what_failed }
214
- assert_kind_of Assert::Result::Pass, result
215
- assert_equal "", result.message
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, @fail_desc){ @what_failed }
220
- assert_kind_of Assert::Result::Fail, result
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, @test.config)}`."
225
- result = subject.assert(false, @fail_desc)
214
+ exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
215
+ result = subject.assert(false, msg1)
226
216
 
227
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
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, @fail_desc){ @what_failed }
232
- assert_equal [@fail_desc, @what_failed].join("\n"), result.message
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
- assert_kind_of Assert::Result::Pass, subject.assert(34)
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
- assert_kind_of Assert::Result::Fail, subject.assert(nil)
230
+ assert_that(subject.assert(nil)).is_kind_of(Assert::Result::Fail)
241
231
  end
242
-
243
232
  end
244
233
 
245
- class AssertNotTests < UnitTests
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, @fail_desc)
253
- assert_kind_of Assert::Result::Pass, result
254
- assert_equal "", result.message
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, @fail_desc)
259
- assert_kind_of Assert::Result::Fail, result
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, @test.config)}`."
264
- result = subject.assert_not(true, @fail_desc)
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
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
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
- assert_kind_of Assert::Result::Fail, subject.assert_not(34)
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
- assert_kind_of Assert::Result::Pass, subject.assert_not(nil)
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 < UnitTests
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 = @expected = "amazing"
283
- @context_class = Factory.modes_off_context_class do
284
- subject{ @something = expected }
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
- subject{ @subject }
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
- assert_equal @expected, subject
296
+ assert_that(@subject).equals(expected1)
293
297
  end
294
-
295
298
  end
296
299
 
297
- class PendingTests < UnitTests
300
+ class PendingTests < InitTests
298
301
  desc "`pending` method"
299
- setup do
300
- block2 = proc { fail; pass; }
301
- @block1 = proc { pending(&block2) } # test nesting
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
- @context.fail "not affected"
306
- @context.pass
307
- @context.pending(&@block1)
307
+ subject.fail "not affected"
308
+ subject.pass
309
+ subject.pending(&block1)
308
310
 
309
- assert_equal 4, @test_results.size
310
- norm_fail, norm_pass, pending_fail, pending_pass = @test_results
311
+ assert_that(test_results1.size).equals(4)
312
+ norm_fail, norm_pass, pending_fail, pending_pass = test_results1
311
313
 
312
- assert_kind_of Assert::Result::Fail, norm_fail
313
- assert_kind_of Assert::Result::Pass, norm_pass
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
- assert_kind_of Assert::Result::Skip, pending_fail
316
- assert_includes "Pending fail", pending_fail.message
317
+ assert_that(pending_fail).is_kind_of(Assert::Result::Skip)
318
+ assert_that(pending_fail.message).includes("Pending fail")
317
319
 
318
- assert_kind_of Assert::Result::Fail, pending_pass
319
- assert_includes "Pending pass", pending_pass.message
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
- setup do
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; @context.pending(&@block1); rescue StandardError => err; end
334
- assert_kind_of Assert::Result::TestSkipped, err
335
- assert_includes "Pending fail", err.message
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
- assert_equal 0, @test_results.size # it halted before the pending pass
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 < UnitTests
338
+ class WithBacktraceTests < InitTests
343
339
  desc "`with_backtrace` method"
344
- setup do
345
- @from_bt = ["called_from_here", Factory.string]
346
- @from_block = proc { ignore; fail; pass; skip "todo"; }
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
- @context.fail "not affected"
345
+ subject.fail "not affected"
351
346
  begin
352
- @context.with_backtrace(@from_bt, &@from_block)
347
+ subject.with_backtrace(from_bt1, &from_block1)
353
348
  rescue Assert::Result::TestSkipped => e
354
- @test_results << Assert::Result::Skip.for_test(@test, e)
349
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
355
350
  end
356
351
 
357
- assert_equal 5, @test_results.size
358
- norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
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 = [@from_bt.first]
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 < UnitTests
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
- from_block2 = proc { ignore; fail; pass; skip "todo"; }
378
- @from_block1 = proc { with_backtrace(from_bt2, &from_block2) }
379
- end
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
- @context.fail "not affected"
378
+ subject.fail "not affected"
383
379
  begin
384
- @context.with_backtrace(@from_bt1, &@from_block1)
380
+ subject.with_backtrace(from_bt1, &from_block1)
385
381
  rescue Assert::Result::TestSkipped => e
386
- @test_results << Assert::Result::Skip.for_test(@test, e)
382
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
387
383
  end
388
384
 
389
- assert_equal 5, @test_results.size
390
- norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
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 = [@from_bt1.first, @from_bt2.first]
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 < UnitTests
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
- assert_equal @expected, subject
402
+ assert_that(subject.inspect).equals("#<#{subject.class}>")
413
403
  end
414
404
  end
415
-
416
405
  end