assert 2.18.3 → 2.19.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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/assert.gemspec +11 -5
  4. data/bin/assert +1 -0
  5. data/lib/assert.rb +20 -6
  6. data/lib/assert/actual_value.rb +26 -8
  7. data/lib/assert/assert_runner.rb +38 -17
  8. data/lib/assert/assertions.rb +145 -41
  9. data/lib/assert/cli.rb +19 -66
  10. data/lib/assert/clirb.rb +55 -0
  11. data/lib/assert/config.rb +9 -7
  12. data/lib/assert/config_helpers.rb +57 -22
  13. data/lib/assert/context.rb +33 -49
  14. data/lib/assert/context/let_dsl.rb +10 -4
  15. data/lib/assert/context/method_missing.rb +3 -0
  16. data/lib/assert/context/setup_dsl.rb +24 -16
  17. data/lib/assert/context/subject_dsl.rb +26 -25
  18. data/lib/assert/context/suite_dsl.rb +5 -1
  19. data/lib/assert/context/test_dsl.rb +58 -19
  20. data/lib/assert/context_info.rb +2 -0
  21. data/lib/assert/default_runner.rb +2 -0
  22. data/lib/assert/default_suite.rb +27 -15
  23. data/lib/assert/default_view.rb +49 -30
  24. data/lib/assert/factory.rb +2 -0
  25. data/lib/assert/file_line.rb +8 -6
  26. data/lib/assert/macro.rb +3 -1
  27. data/lib/assert/macros/methods.rb +73 -45
  28. data/lib/assert/result.rb +117 -61
  29. data/lib/assert/runner.rb +70 -51
  30. data/lib/assert/stub.rb +44 -3
  31. data/lib/assert/suite.rb +76 -38
  32. data/lib/assert/test.rb +43 -44
  33. data/lib/assert/utils.rb +22 -11
  34. data/lib/assert/version.rb +3 -1
  35. data/lib/assert/view.rb +46 -18
  36. data/lib/assert/view_helpers.rb +102 -92
  37. data/test/helper.rb +8 -4
  38. data/test/support/factory.rb +40 -21
  39. data/test/support/inherited_stuff.rb +2 -0
  40. data/test/system/stub_tests.rb +272 -250
  41. data/test/system/test_tests.rb +89 -73
  42. data/test/unit/actual_value_tests.rb +103 -46
  43. data/test/unit/assert_tests.rb +49 -39
  44. data/test/unit/assertions/assert_block_tests.rb +14 -14
  45. data/test/unit/assertions/assert_changes_tests.rb +103 -0
  46. data/test/unit/assertions/assert_empty_tests.rb +18 -16
  47. data/test/unit/assertions/assert_equal_tests.rb +48 -32
  48. data/test/unit/assertions/assert_file_exists_tests.rb +19 -17
  49. data/test/unit/assertions/assert_includes_tests.rb +14 -14
  50. data/test/unit/assertions/assert_instance_of_tests.rb +18 -18
  51. data/test/unit/assertions/assert_is_a_tests.rb +128 -0
  52. data/test/unit/assertions/assert_match_tests.rb +14 -14
  53. data/test/unit/assertions/assert_nil_tests.rb +20 -16
  54. data/test/unit/assertions/assert_raises_tests.rb +36 -27
  55. data/test/unit/assertions/assert_respond_to_tests.rb +14 -14
  56. data/test/unit/assertions/assert_same_tests.rb +28 -32
  57. data/test/unit/assertions/assert_true_false_tests.rb +38 -32
  58. data/test/unit/assertions_tests.rb +25 -18
  59. data/test/unit/config_helpers_tests.rb +20 -9
  60. data/test/unit/config_tests.rb +16 -8
  61. data/test/unit/context/let_dsl_tests.rb +2 -0
  62. data/test/unit/context/setup_dsl_tests.rb +27 -15
  63. data/test/unit/context/subject_dsl_tests.rb +5 -4
  64. data/test/unit/context/suite_dsl_tests.rb +6 -5
  65. data/test/unit/context/test_dsl_tests.rb +43 -19
  66. data/test/unit/context_info_tests.rb +12 -3
  67. data/test/unit/context_tests.rb +166 -116
  68. data/test/unit/default_runner_tests.rb +2 -0
  69. data/test/unit/default_suite_tests.rb +17 -5
  70. data/test/unit/factory_tests.rb +5 -1
  71. data/test/unit/file_line_tests.rb +14 -12
  72. data/test/unit/macro_tests.rb +17 -10
  73. data/test/unit/result_tests.rb +72 -75
  74. data/test/unit/runner_tests.rb +38 -23
  75. data/test/unit/suite_tests.rb +48 -30
  76. data/test/unit/test_tests.rb +88 -102
  77. data/test/unit/utils_tests.rb +53 -36
  78. data/test/unit/view_helpers_tests.rb +25 -17
  79. data/test/unit/view_tests.rb +8 -5
  80. metadata +40 -9
  81. data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/runner"
