assert 2.15.2 → 2.16.0

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 (41) hide show
  1. checksums.yaml +5 -5
  2. data/lib/assert/assertions.rb +6 -0
  3. data/lib/assert/config_helpers.rb +35 -14
  4. data/lib/assert/context.rb +36 -43
  5. data/lib/assert/context/test_dsl.rb +4 -4
  6. data/lib/assert/default_suite.rb +35 -40
  7. data/lib/assert/default_view.rb +109 -37
  8. data/lib/assert/file_line.rb +1 -1
  9. data/lib/assert/result.rb +67 -27
  10. data/lib/assert/runner.rb +14 -10
  11. data/lib/assert/suite.rb +41 -50
  12. data/lib/assert/test.rb +39 -81
  13. data/lib/assert/version.rb +1 -1
  14. data/lib/assert/view_helpers.rb +11 -21
  15. data/test/helper.rb +40 -0
  16. data/test/system/test_tests.rb +90 -88
  17. data/test/unit/assertions/assert_block_tests.rb +14 -10
  18. data/test/unit/assertions/assert_empty_tests.rb +14 -10
  19. data/test/unit/assertions/assert_equal_tests.rb +22 -14
  20. data/test/unit/assertions/assert_file_exists_tests.rb +14 -10
  21. data/test/unit/assertions/assert_includes_tests.rb +14 -10
  22. data/test/unit/assertions/assert_instance_of_tests.rb +14 -10
  23. data/test/unit/assertions/assert_kind_of_tests.rb +14 -10
  24. data/test/unit/assertions/assert_match_tests.rb +14 -10
  25. data/test/unit/assertions/assert_nil_tests.rb +14 -10
  26. data/test/unit/assertions/assert_raises_tests.rb +14 -10
  27. data/test/unit/assertions/assert_respond_to_tests.rb +14 -10
  28. data/test/unit/assertions/assert_same_tests.rb +20 -14
  29. data/test/unit/assertions/assert_true_false_tests.rb +28 -20
  30. data/test/unit/assertions_tests.rb +12 -9
  31. data/test/unit/config_helpers_tests.rb +72 -13
  32. data/test/unit/context/test_dsl_tests.rb +38 -45
  33. data/test/unit/context_tests.rb +12 -8
  34. data/test/unit/default_suite_tests.rb +66 -43
  35. data/test/unit/file_line_tests.rb +4 -1
  36. data/test/unit/result_tests.rb +71 -47
  37. data/test/unit/runner_tests.rb +34 -16
  38. data/test/unit/suite_tests.rb +61 -29
  39. data/test/unit/test_tests.rb +97 -134
  40. data/test/unit/view_helpers_tests.rb +17 -31
  41. metadata +2 -2
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertTrueTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_true`"
10
12
  setup do
11
13
  desc = @desc = "assert true fail desc"
@@ -15,24 +17,26 @@ module Assert::Assertions
15
17
  assert_true(*args) # fail
16
18
  end
17
19
  @c = @test.config
18
- @test.run
20
+ @test.run(&test_run_callback)
19
21
  end
20
22
  subject{ @test }
21
23
 
22
24
  should "produce results as expected" do
23
- assert_equal 2, subject.result_count
24
- assert_equal 1, subject.result_count(:pass)
25
- assert_equal 1, subject.result_count(:fail)
25
+ assert_equal 2, test_run_result_count
26
+ assert_equal 1, test_run_result_count(:pass)
27
+ assert_equal 1, test_run_result_count(:fail)
26
28
  end
27
29
 
28
30
  should "have a fail message with custom and generic explanations" do
29
31
  exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to be true."
30
- assert_equal exp, subject.fail_results.first.message
32
+ assert_equal exp, test_run_results(:fail).first.message
31
33
  end
32
34
 
33
35
  end
34
36
 
35
37
  class AssertNotTrueTests < Assert::Context
38
+ include Assert::Test::TestHelpers
39
+
36
40
  desc "`assert_not_true`"
37
41
  setup do
38
42
  desc = @desc = "assert not true fail desc"
@@ -42,24 +46,26 @@ module Assert::Assertions
42
46
  assert_not_true(*args) # fail
43
47
  end
44
48
  @c = @test.config
45
- @test.run
49
+ @test.run(&test_run_callback)
46
50
  end
47
51
  subject{ @test }
48
52
 
49
53
  should "produce results as expected" do
50
- assert_equal 2, subject.result_count
51
- assert_equal 1, subject.result_count(:pass)
52
- assert_equal 1, subject.result_count(:fail)
54
+ assert_equal 2, test_run_result_count
55
+ assert_equal 1, test_run_result_count(:pass)
56
+ assert_equal 1, test_run_result_count(:fail)
53
57
  end
54
58
 
55
59
  should "have a fail message with custom and generic explanations" do
56
60
  exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to not be true."
57
- assert_equal exp, subject.fail_results.first.message
61
+ assert_equal exp, test_run_results(:fail).first.message
58
62
  end
59
63
 
60
64
  end
61
65
 
62
66
  class AssertFalseTests < Assert::Context
67
+ include Assert::Test::TestHelpers
68
+
63
69
  desc "`assert_false`"
64
70
  setup do
65
71
  desc = @desc = "assert false fail desc"
@@ -69,24 +75,26 @@ module Assert::Assertions
69
75
  assert_false(*args) # fail
70
76
  end
71
77
  @c = @test.config
72
- @test.run
78
+ @test.run(&test_run_callback)
73
79
  end
74
80
  subject{ @test }
75
81
 
76
82
  should "produce results as expected" do
77
- assert_equal 2, subject.result_count
78
- assert_equal 1, subject.result_count(:pass)
79
- assert_equal 1, subject.result_count(:fail)
83
+ assert_equal 2, test_run_result_count
84
+ assert_equal 1, test_run_result_count(:pass)
85
+ assert_equal 1, test_run_result_count(:fail)
80
86
  end
81
87
 
82
88
  should "have a fail message with custom and generic explanations" do
83
89
  exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to be false."
84
- assert_equal exp, subject.fail_results.first.message
90
+ assert_equal exp, test_run_results(:fail).first.message
85
91
  end
86
92
 
87
93
  end
88
94
 
89
95
  class AssertNotFalseTests < Assert::Context
96
+ include Assert::Test::TestHelpers
97
+
90
98
  desc "`assert_not_false`"
91
99
  setup do
92
100
  desc = @desc = "assert not false fail desc"
@@ -96,19 +104,19 @@ module Assert::Assertions
96
104
  assert_not_false(*args) # fail
97
105
  end
98
106
  @c = @test.config
99
- @test.run
107
+ @test.run(&test_run_callback)
100
108
  end
101
109
  subject{ @test }
102
110
 
103
111
  should "produce results as expected" do
104
- assert_equal 2, subject.result_count
105
- assert_equal 1, subject.result_count(:pass)
106
- assert_equal 1, subject.result_count(:fail)
112
+ assert_equal 2, test_run_result_count
113
+ assert_equal 1, test_run_result_count(:pass)
114
+ assert_equal 1, test_run_result_count(:fail)
107
115
  end
108
116
 
109
117
  should "have a fail message with custom and generic explanations" do
110
118
  exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to not be false."
111
- assert_equal exp, subject.fail_results.first.message
119
+ assert_equal exp, test_run_results(:fail).first.message
112
120
  end
113
121
 
114
122
  end
@@ -4,6 +4,8 @@ require 'assert/assertions'
4
4
  module Assert::Assertions
5
5
 
6
6
  class UnitTests < Assert::Context
7
+ include Assert::Test::TestHelpers
8
+
7
9
  desc "Assert::Context"
8
10
  setup do
9
11
  @context_class = Factory.modes_off_context_class
@@ -43,23 +45,24 @@ module Assert::Assertions
43
45
  self.send(helper, "doesn't matter")
44
46
  end
45
47
  end
46
- @expected_messages = Assert::Assertions::IGNORED_ASSERTION_HELPERS.map do |helper|
47
- "The assertion `#{helper}` is not supported."\
48
- " Please use another assertion or the basic `assert`."
49
- end
50
- @results = @tests.map(&:run).flatten
48
+ @tests.each{ |test| test.run(&test_run_callback) }
51
49
  end
