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.
Files changed (82) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +79 -54
  4. data/assert.gemspec +6 -5
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -18
  7. data/lib/assert/actual_value.rb +127 -0
  8. data/lib/assert/assert_runner.rb +7 -10
  9. data/lib/assert/assertions.rb +15 -28
  10. data/lib/assert/cli.rb +41 -57
  11. data/lib/assert/config.rb +8 -12
  12. data/lib/assert/config_helpers.rb +6 -10
  13. data/lib/assert/context.rb +30 -24
  14. data/lib/assert/context/let_dsl.rb +13 -0
  15. data/lib/assert/context/method_missing.rb +19 -0
  16. data/lib/assert/context/setup_dsl.rb +0 -4
  17. data/lib/assert/context/subject_dsl.rb +0 -4
  18. data/lib/assert/context/suite_dsl.rb +0 -4
  19. data/lib/assert/context/test_dsl.rb +5 -9
  20. data/lib/assert/context_info.rb +2 -6
  21. data/lib/assert/default_runner.rb +1 -5
  22. data/lib/assert/default_suite.rb +1 -6
  23. data/lib/assert/default_view.rb +8 -12
  24. data/lib/assert/factory.rb +1 -4
  25. data/lib/assert/file_line.rb +0 -4
  26. data/lib/assert/macro.rb +1 -4
  27. data/lib/assert/macros/methods.rb +5 -11
  28. data/lib/assert/result.rb +19 -34
  29. data/lib/assert/runner.rb +12 -11
  30. data/lib/assert/stub.rb +16 -2
  31. data/lib/assert/suite.rb +3 -7
  32. data/lib/assert/test.rb +13 -18
  33. data/lib/assert/utils.rb +8 -12
  34. data/lib/assert/version.rb +1 -1
  35. data/lib/assert/view.rb +18 -21
  36. data/lib/assert/view_helpers.rb +6 -17
  37. data/log/{.gitkeep → .keep} +0 -0
  38. data/test/helper.rb +26 -41
  39. data/test/support/factory.rb +20 -6
  40. data/test/support/inherited_stuff.rb +0 -2
  41. data/test/system/stub_tests.rb +350 -354
  42. data/test/system/test_tests.rb +119 -133
  43. data/test/unit/actual_value_tests.rb +335 -0
  44. data/test/unit/assert_tests.rb +125 -52
  45. data/test/unit/assertions/assert_block_tests.rb +34 -37
  46. data/test/unit/assertions/assert_empty_tests.rb +38 -38
  47. data/test/unit/assertions/assert_equal_tests.rb +84 -86
  48. data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
  49. data/test/unit/assertions/assert_includes_tests.rb +45 -46
  50. data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
  51. data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
  52. data/test/unit/assertions/assert_match_tests.rb +39 -40
  53. data/test/unit/assertions/assert_nil_tests.rb +35 -38
  54. data/test/unit/assertions/assert_raises_tests.rb +58 -62
  55. data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
  56. data/test/unit/assertions/assert_same_tests.rb +94 -90
  57. data/test/unit/assertions/assert_true_false_tests.rb +67 -69
  58. data/test/unit/assertions_tests.rb +17 -19
  59. data/test/unit/config_helpers_tests.rb +41 -43
  60. data/test/unit/config_tests.rb +42 -46
  61. data/test/unit/context/let_dsl_tests.rb +10 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -91
  63. data/test/unit/context/subject_dsl_tests.rb +18 -51
  64. data/test/unit/context/suite_dsl_tests.rb +19 -23
  65. data/test/unit/context/test_dsl_tests.rb +52 -59
  66. data/test/unit/context_info_tests.rb +19 -21
  67. data/test/unit/context_tests.rb +175 -178
  68. data/test/unit/default_runner_tests.rb +4 -10
  69. data/test/unit/default_suite_tests.rb +54 -59
  70. data/test/unit/factory_tests.rb +6 -9
  71. data/test/unit/file_line_tests.rb +34 -40
  72. data/test/unit/macro_tests.rb +11 -20
  73. data/test/unit/result_tests.rb +156 -182
  74. data/test/unit/runner_tests.rb +72 -79
  75. data/test/unit/suite_tests.rb +62 -63
  76. data/test/unit/test_tests.rb +143 -147
  77. data/test/unit/utils_tests.rb +49 -62
  78. data/test/unit/view_helpers_tests.rb +67 -70
  79. data/test/unit/view_tests.rb +26 -32
  80. metadata +54 -47
  81. data/.assert.rb +0 -3
  82. data/.gitignore +0 -19