3
5
 
@@ -10,7 +12,9 @@ require "assert/view"
10
12
  class Assert::Runner
11
13
  class UnitTests < Assert::Context
12
14
  desc "Assert::Runner"
13
- subject { Assert::Runner }
15
+ subject{ unit_class }
16
+
17
+ let(:unit_class){ Assert::Runner }
14
18
 
15
19
  should "include the config helpers" do
16
20
  assert_that(subject).includes(Assert::ConfigHelpers)
@@ -19,15 +23,14 @@ class Assert::Runner
19
23
 
20
24
  class InitTests < UnitTests
21
25
  desc "when init"
22
- subject { runner1 }
26
+ subject{ unit_class.new(config1) }
23
27
 
24
28
  setup do
25
29
  config1.suite Assert::DefaultSuite.new(config1)
26
- config1.view Assert::View.new(config1, StringIO.new("", "w+"))
30
+ config1.view Assert::View.new(config1, StringIO.new(+"", "w+"))
27
31
  end
28
32
 
29
- let(:config1) { Factory.modes_off_config }
30
- let(:runner1) { Assert::Runner.new(config1) }
33
+ let(:config1){ Factory.modes_off_config }
31
34
 
32
35
  should have_readers :config
33
36
  should have_imeths :runner, :run
@@ -46,9 +49,10 @@ class Assert::Runner
46
49
 
47
50
  class RunTests < InitTests
48
51
  desc "and run"
52
+ subject{ runner_class1.new(config1) }
49
53
 
50
54
  setup do
51
- @view_output = ""
55
+ @view_output = +""
52
56
 
53
57
  suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
54
58
  view_class = Class.new(Assert::View){ include CallbackMixin }
@@ -57,33 +61,36 @@ class Assert::Runner
57
61
  config1.view view_class.new(config1, StringIO.new(@view_output, "w+"))
58
62
  config1.suite.on_test(test1)
59
63
 
60
- @result = subject.run
64
+ @result_count = subject.run
61
65
  end
62
66
 
63
- let(:runner_class1) { Class.new(Assert::Runner) { include CallbackMixin } }
64
- let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
65
- let(:test1) { Factory.test("should pass", ci1){ assert(1==1) } }
66
- let(:runner1) { runner_class1.new(config1) }
67
+ let(:runner_class1) do
68
+ Class.new(unit_class){ include CallbackMixin }
69
+ end
70
+ let(:ci1){ Factory.context_info(Factory.modes_off_context_class) }
71
+ # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
72
+ let(:test1){ Factory.test("should pass", ci1){ assert(1 == 1) } }
73
+ # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands
67
74
 
68
75
  should "return the fail+error result count as an integer exit code" do
69
- assert_that(@result).equals(0)
76
+ assert_that(@result_count).equals(0)
70
77
 
71
78
  fail_count = Factory.integer
72
79
  error_count = Factory.integer
73
80
  Assert.stub(subject, :fail_result_count){ fail_count }
74
81
  Assert.stub(subject, :error_result_count){ error_count }
75
- Assert.stub(test1, :run){ } # no-op
76
- result = runner1.run
82
+ Assert.stub(test1, :run){} # no-op
83
+ result_count = subject.run
77
84
 