52
- subject{ @results }
53
50
 
54
51
  should "have an ignored result for each helper in the constant" do
55
- subject.each do |result|
52
+ exp = Assert::Assertions::IGNORED_ASSERTION_HELPERS.size
53
+ assert_equal exp, test_run_result_count
54
+
55
+ test_run_results.each do |result|
56
56
  assert_kind_of Assert::Result::Ignore, result
57
57
  end
58
- assert_equal(Assert::Assertions::IGNORED_ASSERTION_HELPERS.size, subject.size)
59
58
  end
60
59
 
61
60
  should "have a custom ignore message for each helper in the constant" do
62
- assert_equal(@expected_messages, subject.collect(&:message))
61
+ exp = Assert::Assertions::IGNORED_ASSERTION_HELPERS.map do |helper|
62
+ "The assertion `#{helper}` is not supported."\
63
+ " Please use another assertion or the basic `assert`."
64
+ end
65
+ assert_equal exp, test_run_results.collect(&:message)
63
66
  end
64
67
 
65
68
  end
@@ -23,9 +23,14 @@ module Assert::ConfigHelpers
23
23
 
24
24
  should have_imeths :runner, :suite, :view
25
25
  should have_imeths :runner_seed, :single_test?, :single_test_file_line
26
- should have_imeths :count, :tests?, :all_pass?
27
- should have_imeths :formatted_run_time
26
+ should have_imeths :tests_to_run?, :tests_to_run_count
27
+ should have_imeths :test_count, :result_count, :pass_result_count
28
+ should have_imeths :fail_result_count, :error_result_count
29
+ should have_imeths :skip_result_count, :ignore_result_count
30
+ should have_imeths :all_pass?, :formatted_run_time
28
31
  should have_imeths :formatted_test_rate, :formatted_result_rate