@@ -1,55 +1,53 @@
1
- require 'assert'
2
- require 'assert/context_info'
1
+ require "assert"
2
+ require "assert/context_info"
3
3
 
4
- require 'assert/context'
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{ @info }
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
- assert_equal @klass, subject.klass
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(@klass, @caller.first, nil)
26
- assert_equal @caller.first, info.called_from
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(@klass, nil, @caller.first)
29
- assert_equal @caller.first, info.called_from
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
- assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ''), subject.file
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(@klass)
38
- assert_nil info.file
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
- assert_equal name, subject.test_name(name)
46
- assert_equal '', subject.test_name('')
47
- assert_equal '', subject.test_name(nil)
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
- assert_equal "#{desc} #{name}", subject.test_name(name)
50
+ assert_that(subject.test_name(name)).equals("#{desc} #{name}")
51
51
  end
52
-
53
52
  end
54
-
55
53
  end
@@ -1,29 +1,31 @@
1
- require 'assert'
2
- require 'assert/context'
1
+ require "assert"
2
+ require "assert/context"
3
3
 
4
- require 'assert/config'
5
- require 'assert/result'
6
- require 'assert/utils'
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
- subject{ @context }
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
- assert_match /test\/unit\/context_tests.rb$/, test.context_info.file
42
- assert_equal self.class, test.context_info.klass
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, 'test', '')}/
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
- assert_true result.with_bt_set?
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
- assert_equal exp, result.trace
54
- assert_equal exp_with_bt.first, result.src_line
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
- assert_false result.with_bt_set?
63
+ assert_that(result.with_bt_set?).is_false
61
64
 
62
- assert_equal result.src_line, result.trace
63
- assert_equal result.backtrace.filtered.first.to_s, result.src_line
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
- @skip_msg = "I need to implement this in the future."
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
- assert_kind_of Assert::Result::TestSkipped, @exception
80
- assert_equal @skip_msg, @exception.message
81
- assert_equal @skip_msg, subject.message
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
- assert_nil @callback_result
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
- assert_not_equal 1, @exception.backtrace.size
91
+ assert_that(@exception.backtrace.size).does_not_equal(1)
90
92
 
91
93
  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
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
- @ignore_msg = "Ignore this for now, will do later."
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
- assert_kind_of Assert::Result::Ignore, subject
109
- assert_equal @ignore_msg, subject.message
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
- assert_equal @result, @callback_result
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
- @pass_msg = "That's right, it works."
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
- assert_kind_of Assert::Result::Pass, subject
128
- assert_equal @pass_msg, subject.message
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
- assert_equal @result, @callback_result
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
- @flunk_msg = "It flunked."
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
- assert_kind_of Assert::Result::Fail, subject
147
- assert_equal @flunk_msg, subject.message
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
- assert_equal @result, @callback_result
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 = @context.fail
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
- 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
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
- fail_msg = "Didn't work"
171
- result = @context.fail(fail_msg)
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
- assert_equal @result, @callback_result
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
- 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 }
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; @context.fail(@fail_msg); rescue StandardError => err; end
192
- assert_kind_of Assert::Result::TestFailure, err
193
- assert_equal @fail_msg, err.message
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
- assert_equal @fail_msg, result.message
190
+ assert_that(result.message).equals(msg1)
197
191
  end
198
192
 
199
193
  should "not call the result callback" do