78
- exp = fail_count + error_count
79
- assert_that(result).equals(exp)
85
+ assert_that(result_count).equals(fail_count + error_count)
80
86
  end
81
87
 
82
88
  should "run all callbacks on itself, the suite and the view" do
83
89
  # itself
84
90
  assert_that(subject.on_start_called).is_true
85
91
  assert_that(subject.before_test_called).equals([test1])
86
- assert_that(subject.on_result_called.last).is_instance_of(Assert::Result::Pass)
92
+ assert_that(subject.on_result_called.last)
93
+ .is_instance_of(Assert::Result::Pass)
87
94
  assert_that(subject.after_test_called).equals([test1])
88
95
  assert_that(subject.on_finish_called).is_true
89
96
 
@@ -91,7 +98,8 @@ class Assert::Runner
91
98
  suite = config1.suite
92
99
  assert_that(suite.on_start_called).is_true
93
100
  assert_that(suite.before_test_called).equals([test1])
94
- assert_that(suite.on_result_called.last).is_instance_of(Assert::Result::Pass)
101
+ assert_that(suite.on_result_called.last)
102
+ .is_instance_of(Assert::Result::Pass)
95
103
  assert_that(suite.after_test_called).equals([test1])
96
104
  assert_that(suite.on_finish_called).is_true
97
105
 
@@ -99,7 +107,8 @@ class Assert::Runner
99
107
  view = config1.view
100
108
  assert_that(view.on_start_called).is_true
101
109
  assert_that(view.before_test_called).equals([test1])
102
- assert_that(view.on_result_called.last).is_instance_of(Assert::Result::Pass)
110
+ assert_that(view.on_result_called.last)
111
+ .is_instance_of(Assert::Result::Pass)
103
112
  assert_that(view.after_test_called).equals([test1])
104
113
  assert_that(view.on_finish_called).is_true
105
114
  end
@@ -116,7 +125,9 @@ class Assert::Runner
116
125
  end
117
126
 
118
127
  should "run only a single test if a single test is configured" do
119
- test = Factory.test("should pass", ci1){ assert(1==1) }
128
+ # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
129
+ test = Factory.test("should pass", ci1){ assert(1 == 1) }
130
+ # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands
120
131
  config1.suite.clear_tests_to_run
121
132
  config1.suite.on_test(test)
122
133
  config1.single_test test.file_line.to_s
@@ -125,8 +136,11 @@ class Assert::Runner
125
136
  assert_that(runner.before_test_called).equals([test])
126
137
  end
127
138
 
128
- should "not run any tests if a single test is configured but can't be found" do
129
- test = Factory.test("should pass", ci1){ assert(1==1) }
139
+ should "not run any tests if a single test is configured but "\
140
+ "can't be found" do
141
+ # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
142
+ test = Factory.test("should pass", ci1){ assert(1 == 1) }
143
+ # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands
130
144
  config1.suite.clear_tests_to_run
131
145
  config1.suite.on_test(test)
132
146
  config1.single_test Factory.string
@@ -135,7 +149,8 @@ class Assert::Runner
135
149
  assert_that(runner.before_test_called).is_nil
136
150
  end
137
151
 
138
- should "describe running only a single test if a single test is configured" do
152
+ should "describe running only a single test if a single test is "\
153
+ "configured" do
139
154
  config1.suite.clear_tests_to_run
140
155
  config1.suite.on_test(test1)
141
156
  config1.single_test test1.file_line.to_s
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/suite"
3
5
 
@@ -6,29 +8,24 @@ require "assert/test"
6
8
  require "test/support/inherited_stuff"
7
9
 
8
10
  class Assert::Suite
9
-
10
11
  class UnitTests < Assert::Context
11
12
  desc "Assert::Suite"
12
- subject { Assert::Suite }
13
+ subject{ unit_class }
14
+
15
+ let(:unit_class){ Assert::Suite }
13
16
 
14
17
  should "include the config helpers" do
15
18
  assert_that(subject).includes(Assert::ConfigHelpers)
16
19
  end
