assert 2.15.2 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -4,6 +4,8 @@ require 'assert/assertions'
4
4
  module Assert::Assertions
5
5
 
6
6
  class AssertBlockTests < Assert::Context
7
+ include Assert::Test::TestHelpers
8
+
7
9
  desc "`assert_block`"
8
10
  setup do
9
11
  desc = @desc = "assert block fail desc"
@@ -11,24 +13,26 @@ module Assert::Assertions
11
13
  assert_block{ true } # pass
12
14
  assert_block(desc){ false } # fail
13
15
  end
14
- @test.run
16
+ @test.run(&test_run_callback)
15
17
  end
16
18
  subject{ @test }
17
19
 
18
20
  should "produce results as expected" do
19
- assert_equal 2, subject.result_count
20
- assert_equal 1, subject.result_count(:pass)
21
- assert_equal 1, subject.result_count(:fail)
21
+ assert_equal 2, test_run_result_count
22
+ assert_equal 1, test_run_result_count(:pass)
23
+ assert_equal 1, test_run_result_count(:fail)
22
24
  end
23
25
 
24
26
  should "have a fail message with custom and generic explanations" do
25
27
  exp = "#{@desc}\nExpected block to return a true value."
26
- assert_equal exp, subject.fail_results.first.message
28
+ assert_equal exp, test_run_results(:fail).first.message
27
29
  end
28
30
 
29
31
  end
30
32
 
31
33
  class AssertNotBlockTests < Assert::Context
34
+ include Assert::Test::TestHelpers
35
+
32
36
  desc "`assert_not_block`"
33
37
  setup do
34
38
  desc = @desc = "assert not block fail desc"
@@ -36,19 +40,19 @@ module Assert::Assertions
36
40
  assert_not_block(desc){ true } # fail
37
41
  assert_not_block{ false } # pass
38
42
  end
39
- @test.run
43
+ @test.run(&test_run_callback)
40
44
  end
41
45
  subject{ @test }
42
46
 
43
47
  should "produce results as expected" do
44
- assert_equal 2, subject.result_count
45
- assert_equal 1, subject.result_count(:pass)
46
- assert_equal 1, subject.result_count(:fail)
48
+ assert_equal 2, test_run_result_count
49
+ assert_equal 1, test_run_result_count(:pass)
50
+ assert_equal 1, test_run_result_count(:fail)
47
51
  end
48
52
 
49
53
  should "have a fail message with custom and generic explanations" do
50
54
  exp = "#{@desc}\nExpected block to not return a true value."
51
- assert_equal exp, subject.fail_results.first.message
55
+ assert_equal exp, test_run_results(:fail).first.message
52
56
  end
53
57
 
54
58
  end
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertEmptyTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_empty`"
10
12
  setup do
11
13
  desc = @desc = "assert empty fail desc"
@@ -15,24 +17,26 @@ module Assert::Assertions
15
17
  assert_empty(*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 empty."
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 AssertNotEmptyTests < Assert::Context
38
+ include Assert::Test::TestHelpers
39
+
36
40
  desc "`assert_not_empty`"
37
41
  setup do
38
42
  desc = @desc = "assert not empty fail desc"
@@ -42,19 +46,19 @@ module Assert::Assertions
42
46
  assert_not_empty(*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 empty."
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
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertEqualTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_equal`"
10
12
  setup do
11
13
  desc = @desc = "assert equal fail desc"
@@ -15,25 +17,27 @@ module Assert::Assertions
15
17
  assert_equal(*a) # 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 = "#{@a[2]}\nExpected #{Assert::U.show(@a[1], @c)}"\
30
32
  " to be equal to #{Assert::U.show(@a[0], @c)}."
31
- assert_equal exp, subject.fail_results.first.message
33
+ assert_equal exp, test_run_results(:fail).first.message
32
34
  end
33
35
 
34
36
  end
35
37
 
36
38
  class AssertNotEqualTests < Assert::Context