32
+ should have_imeths :formatted_suite_run_time
33
+ should have_imeths :formatted_suite_test_rate, :formatted_suite_result_rate
29
34
  should have_imeths :show_test_profile_info?, :show_test_verbose_info?
30
35
  should have_imeths :ocurring_result_types
31
36
 
@@ -52,27 +57,77 @@ module Assert::ConfigHelpers
52
57
  assert_equal exp, subject.single_test_file_line
53
58
  end
54
59
 
55
- should "know how to count things on the suite" do
56
- thing = [:pass, :fail, :results, :tests].sample
57
- assert_equal subject.config.suite.count(thing), subject.count(thing)
60
+ should "know its tests-to-run attrs" do
61
+ exp = subject.config.suite.tests_to_run?
62
+ assert_equal exp, subject.tests_to_run?
63
+
64
+ exp = subject.config.suite.tests_to_run_count
65
+ assert_equal exp, subject.tests_to_run_count
58
66
  end
59
67
 
60
- should "know if it has tests or not" do
61
- exp = subject.count(:tests) > 0
62
- assert_equal exp, subject.tests?
68
+ should "know its test/result counts" do
69
+ exp = subject.config.suite.test_count
70
+ assert_equal exp, subject.test_count
71
+
72
+ exp = subject.config.suite.result_count
73
+ assert_equal exp, subject.result_count
74
+
75
+ exp = subject.config.suite.pass_result_count
76
+ assert_equal exp, subject.pass_result_count
77
+
78
+ exp = subject.config.suite.fail_result_count
79
+ assert_equal exp, subject.fail_result_count
80
+
81
+ exp = subject.config.suite.error_result_count
82
+ assert_equal exp, subject.error_result_count
83
+
84
+ exp = subject.config.suite.skip_result_count
85
+ assert_equal exp, subject.skip_result_count
86
+
87
+ exp = subject.config.suite.ignore_result_count
88
+ assert_equal exp, subject.ignore_result_count
89
+ end
90
+
91
+ should "know if all tests are passing or not" do
92
+ result_count = Factory.integer
93
+ Assert.stub(subject, :result_count){ result_count }
94
+ Assert.stub(subject, :pass_result_count){ result_count }
95
+ assert_true subject.all_pass?
96
+
97
+ Assert.stub(subject, :pass_result_count){ Factory.integer }
98
+ assert_false subject.all_pass?
63
99
  end