17
-
18
- should "know its test method regex" do
19
- assert_that(subject::TEST_METHOD_REGEX).matches("test#{Factory.string}")
20
- assert_that(subject::TEST_METHOD_REGEX).does_not_match("#{Factory.string}test")
21
- end
22
20
  end
23
21
 
24
22
  class InitTests < UnitTests
25
23
  desc "when init"
26
- subject { suite1 }
24
+ subject{ unit_class.new(config1) }
27
25
 
28
- let(:config1) { Factory.modes_off_config }
29
- let(:suite1) { Assert::Suite.new(config1) }
26
+ let(:config1){ Factory.modes_off_config }
30
27
 
31
- should have_readers :config, :test_methods, :setups, :teardowns
28
+ should have_readers :config, :setups, :teardowns
32
29
  should have_accessors :start_time, :end_time
33
30
  should have_imeths :suite, :setup, :startup, :teardown, :shutdown
34
31
  should have_imeths :tests_to_run?, :tests_to_run_count, :clear_tests_to_run
@@ -46,7 +43,6 @@ class Assert::Suite
46
43
  end
47
44
 
48
45
  should "default its attrs" do
49
- assert_that(subject.test_methods).equals([])
50
46
  assert_that(subject.setups).equals([])
51
47
  assert_that(subject.teardowns).equals([])
52
48
 
@@ -78,14 +74,16 @@ class Assert::Suite
78
74
  Assert.stub(subject, :result_count){ count }
79
75
 
80
76
  assert_that(subject.run_time).equals(time)
81
- assert_that(subject.test_rate).equals((subject.test_count / subject.run_time))
82
- assert_that(subject.result_rate).equals((subject.result_count / subject.run_time))
77
+ assert_that(subject.test_rate)
78
+ .equals((subject.test_count / subject.run_time))
79
+ assert_that(subject.result_rate)
80
+ .equals((subject.result_count / subject.run_time))
83
81
  end
84
82
 
85
83
  should "add setup procs" do
86
84
  status = nil
87
- suite1.setup{ status = "setups" }
88
- suite1.startup{ status += " have been run" }
85
+ subject.setup{ status = "setups" }
86
+ subject.startup{ status += " have been run" }
89
87
 
90
88
  assert_that(subject.setups.count).equals(2)
91
89
  subject.setups.each(&:call)
@@ -94,8 +92,8 @@ class Assert::Suite
94
92
 
95
93
  should "add teardown procs" do
96
94
  status = nil
97
- suite1.teardown{ status = "teardowns" }
98
- suite1.shutdown{ status += " have been run" }
95
+ subject.teardown{ status = "teardowns" }
96
+ subject.shutdown{ status += " have been run" }
99
97
 
100
98
  assert_that(subject.teardowns.count).equals(2)
101
99
  subject.teardowns.each(&:call)
@@ -107,20 +105,40 @@ class Assert::Suite
107
105
  desc "with tests loaded"
108
106
 
109
107
  setup do
110
- tests1.each{ |test| suite1.on_test(test) }
108
+ tests1.each{ |test| subject.on_test(test) }
111
109
  end
112
110
 
113
- let(:ci1) { proc{ Factory.context_info(Factory.modes_off_context_class) } }
114
- let(:tests1) {
111
+ let(:ci1){ proc{ Factory.context_info(Factory.modes_off_context_class) } }
112
+ let(:tests1) do
113
+ # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
115
114
  [
116
- Factory.test("should nothing", ci1.call){ },
117
- Factory.test("should pass", ci1.call){ assert(1==1); refute(1==0) },
118
- Factory.test("should fail", ci1.call){ ignore; assert(1==0); refute(1==1) },
119
- Factory.test("should ignore", ci1.call){ ignore },
120
- Factory.test("should skip", ci1.call){ skip; ignore; assert(1==1) },
121
- Factory.test("should error", ci1.call){ raise Exception; ignore; assert(1==1) }
115
+ Factory.test("should nothing", ci1.call) do
116
+ end,
117
+ Factory.test("should pass", ci1.call) do
118
+ assert(1 == 1)
119
+ refute(1 == 0)
120
+ end,
121
+ Factory.test("should fail", ci1.call) do
122
+ ignore
123
+ assert(1 == 0)
124
+ refute(1 == 1)
125
+ end,
126
+ Factory.test("should ignore", ci1.call) do
127
+ ignore
128
+ end,
129
+ Factory.test("should skip", ci1.call) do
130
+ skip
131
+ ignore
132
+ assert(1 == 1)
133
+ end,
134
+ Factory.test("should error", ci1.call) do
135
+ raise Exception
136
+ ignore # rubocop:disable Lint/UnreachableCode
137
+ assert(1 == 1)
138
+ end,
122
139
  ]
123
- }
140
+ # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands
141
+ end
124
142
 