39
+ include Assert::Test::TestHelpers
40
+
37
41
  desc "`assert_not_equal`"
38
42
  setup do
39
43
  desc = @desc = "assert not equal fail desc"
@@ -43,25 +47,27 @@ module Assert::Assertions
43
47
  assert_not_equal(1, 2) # pass
44
48
  end
45
49
  @c = @test.config
46
- @test.run
50
+ @test.run(&test_run_callback)
47
51
  end
48
52
  subject{ @test }
49
53
 
50
54
  should "produce results as expected" do
51
- assert_equal 2, subject.result_count
52
- assert_equal 1, subject.result_count(:pass)
53
- assert_equal 1, subject.result_count(:fail)
55
+ assert_equal 2, test_run_result_count
56
+ assert_equal 1, test_run_result_count(:pass)
57
+ assert_equal 1, test_run_result_count(:fail)
54
58
  end
55
59
 
56
60
  should "have a fail message with custom and generic explanations" do
57
61
  exp = "#{@a[2]}\nExpected #{Assert::U.show(@a[1], @c)}"\
58
62
  " to not be equal to #{Assert::U.show(@a[0], @c)}."
59
- assert_equal exp, subject.fail_results.first.message
63
+ assert_equal exp, test_run_results(:fail).first.message
60
64
  end
61
65
 
62
66
  end
63
67
 
64
68
  class EqualOrderTests < Assert::Context
69
+ include Assert::Test::TestHelpers
70
+
65
71
  desc "with objects that define custom equality operators"
66
72
  setup do
67
73
  is_class = Class.new do
@@ -83,6 +89,8 @@ module Assert::Assertions
83
89
  end
84
90
 
85
91
  class DiffTests < Assert::Context
92
+ include Assert::Test::TestHelpers
93
+
86
94
  desc "with objects that should use diff when showing"
87
95
  setup do
88
96
  @exp_obj = "I'm a\nstring"
@@ -105,14 +113,14 @@ module Assert::Assertions
105
113
  @test = Factory.test(@c) do
106
114
  assert_equal(exp_obj, act_obj)
107
115
  end
108
- @test.run
116
+ @test.run(&test_run_callback)
109
117
  end
110
118
  subject{ @test }
111
119
 
112
120
  should "include diff output in the fail messages" do
113
121
  exp = "Expected does not equal actual, diff:\n"\
114
122
  "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @act_obj_show)}"
115
- assert_equal exp, subject.fail_results.first.message
123
+ assert_equal exp, test_run_results(:fail).first.message
116
124
  end
117
125
 
118
126
  end
@@ -124,14 +132,14 @@ module Assert::Assertions
124
132
  @test = Factory.test(@c) do
125
133
  assert_not_equal(exp_obj, exp_obj)
126
134
  end
127
- @test.run
135
+ @test.run(&test_run_callback)
128
136
  end
129
137
  subject{ @test }
130
138
 
131
139
  should "include diff output in the fail messages" do
132
140
  exp = "Expected equals actual, diff:\n"\
133
141
  "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @exp_obj_show)}"
134
- assert_equal exp, subject.fail_results.first.message
142
+ assert_equal exp, test_run_results(:fail).first.message
135
143
  end
136
144
 
137
145
  end
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertFileExistsTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_file_exists`"
10
12
  setup do
11
13
  desc = @desc = "assert file exists empty fail desc"
@@ -15,24 +17,26 @@ module Assert::Assertions
15
17
  assert_file_exists(*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 exist."
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 AssertNotFileExistsTests < Assert::Context
38
+ include Assert::Test::TestHelpers
39
+
36
40
  desc "`assert_not_file_exists`"
37
41
  setup do
38
42
  desc = @desc = "assert not file exists empty fail desc"
@@ -42,19 +46,19 @@ module Assert::Assertions
42
46
  assert_not_file_exists(*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 exist."
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
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertIncludesTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_includes`"
10
12
  setup do
11
13
  desc = @desc = "assert includes fail desc"