64
100
 
65
101
  should "know its formatted run time, test rate and result rate" do
66
102
  format = '%.6f'
67
103
 
104
+ run_time = Factory.float
105
+ exp = format % run_time
106
+ assert_equal exp, subject.formatted_run_time(run_time, format)
107
+ assert_equal exp, subject.formatted_run_time(run_time)
108
+
109
+ test_rate = Factory.float
110
+ exp = format % test_rate
111
+ assert_equal exp, subject.formatted_result_rate(test_rate, format)
112
+ assert_equal exp, subject.formatted_result_rate(test_rate)
113
+
114
+ result_rate = Factory.float
115
+ exp = format % result_rate
116
+ assert_equal exp, subject.formatted_result_rate(result_rate, format)
117
+ assert_equal exp, subject.formatted_result_rate(result_rate)
118
+ end
119
+
120
+ should "know its formatted suite run time, test rate and result rate" do
121
+ format = '%.6f'
122
+
68
123
  exp = format % subject.config.suite.run_time
69
- assert_equal exp, subject.formatted_run_time(format)
124
+ assert_equal exp, subject.formatted_suite_run_time(format)
70
125
 
71
126
  exp = format % subject.config.suite.test_rate
72
- assert_equal exp, subject.formatted_test_rate(format)
127
+ assert_equal exp, subject.formatted_suite_test_rate(format)
73
128
 
74
129
  exp = format % subject.config.suite.result_rate
75
- assert_equal exp, subject.formatted_result_rate(format)
130
+ assert_equal exp, subject.formatted_suite_result_rate(format)
76
131
  end
77
132
 
78
133
  should "know whether to show test profile info" do
@@ -84,8 +139,12 @@ module Assert::ConfigHelpers
84
139
  end
85
140
 
86
141
  should "know what result types occur in a suite's results" do
87
- exp = [:pass, :fail, :ignore, :skip, :error].select do |result_sym|
88
- subject.count(result_sym) > 0
142
+ result_types = [:pass, :fail, :ignore, :skip, :error]
143
+ result_count = Factory.integer
144
+ Assert.stub(subject, "#{result_types.sample}_result_count"){ result_count }
145
+
146
+ exp = result_types.select do |type_sym|
147
+ subject.send("#{type_sym}_result_count") > 0
89
148
  end
90
149
  assert_equal exp, subject.ocurring_result_types
91
150
  end
@@ -12,100 +12,94 @@ module Assert::Context::TestDSL
12
12
 
13
13
  should "build a test using `test` with a desc and code block" do
14
14
  d, b = @test_desc, @test_block
15
- context_class = Factory.modes_off_context_class{ test(d, &b) }
15
+ context, test = build_eval_context{ test(d, &b) }
16
16
 
17
- assert_equal 1, context_class.suite.tests.size
17
+ assert_equal 1, context.class.suite.tests_to_run_count
18
18
 
19
- exp_test_name = @test_desc
20
- built_test = context_class.suite.tests.first
21
-
22
- assert_kind_of Assert::Test, built_test
23
- assert_equal exp_test_name, built_test.name
24
- assert_equal @test_block, built_test.code
19
+ assert_kind_of Assert::Test, test
20
+ assert_equal @test_desc, test.name
21
+ assert_equal @test_block, test.code
25
22
  end
26
23
 
27
24
  should "build a test using `should` with a desc and code block" do
28
25
  d, b = @test_desc, @test_block