125
143
  should "know its tests-to-run attrs" do
126
144
  assert_that(subject.tests_to_run_count).equals(tests1.size)
@@ -134,14 +152,14 @@ class Assert::Suite
134
152
 
135
153
  should "find a test to run given a file line" do
136
154
  test = tests1.sample
137
- assert_that(subject.find_test_to_run(test.file_line)).is_the_same_as(test)
155
+ assert_that(subject.find_test_to_run(test.file_line)).is(test)
138
156
  end
139
157
 
140
158
  should "know its sorted tests to run" do
141
159
  sorted_tests = subject.sorted_tests_to_run{ 1 }
142
160
  assert_that(sorted_tests.size).equals(tests1.size)
143
161
  assert_that(sorted_tests.first).is_kind_of(Assert::Test)
144
- assert_that(subject.sorted_tests_to_run{ 1 }.first).is_the_same_as(sorted_tests.first)
162
+ assert_that(subject.sorted_tests_to_run{ 1 }.first).is(sorted_tests.first)
145
163
  end
146
164
  end
147
165
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/test"
3
5
 
@@ -8,14 +10,18 @@ require "assert/result"
8
10
  class Assert::Test
9
11
  class UnitTests < Assert::Context
10
12
  desc "Assert::Test"
11
- subject { Assert::Test }
13
+ subject{ unit_class }
14
+
15
+ let(:unit_class){ Assert::Test }
12
16
 
13
- let(:context_class1) { Factory.modes_off_context_class { desc "context class" } }
14
- let(:context_info1) { Factory.context_info(context_class1) }
15
- let(:config1) { Factory.modes_off_config }
16
- let(:test_code1) { proc { assert(true) } }
17
+ let(:context_class1) do
18
+ Factory.modes_off_context_class{ desc "context class" }
19
+ end
20
+ let(:context_info1){ Factory.context_info(context_class1) }
21
+ let(:config1){ Factory.modes_off_config }
22
+ let(:test_code1){ proc{ assert(true) } }
17
23
 
18
- should have_imeths :name_file_line_context_data, :for_block, :for_method
24
+ should have_imeths :name_file_line_context_data, :for_block
19
25
 
20
26
  should "know how to build the name and file line given context" do
21
27
  test_name = Factory.string
@@ -42,51 +48,30 @@ class Assert::Test
42
48
  assert_that(test.config).equals(config1)
43
49
  assert_that(test.code).equals(test_code1)
44
50
  end
45
-
46
- should "build tests for a method" do
47
- meth = "a_test_method"
48
- test = subject.for_method(meth, context_info1, config1)
49
-
50
- exp = Assert::FileLine.parse(context_info1.called_from)
51
- assert_that(test.file_line).equals(exp)
52
-
53
- exp = context_info1.test_name(meth)
54
- assert_that(test.name).equals(exp)
55
-
56
- assert_that(test.context_info).equals(context_info1)
57
- assert_that(test.config).equals(config1)
58
-
59
- assert_that(test.code).is_kind_of(Proc)
60
- self.instance_eval(&test.code)
61
- assert_that(@a_test_method_called).is_true
62
- end
63
-
64
- def a_test_method
65
- @a_test_method_called = true
66
- end
67
51
  end
68
52
 
69
53
  class InitWithDataTests < UnitTests
70
54
  desc "when init with data"
71
- subject { test1 }
55
+ subject{ unit_class.new(meta_data1.merge(run_data1)) }
72
56
 