@@ -15,26 +17,28 @@ module Assert::Assertions
15
17
  assert_includes(*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[2]}\n"\
30
32
  "Expected #{Assert::U.show(@args[1], @c)}"\
31
33
  " to include #{Assert::U.show(@args[0], @c)}."
32
- assert_equal exp, subject.fail_results.first.message
34
+ assert_equal exp, test_run_results(:fail).first.message
33
35
  end
34
36
 
35
37
  end
36
38
 
37
39
  class AssertNotIncludedTests < Assert::Context
40
+ include Assert::Test::TestHelpers
41
+
38
42
  desc "`assert_not_included`"
39
43
  setup do
40
44
  desc = @desc = "assert not included fail desc"
@@ -44,21 +48,21 @@ module Assert::Assertions
44
48
  assert_not_included(*args) # fail
45
49
  end
46
50
  @c = @test.config
47
- @test.run
51
+ @test.run(&test_run_callback)
48
52
  end
49
53
  subject{ @test }
50
54
 
51
55
  should "produce results as expected" do
52
- assert_equal 2, subject.result_count
53
- assert_equal 1, subject.result_count(:pass)
54
- assert_equal 1, subject.result_count(:fail)
56
+ assert_equal 2, test_run_result_count
57
+ assert_equal 1, test_run_result_count(:pass)
58
+ assert_equal 1, test_run_result_count(:fail)
55
59
  end
56
60
 
57
61
  should "have a fail message with custom and generic explanations" do
58
62
  exp = "#{@args[2]}\n"\
59
63
  "Expected #{Assert::U.show(@args[1], @c)}"\
60
64
  " to not include #{Assert::U.show(@args[0], @c)}."
61
- assert_equal exp, subject.fail_results.first.message
65
+ assert_equal exp, test_run_results(:fail).first.message
62
66
  end
63
67
 
64
68
  end
@@ -6,6 +6,8 @@ require 'assert/utils'
6
6
  module Assert::Assertions
7
7
 
8
8
  class AssertInstanceOfTests < Assert::Context
9
+ include Assert::Test::TestHelpers
10
+
9
11
  desc "`assert_instance_of`"
10
12
  setup do
11
13
  desc = @desc = "assert instance of fail desc"
@@ -15,25 +17,27 @@ module Assert::Assertions
15
17
  assert_instance_of(*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[2]}\nExpected #{Assert::U.show(@args[1], @c)} (#{@args[1].class})"\
30
32
  " to be an instance of #{@args[0]}."
31
- assert_equal exp, subject.fail_results.first.message
33
+ assert_equal exp, test_run_results(:fail).first.message
32
34
  end
33
35
 
34
36
  end
35
37
 
36
38
  class AssertNotInstanceOfTests < Assert::Context
39
+ include Assert::Test::TestHelpers
40
+
37
41
  desc "`assert_not_instance_of`"
38
42
  setup do
39
43
  desc = @desc = "assert not instance of fail desc"
@@ -43,20 +47,20 @@ module Assert::Assertions
43
47
  assert_not_instance_of(Array, "object") # pass
44
48
  end
45
49
  @c = @test.config
46
- @test.run
50
+ @test.run(&test_run_callback)
47
51
  end
48
52
  subject{ @test }
49
53
 
50
54
  should "produce results as expected" do
51
- assert_equal 2, subject.result_count
52
- assert_equal 1, subject.result_count(:pass)
53
- assert_equal 1, subject.result_count(:fail)
55
+ assert_equal 2, test_run_result_count
56
+ assert_equal 1, test_run_result_count(:pass)
57
+ assert_equal 1, test_run_result_count(:fail)
54
58
  end
55
59
 
56
60
  should "have a fail message with custom and generic explanations" do
57
61
  exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1], @c)} (#{@args[1].class})"\
58
62
  " to not be an instance of #{@args[0]}."
59
- assert_equal exp, subject.fail_results.first.message
63
+ assert_equal exp, test_run_results(:fail).first.message
60
64
  end
61
65
 
62
66
  end