29
- context_class = Factory.modes_off_context_class{ should(d, &b) }
30
-
31
- assert_equal 1, context_class.suite.tests.size
26
+ context, test = build_eval_context{ should(d, &b) }
32
27
 
33
- exp_test_name = "should #{@test_desc}"
34
- built_test = context_class.suite.tests.last
28
+ assert_equal 1, context.class.suite.tests_to_run_count
35
29
 
36
- assert_kind_of Assert::Test, built_test
37
- assert_equal exp_test_name, built_test.name
38
- assert_equal @test_block, built_test.code
30
+ assert_kind_of Assert::Test, test
31
+ assert_equal "should #{@test_desc}", test.name
32
+ assert_equal @test_block, test.code
39
33
  end
40
34
 
41
35
  should "build a test that skips with no msg when `test_eventually` called" do
42
36
  d, b = @test_desc, @test_block
43
- context = build_eval_context{ test_eventually(d, &b) }
37
+ context, test = build_eval_context{ test_eventually(d, &b) }
44
38
  err = capture_err(Assert::Result::TestSkipped) do
45
- context.instance_eval(&context.class.suite.tests.last.code)
39
+ context.instance_eval(&test.code)
46
40
  end
47
41
 
48
- assert_equal 1, context.class.suite.tests.size
42
+ assert_equal 1, context.class.suite.tests_to_run_count
49
43
  assert_equal 'TODO', err.message
50
44
  assert_equal 1, err.backtrace.size
51
45
  end
52
46
 
53
47
  should "build a test that skips with no msg when `should_eventually` called" do
54
48
  d, b = @test_desc, @test_block
55
- context = build_eval_context{ should_eventually(d, &b) }
49
+ context, test = build_eval_context{ should_eventually(d, &b) }
56
50
  err = capture_err(Assert::Result::TestSkipped) do
57
- context.instance_eval(&context.class.suite.tests.last.code)
51
+ context.instance_eval(&test.code)
58
52
  end
59
53
 
60
- assert_equal 1, context.class.suite.tests.size
54
+ assert_equal 1, context.class.suite.tests_to_run_count
61
55
  assert_equal 'TODO', err.message
62
56
  assert_equal 1, err.backtrace.size
63
57
  end
64
58
 
65
59
  should "skip with the msg \"TODO\" when `test` called with no block" do
66
60
  d = @test_desc
67
- context = build_eval_context { test(d) } # no block passed
61
+ context, test = build_eval_context { test(d) } # no block passed
68
62
  err = capture_err(Assert::Result::TestSkipped) do
69
- context.instance_eval(&context.class.suite.tests.last.code)
63
+ context.instance_eval(&test.code)
70
64
  end
71
65
 
72
- assert_equal 1, context.class.suite.tests.size
66
+ assert_equal 1, context.class.suite.tests_to_run_count
73
67
  assert_equal 'TODO', err.message
74
68
  assert_equal 1, err.backtrace.size
75
69
  end
76
70
 
77
71
  should "skip with the msg \"TODO\" when `should` called with no block" do
78
72
  d = @test_desc
79
- context = build_eval_context { should(d) } # no block passed
73
+ context, test = build_eval_context { should(d) } # no block passed
80
74
  err = capture_err(Assert::Result::TestSkipped) do
81
- context.instance_eval(&context.class.suite.tests.last.code)
75
+ context.instance_eval(&test.code)
82
76
  end
83
77
 
84
- assert_equal 1, context.class.suite.tests.size
78
+ assert_equal 1, context.class.suite.tests_to_run_count
85
79
  assert_equal 'TODO', err.message
86
80
  assert_equal 1, err.backtrace.size
87
81
  end
88
82
 
89
83
  should "skip with the msg \"TODO\" when `test_eventually` called with no block" do
90
84
  d = @test_desc
91
- context = build_eval_context{ test_eventually(d) } # no block given
85
+ context, test = build_eval_context{ test_eventually(d) } # no block given
92
86
  err = capture_err(Assert::Result::TestSkipped) do