73
- let(:file_line1) { Assert::FileLine.new(Factory.string, Factory.integer.to_s) }
74
- let(:meta_data1) {
57
+ let(:file_line1) do
58
+ Assert::FileLine.new(Factory.string, Factory.integer.to_s)
59
+ end
60
+ let(:meta_data1) do
75
61
  {
76
- :file_line => file_line1.to_s,
77
- :name => Factory.string,
78
- :output => Factory.string,
79
- :run_time => Factory.float(1.0),
62
+ file_line: file_line1.to_s,
63
+ name: Factory.string,
64
+ output: Factory.string,
65
+ run_time: Factory.float(1.0),
80
66
  }
81
- }
82
- let(:run_data1) {
67
+ end
68
+ let(:run_data1) do
83
69
  {
84
- :context_info => context_info1,
85
- :config => config1,
86
- :code => test_code1
70
+ context_info: context_info1,
71
+ config: config1,
72
+ code: test_code1,
87
73
  }
88
- }
89
- let(:test1) { Assert::Test.new(meta_data1.merge(run_data1)) }
74
+ end
90
75
 
91
76
  should have_imeths :file_line, :file_name, :line_num
92
77
  should have_imeths :name, :output, :run_time
@@ -104,7 +89,7 @@ class Assert::Test
104
89
  end
105
90
 
106
91
  should "default its attrs" do
107
- test = Assert::Test.new
92
+ test = unit_class.new
108
93
 
109
94
  assert_that(test.file_line).equals(Assert::FileLine.parse(""))
110
95
  assert_that(test.name).equals("")
@@ -126,9 +111,12 @@ class Assert::Test
126
111
  end
127
112
 
128
113
  should "have a custom inspect that only shows limited attributes" do
129
- attrs = [:name, :context_info].collect do |method|
130
- "@#{method}=#{subject.send(method).inspect}"
131
- end.join(" ")
114
+ attrs =
115
+ [:name, :context_info]
116
+ .map{ |method|
117
+ "@#{method}=#{subject.send(method).inspect}"
118
+ }
119
+ .join(" ")
132
120
  exp = "#<#{subject.class}:#{"0x0%x" % (subject.object_id << 1)} #{attrs}>"
133
121
  assert_that(subject.inspect).equals(exp)
134
122
  end
@@ -137,7 +125,13 @@ class Assert::Test
137
125
  class PassFailIgnoreHandlingTests < UnitTests
138
126
  include Assert::Test::TestHelpers
139
127
 
140
- subject { test1 }
128
+ subject do
129
+ Factory.test("pass fail ignore test", context_info1) do
130
+ ignore("something")
131
+ assert(true)
132
+ assert(false)
133
+ end
134
+ end
141
135
 
142
136
  setup do
143
137
  subject.context_class.setup do
@@ -153,14 +147,6 @@ class Assert::Test
153
147
  subject.run(&test_run_callback)
154
148
  end
155
149
 
156
- let(:test1) {
157
- Factory.test("pass fail ignore test", context_info1) do
158
- ignore("something")
159
- assert(true)
160
- assert(false)
161
- end
162
- }
163
-
164
150
  should "capture results in the test and any setups/teardowns" do
165
151
  assert_that(test_run_results.size).equals(9)
166
152
  test_run_results.each do |result|
@@ -205,7 +191,7 @@ class Assert::Test
205
191
  end
206
192
 
207
193
  should "capture fails in the context setup" do
208
- test = Factory.test("setup halt-on-fail test", context_info1){ }
194
+ test = Factory.test("setup halt-on-fail test", context_info1){}
209
195
  test.context_class.setup{ raise Assert::Result::TestFailure }
210
196
  test.run(&test_run_callback)
211
197
 
@@ -213,7 +199,7 @@ class Assert::Test
213
199
  end
214
200
 
215
201
  should "capture fails in the context teardown" do
216
- test = Factory.test("teardown halt-on-fail test", context_info1){ }
202
+ test = Factory.test("teardown halt-on-fail test", context_info1){}
217
203
  test.context_class.teardown{ raise Assert::Result::TestFailure }
218
204
  test.run(&test_run_callback)