200
- assert_nil @callback_result
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
- setup do
208
- @fail_desc = "my fail desc"
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, @fail_desc){ @what_failed }
214
- assert_kind_of Assert::Result::Pass, result
215
- assert_equal '', result.message
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, @fail_desc){ @what_failed }
220
- assert_kind_of Assert::Result::Fail, result
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, @test.config)}`."
225
- result = subject.assert(false, @fail_desc)
215
+ exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
216
+ result = subject.assert(false, msg1)
226
217
 
227
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
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, @fail_desc){ @what_failed }
232
- assert_equal [@fail_desc, @what_failed].join("\n"), result.message
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
- assert_kind_of Assert::Result::Pass, subject.assert(34)
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
- assert_kind_of Assert::Result::Fail, subject.assert(nil)
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, @fail_desc)
253
- assert_kind_of Assert::Result::Pass, result
254
- assert_equal '', result.message
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, @fail_desc)
259
- assert_kind_of Assert::Result::Fail, result
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, @test.config)}`."
264
- result = subject.assert_not(true, @fail_desc)
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
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
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
- assert_kind_of Assert::Result::Fail, subject.assert_not(34)
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
- assert_kind_of Assert::Result::Pass, subject.assert_not(nil)
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 = @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
288
+ expected = expected1
289
+ context_class1.subject { @something = expected }
290
+ @subject = context1.subject
288
291
  end
289
- subject{ @subject }
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
- assert_equal @expected, subject
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
- setup do
300
- block2 = proc { fail; pass; }
301
- @block1 = proc { pending(&block2) } # test nesting
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
- @context.fail 'not affected'
306
- @context.pass
307
- @context.pending(&@block1)
309
+ context1.fail "not affected"
310
+ context1.pass
311
+ context1.pending(&block1)
308
312
 
309
- assert_equal 4, @test_results.size
310
- norm_fail, norm_pass, pending_fail, pending_pass = @test_results
313
+ assert_that(test_results1.size).equals(4)
314
+ norm_fail, norm_pass, pending_fail, pending_pass = test_results1
311
315
 
312
- assert_kind_of Assert::Result::Fail, norm_fail
313
- assert_kind_of Assert::Result::Pass, norm_pass
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
- assert_kind_of Assert::Result::Skip, pending_fail
316
- assert_includes "Pending fail", pending_fail.message
319
+ assert_that(pending_fail).is_kind_of(Assert::Result::Skip)
320
+ assert_that(pending_fail.message).includes("Pending fail")
317
321
 
318
- assert_kind_of Assert::Result::Fail, pending_pass
319
- assert_includes "Pending pass", pending_pass.message
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
- 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 }
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; @context.pending(&@block1); rescue StandardError => err; end
334
- assert_kind_of Assert::Result::TestSkipped, err
335
- assert_includes "Pending fail", err.message
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
- assert_equal 0, @test_results.size # it halted before the pending pass
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
- setup do
345
- @from_bt = ['called_from_here', Factory.string]
346
- @from_block = proc { ignore; fail; pass; skip 'todo'; }
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
- @context.fail 'not affected'
349
+ context1.fail "not affected"
351
350
  begin
352
- @context.with_backtrace(@from_bt, &@from_block)
351
+ context1.with_backtrace(from_bt1, &from_block1)
353
352
  rescue Assert::Result::TestSkipped => e
354
- @test_results << Assert::Result::Skip.for_test(@test, e)
353
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
355
354
  end
356
355
 
357
- assert_equal 5, @test_results.size
358
- norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
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 = [@from_bt.first]
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
- from_block2 = proc { ignore; fail; pass; skip 'todo'; }
378
- @from_block1 = proc { with_backtrace(from_bt2, &from_block2) }
379
- end
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
- @context.fail 'not affected'
382
+ context1.fail "not affected"
383
383
  begin
384
- @context.with_backtrace(@from_bt1, &@from_block1)
384
+ context1.with_backtrace(from_bt1, &from_block1)
385
385
  rescue Assert::Result::TestSkipped => e
386
- @test_results << Assert::Result::Skip.for_test(@test, e)
386
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
387
387
  end
388
388
 
389
- assert_equal 5, @test_results.size
390
- norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
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 = [@from_bt1.first, @from_bt2.first]
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
- setup do
406
- @expected = "#<#{@context.class}>"
407
- @inspect = @context.inspect
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
- assert_equal @expected, subject
409
+ exp = "#<#{context1.class}>"
410
+ assert_that(subject).equals(exp)
413
411
  end
414
412
  end
415
-
416
413
  end