93
- context.instance_eval(&context.class.suite.tests.last.code)
87
+ context.instance_eval(&test.code)
94
88
  end
95
89
 
96
- assert_equal 1, context.class.suite.tests.size
90
+ assert_equal 1, context.class.suite.tests_to_run_count
97
91
  assert_equal 'TODO', err.message
98
92
  assert_equal 1, err.backtrace.size
99
93
  end
100
94
 
101
95
  should "skip with the msg \"TODO\" when `should_eventually` called with no block" do
102
96
  d = @test_desc
103
- context = build_eval_context{ should_eventually(d) } # no block given
97
+ context, test = build_eval_context{ should_eventually(d) } # no block given
104
98
  err = capture_err(Assert::Result::TestSkipped) do
105
- context.instance_eval(&context.class.suite.tests.last.code)
99
+ context.instance_eval(&test.code)
106
100
  end
107
101
 
108
- assert_equal 1, context.class.suite.tests.size
102
+ assert_equal 1, context.class.suite.tests_to_run_count
109
103
  assert_equal 'TODO', err.message
110
104
  assert_equal 1, err.backtrace.size
111
105
  end
@@ -115,7 +109,7 @@ module Assert::Context::TestDSL
115
109
  m = Assert::Macro.new{ test(d, &b); test(d, &b) }
116
110
  context_class = Factory.modes_off_context_class{ test(m) }
117
111
 
118
- assert_equal 2, context_class.suite.tests.size
112
+ assert_equal 2, context_class.suite.tests_to_run_count
119
113
  end
120
114
 
121
115
  should "build a test from a macro using `should`" do
@@ -123,28 +117,28 @@ module Assert::Context::TestDSL
123
117
  m = Assert::Macro.new{ should(d, &b); should(d, &b) }
124
118
  context_class = Factory.modes_off_context_class{ should(m) }
125
119
 
126
- assert_equal 2, context_class.suite.tests.size
120
+ assert_equal 2, context_class.suite.tests_to_run_count
127
121
  end
128
122
 
129
123
  should "build a test that skips from a macro using `test_eventually`" do
130
124
  d, b = @test_desc, @test_block
131
125
  m = Assert::Macro.new{ test(d, &b); test(d, &b) }
132
- context = build_eval_context{ test_eventually(m) }
126
+ context, test = build_eval_context{ test_eventually(m) }
133
127
 
134
- assert_equal 1, context.class.suite.tests.size
128
+ assert_equal 1, context.class.suite.tests_to_run_count
135
129
  assert_raises(Assert::Result::TestSkipped) do
136
- context.instance_eval(&context.class.suite.tests.last.code)
130
+ context.instance_eval(&test.code)
137
131
  end
138
132
  end
139
133
 
140
134
  should "build a test that skips from a macro using `should_eventually`" do
141
135
  d, b = @test_desc, @test_block
142
136
  m = Assert::Macro.new{ should(d, &b); should(d, &b) }
143
- context = build_eval_context{ should_eventually(m) }
137
+ context, test = build_eval_context{ should_eventually(m) }
144
138
 
145
- assert_equal 1, context.class.suite.tests.size
139
+ assert_equal 1, context.class.suite.tests_to_run_count
146
140
  assert_raises(Assert::Result::TestSkipped) do
147
- context.instance_eval(&context.class.suite.tests.last.code)
141
+ context.instance_eval(&test.code)
148
142
  end
149
143
 
150
144
  end
@@ -153,9 +147,8 @@ module Assert::Context::TestDSL
153
147
 
154
148
  def build_eval_context(&build_block)
155
149
  context_class = Factory.modes_off_context_class &build_block
156
- context_info = Factory.context_info(context_class)
157
- test = Factory.test("whatever", context_info)
158
- context_class.new(test, test.config, proc{ |r| })
150
+ test = context_class.suite.sorted_tests_to_run.to_a.last
151
+ [context_class.new(test, test.config, proc{ |r| }), test]
159
152
  end
160
153
 
161
154
  def capture_err(err_class, &block)