219
205
 
@@ -222,11 +208,13 @@ class Assert::Test
222
208
 
223
209
  private
224
210
 
225
- def assert_failed(test)
211
+ def assert_failed(_test)
226
212
  with_backtrace(caller) do
227
- assert_that(test_run_result_count).equals(1, "too many/few fail results")
213
+ assert_that(test_run_result_count)
214
+ .equals(1, "too many/few fail results")
228
215
  test_run_results.each do |result|
229
- assert_that(result).is_kind_of(Assert::Result::Fail, "not a fail result")
216
+ assert_that(result)
217
+ .is_kind_of(Assert::Result::Fail, "not a fail result")
230
218
  end
231
219
  end
232
220
  end
@@ -243,7 +231,7 @@ class Assert::Test
243
231
  end
244
232
 
245
233
  should "capture skips in the context setup" do
246
- test = Factory.test("setup skip test", context_info1){ }
234
+ test = Factory.test("setup skip test", context_info1){}
247
235
  test.context_class.setup{ skip }
248
236
  test.run(&test_run_callback)
249
237
 
@@ -251,7 +239,7 @@ class Assert::Test
251
239
  end
252
240
 
253
241
  should "capture skips in the context teardown" do
254
- test = Factory.test("teardown skip test", context_info1){ }
242
+ test = Factory.test("teardown skip test", context_info1){}
255
243
  test.context_class.teardown{ skip }
256
244
  test.run(&test_run_callback)
257
245
 
@@ -260,11 +248,13 @@ class Assert::Test
260
248
 
261
249
  private
262
250
 
263
- def assert_skipped(test)
251
+ def assert_skipped(_test)
264
252
  with_backtrace(caller) do
265
- assert_that(test_run_result_count).equals(1, "too many/few skip results")
253
+ assert_that(test_run_result_count)
254
+ .equals(1, "too many/few skip results")
266
255
  test_run_results.each do |result|
267
- assert_that(result).is_kind_of(Assert::Result::Skip, "not a skip result")
256
+ assert_that(result)
257
+ .is_kind_of(Assert::Result::Skip, "not a skip result")
268
258
  end
269
259
  end
270
260
  end
@@ -283,7 +273,7 @@ class Assert::Test
283
273
  end
284
274
 
285
275
  should "capture errors in the context setup" do
286
- test = Factory.test("setup error test", context_info1){ }
276
+ test = Factory.test("setup error test", context_info1){}
287
277
  test.context_class.setup{ raise "an error" }
288
278
  test.run(&test_run_callback)
289
279
 
@@ -291,7 +281,7 @@ class Assert::Test
291
281
  end
292
282
 
293
283
  should "capture errors in the context teardown" do
294
- test = Factory.test("teardown error test", context_info1){ }
284
+ test = Factory.test("teardown error test", context_info1){}
295
285
  test.context_class.teardown{ raise "an error" }
296
286
  test.run(&test_run_callback)
297
287
 
@@ -300,11 +290,13 @@ class Assert::Test
300
290
 
301
291
  private
302
292
 
303
- def assert_errored(test)
293
+ def assert_errored(_test)
304
294
  with_backtrace(caller) do
305
- assert_that(test_run_result_count).equals(1, "too many/few error results")
295
+ assert_that(test_run_result_count)
296
+ .equals(1, "too many/few error results")
306
297
  test_run_results.each do |result|
307
- assert_that(result).is_kind_of(Assert::Result::Error, "not an error result")
298
+ assert_that(result)
299
+ .is_kind_of(Assert::Result::Error, "not an error result")
308
300
  end
309
301
  end
310
302
  end
@@ -316,90 +308,84 @@ class Assert::Test
316
308
  raise SignalException, "USR1"
317
309
  end
318
310
 
319
- assert_that(-> { test.run }).raises(SignalException)
311
+ assert_that{ test.run }.raises(SignalException)
320
312
  end
321
313
 
322
314
  should "raises signal exceptions in the context setup" do
323
- test = Factory.test("setup signal test", context_info1){ }
315
+ test = Factory.test("setup signal test", context_info1){}
324
316
  test.context_class.setup{ raise SignalException, "INT" }
325
317
 
326
- assert_that(-> { test.run }).raises(SignalException)
318
+ assert_that{ test.run }.raises(SignalException)
327
319
  end
328
320
 
329
321
  should "raises signal exceptions in the context teardown" do
330
- test = Factory.test("teardown signal test", context_info1){ }
322
+ test = Factory.test("teardown signal test", context_info1){}
331
323
  test.context_class.teardown{ raise SignalException, "TERM" }
332
324
 
333
- assert_that(-> { test.run }).raises(SignalException)
325
+ assert_that{ test.run }.raises(SignalException)
334
326
  end
335
327
  end
336
328
 
337
329
  class ComparingTests < UnitTests
338
330
  desc "<=> another test"
339
- subject { test1 }
340
-
341
- let(:test1) { Factory.test("mmm") }
331
+ subject{ Factory.test("mmm") }
342
332
 
343
333
  should "return 1 with a test named 'aaa' (greater than it)" do
344
- result = test1 <=> Factory.test("aaa")
345
- assert_that(result).equals(1)
334
+ assert_that(subject <=> Factory.test("aaa")).equals(1)
346
335
  end
347
336
 
348
337
  should "return 0 with a test named the same" do
349
- result = test1 <=> Factory.test(test1.name)
350
- assert_that(result).equals(0)
338
+ assert_that(subject <=> Factory.test(subject.name)).equals(0)
351
339
  end
352
340
 
353
341
  should "return -1 with a test named 'zzz' (less than it)" do
354
- result = test1 <=> Factory.test("zzz")
355
- assert_that(result).equals(-1)
342
+ assert_that(subject <=> Factory.test("zzz")).equals(-1)
356
343
  end
357
344
  end
358
345
 
359
346
  class CaptureOutTests < UnitTests
360
347
  desc "when capturing std out"
361
-
362
- let(:capture_config1) { Assert::Config.new(:capture_output => true) }
363
- let(:test1) {
348
+ subject do
364
349
  Factory.test("stdout", capture_config1) do
365
350
  puts "std out from the test"
366
351
  assert true
367
352
  end
368
- }
353
+ end
354
+
355
+ let(:capture_config1){ Assert::Config.new(capture_output: true) }
369
356
 
370
357
  should "capture any io from the test" do
371
- test1.run
372
- assert_that(test1.output).equals("std out from the test\n")
358
+ subject.run
359
+ assert_that(subject.output).equals("std out from the test\n")
373
360
  end
374
361
  end
375
362
 
376
363
  class FullCaptureOutTests < CaptureOutTests
377
364
  desc "across setup, teardown, and meth calls"
365
+ subject do
366
+ Factory.test("fullstdouttest", capture_config1) do
367
+ puts "std out from the test"
368
+ assert a_method_an_assert_calls
369
+ end
370
+ end
378
371
 
379
372
  setup do
380
- test1.context_class.setup{ puts "std out from the setup" }
381
- test1.context_class.teardown{ puts "std out from the teardown" }
382
- test1.context_class.send(:define_method, "a_method_an_assert_calls") do
373
+ subject.context_class.setup{ puts "std out from the setup" }
374
+ subject.context_class.teardown{ puts "std out from the teardown" }
375
+ subject.context_class.send(:define_method, "a_method_an_assert_calls") do
383
376
  puts "std out from a method an assert called"
384
377
  end
385
378
  end
386
379
 
387
- let(:test1) {
388
- Factory.test("fullstdouttest", capture_config1) do
389
- puts "std out from the test"
390
- assert a_method_an_assert_calls
391
- end
392
- }
393
-
394
380
  should "collect all stdout in the output accessor" do
395
- test1.run
381
+ subject.run
396
382
 
397
383
  exp_out =
398
384
  "std out from the setup\n"\
399
385
  "std out from the test\n"\
400
386
  "std out from a method an assert called\n"\
401
387
  "std out from the teardown\n"
402
- assert_that(test1.output).equals(exp_out)
388
+ assert_that(subject.output).equals(exp_out)
403
389
  end
404
390
  end
405
391
  end