assert 2.17.0 → 2.18.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +66 -41
  4. data/assert.gemspec +2 -3
  5. data/lib/assert.rb +0 -10
  6. data/lib/assert/actual_value.rb +127 -0
  7. data/lib/assert/assert_runner.rb +0 -3
  8. data/lib/assert/assertions.rb +10 -23
  9. data/lib/assert/cli.rb +30 -46
  10. data/lib/assert/config.rb +0 -4
  11. data/lib/assert/config_helpers.rb +0 -4
  12. data/lib/assert/context.rb +18 -9
  13. data/lib/assert/context/let_dsl.rb +13 -0
  14. data/lib/assert/context/method_missing.rb +19 -0
  15. data/lib/assert/context/setup_dsl.rb +0 -4
  16. data/lib/assert/context/subject_dsl.rb +23 -28
  17. data/lib/assert/context/suite_dsl.rb +0 -4
  18. data/lib/assert/context/test_dsl.rb +0 -4
  19. data/lib/assert/context_info.rb +0 -4
  20. data/lib/assert/default_runner.rb +0 -4
  21. data/lib/assert/default_suite.rb +0 -5
  22. data/lib/assert/default_view.rb +0 -4
  23. data/lib/assert/factory.rb +0 -3
  24. data/lib/assert/file_line.rb +0 -4
  25. data/lib/assert/macro.rb +0 -3
  26. data/lib/assert/macros/methods.rb +4 -10
  27. data/lib/assert/result.rb +2 -17
  28. data/lib/assert/runner.rb +0 -3
  29. data/lib/assert/stub.rb +15 -1
  30. data/lib/assert/suite.rb +0 -4
  31. data/lib/assert/test.rb +2 -7
  32. data/lib/assert/utils.rb +0 -4
  33. data/lib/assert/version.rb +1 -1
  34. data/lib/assert/view.rb +0 -3
  35. data/lib/assert/view_helpers.rb +0 -11
  36. data/log/{.gitkeep → .keep} +0 -0
  37. data/test/helper.rb +23 -29
  38. data/test/support/factory.rb +14 -0
  39. data/test/support/inherited_stuff.rb +0 -2
  40. data/test/system/stub_tests.rb +332 -352
  41. data/test/system/test_tests.rb +98 -124
  42. data/test/unit/actual_value_tests.rb +335 -0
  43. data/test/unit/assert_tests.rb +121 -46
  44. data/test/unit/assertions/assert_block_tests.rb +30 -35
  45. data/test/unit/assertions/assert_empty_tests.rb +33 -35
  46. data/test/unit/assertions/assert_equal_tests.rb +75 -83
  47. data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
  48. data/test/unit/assertions/assert_includes_tests.rb +38 -41
  49. data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
  50. data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
  51. data/test/unit/assertions/assert_match_tests.rb +34 -37
  52. data/test/unit/assertions/assert_nil_tests.rb +30 -35
  53. data/test/unit/assertions/assert_raises_tests.rb +54 -60
  54. data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
  55. data/test/unit/assertions/assert_same_tests.rb +86 -88
  56. data/test/unit/assertions/assert_true_false_tests.rb +60 -66
  57. data/test/unit/assertions_tests.rb +14 -17
  58. data/test/unit/config_helpers_tests.rb +41 -39
  59. data/test/unit/config_tests.rb +38 -37
  60. data/test/unit/context/let_dsl_tests.rb +10 -0
  61. data/test/unit/context/setup_dsl_tests.rb +68 -87
  62. data/test/unit/context/subject_dsl_tests.rb +15 -49
  63. data/test/unit/context/suite_dsl_tests.rb +15 -20
  64. data/test/unit/context/test_dsl_tests.rb +50 -57
  65. data/test/unit/context_info_tests.rb +23 -18
  66. data/test/unit/context_tests.rb +183 -194
  67. data/test/unit/default_runner_tests.rb +1 -7
  68. data/test/unit/default_suite_tests.rb +57 -56
  69. data/test/unit/factory_tests.rb +5 -6
  70. data/test/unit/file_line_tests.rb +33 -39
  71. data/test/unit/macro_tests.rb +14 -18
  72. data/test/unit/result_tests.rb +159 -196
  73. data/test/unit/runner_tests.rb +64 -71
  74. data/test/unit/suite_tests.rb +58 -59
  75. data/test/unit/test_tests.rb +125 -136
  76. data/test/unit/utils_tests.rb +43 -54
  77. data/test/unit/view_helpers_tests.rb +54 -58
  78. data/test/unit/view_tests.rb +22 -27
  79. metadata +15 -10
  80. data/tmp/.gitkeep +0 -0
@@ -2,60 +2,55 @@ require "assert"
2
2
  require "assert/assertions"
3
3
 
4
4
  module Assert::Assertions
5
-
6
5
  class AssertBlockTests < Assert::Context
7
6
  include Assert::Test::TestHelpers
8
7
 
9
8
  desc "`assert_block`"
10
- setup do
11
- desc = @desc = "assert block fail desc"
12
- @test = Factory.test do
13
- assert_block{ true } # pass
14
- assert_block(desc){ false } # fail
9
+ subject {
10
+ desc = desc1
11
+ Factory.test do
12
+ assert_block { true } # pass
13
+ assert_block(desc) { false } # fail
15
14
  end
16
- @test.run(&test_run_callback)
17
- end
18
- subject{ @test }
15
+ }
16
+
17
+ let(:desc1) { "assert block fail desc" }
19
18
 
20
19
  should "produce results as expected" do
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)
24
- end
20
+ subject.run(&test_run_callback)
25
21
 
26
- should "have a fail message with custom and generic explanations" do
27
- exp = "#{@desc}\nExpected block to return a true value."
28
- assert_equal exp, test_run_results(:fail).first.message
29
- end
22
+ assert_that(test_run_result_count).equals(2)
23
+ assert_that(test_run_result_count(:pass)).equals(1)
24
+ assert_that(test_run_result_count(:fail)).equals(1)
30
25
 
26
+ exp = "#{desc1}\nExpected block to return a true value."
27
+ assert_that(test_run_results(:fail).first.message).equals(exp)
28
+ end
31
29
  end
32
30
 
33
31
  class AssertNotBlockTests < Assert::Context
34
32
  include Assert::Test::TestHelpers
35
33
 
36
34
  desc "`assert_not_block`"
37
- setup do
38
- desc = @desc = "assert not block fail desc"
39
- @test = Factory.test do
40
- assert_not_block(desc){ true } # fail
41
- assert_not_block{ false } # pass
35
+ subject {
36
+ desc = desc1
37
+ Factory.test do
38
+ assert_not_block(desc) { true } # fail
39
+ assert_not_block { false } # pass
42
40
  end
43
- @test.run(&test_run_callback)
44
- end
45
- subject{ @test }
41
+ }
42
+
43
+ let(:desc1) { "assert not block fail desc" }
46
44
 
47
45
  should "produce results as expected" do
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)
51
- end
46
+ subject.run(&test_run_callback)
52
47
 
53
- should "have a fail message with custom and generic explanations" do
54
- exp = "#{@desc}\nExpected block to not return a true value."
55
- assert_equal exp, test_run_results(:fail).first.message
56
- end
48
+ assert_that(test_run_result_count).equals(2)
49
+ assert_that(test_run_result_count(:pass)).equals(1)
50
+ assert_that(test_run_result_count(:fail)).equals(1)
57
51
 
52
+ exp = "#{desc1}\nExpected block to not return a true value."
53
+ assert_that(test_run_results(:fail).first.message).equals(exp)
54
+ end
58
55
  end
59
-
60
56
  end
61
-
@@ -4,63 +4,61 @@ require "assert/assertions"
4
4
  require "assert/utils"
5
5
 
6
6
  module Assert::Assertions
7
-
8
7
  class AssertEmptyTests < Assert::Context
9
8
  include Assert::Test::TestHelpers
10
9
 
11
10
  desc "`assert_empty`"
12
- setup do
13
- desc = @desc = "assert empty fail desc"
14
- args = @args = [[1], desc]
15
- @test = Factory.test do
11
+ subject {
12
+ args = args1
13
+ Factory.test do
16
14
  assert_empty([]) # pass
17
15
  assert_empty(*args) # fail
18
16
  end
19
- @c = @test.config
20
- @test.run(&test_run_callback)
21
- end
22
- subject{ @test }
17
+ }
18
+
19
+ let(:desc1) { "assert empty fail desc" }
20
+ let(:args1) { [[1], desc1] }
21
+ let(:config1) { subject.config }
23
22
 
24
23
  should "produce results as expected" do
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)
28
- end
24
+ subject.run(&test_run_callback)
29
25
 
30
- should "have a fail message with custom and generic explanations" do
31
- exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to be empty."
32
- assert_equal exp, test_run_results(:fail).first.message
33
- end
26
+ assert_that(test_run_result_count).equals(2)
27
+ assert_that(test_run_result_count(:pass)).equals(1)
28
+ assert_that(test_run_result_count(:fail)).equals(1)
34
29
 
30
+ exp =
31
+ "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be empty."
32
+ assert_that(test_run_results(:fail).first.message).equals(exp)
33
+ end
35
34
  end
36
35
 
37
36
  class AssertNotEmptyTests < Assert::Context
38
37
  include Assert::Test::TestHelpers
39
38
 
40
39
  desc "`assert_not_empty`"
41
- setup do
42
- desc = @desc = "assert not empty fail desc"
43
- args = @args = [[], desc]
44
- @test = Factory.test do
45
- assert_not_empty([1]) # pass
40
+ subject {
41
+ args = args1
42
+ Factory.test do
43
+ assert_not_empty([1]) # pass
46
44
  assert_not_empty(*args) # fail
47
45
  end
48
- @c = @test.config
49
- @test.run(&test_run_callback)
50
- end
51
- subject{ @test }
46
+ }
47
+
48
+ let(:desc1) { "assert not empty fail desc" }
49
+ let(:args1) { [[], desc1] }
50
+ let(:config1) { subject.config }
52
51
 
53
52
  should "produce results as expected" do
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)
57
- end
53
+ subject.run(&test_run_callback)
58
54
 
59
- should "have a fail message with custom and generic explanations" do
60
- exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to not be empty."
61
- assert_equal exp, test_run_results(:fail).first.message
62
- end
55
+ assert_that(test_run_result_count).equals(2)
56
+ assert_that(test_run_result_count(:pass)).equals(1)
57
+ assert_that(test_run_result_count(:fail)).equals(1)
63
58
 
59
+ exp =
60
+ "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be empty."
61
+ assert_that(test_run_results(:fail).first.message).equals(exp)
62
+ end
64
63
  end
65
-
66
64
  end
@@ -4,144 +4,136 @@ require "assert/assertions"
4
4
  require "assert/utils"
5
5
 
6
6
  module Assert::Assertions
7
-
8
7
  class AssertEqualTests < Assert::Context
9
8
  include Assert::Test::TestHelpers
10
9
 
11
10
  desc "`assert_equal`"
12
- setup do
13
- desc = @desc = "assert equal fail desc"
14
- a = @a = ["1", "2", desc]
15
- @test = Factory.test do
16
- assert_equal(1, 1) # pass
17
- assert_equal(*a) # fail
11
+ subject {
12
+ args = args1
13
+ Factory.test do
14
+ assert_equal(1, 1) # pass
15
+ assert_equal(*args) # fail
18
16
  end
19
- @c = @test.config
20
- @test.run(&test_run_callback)
21
- end
22
- subject{ @test }
17
+ }
18
+
19
+ let(:desc1) { "assert equal fail desc" }
20
+ let(:args1) { ["1", "2", desc1] }
21
+ let(:config1) { subject.config }
23
22
 
24
23
  should "produce results as expected" do
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)
28
- end
24
+ subject.run(&test_run_callback)
29
25
 
30
- should "have a fail message with custom and generic explanations" do
31
- exp = "#{@a[2]}\nExpected #{Assert::U.show(@a[1], @c)}"\
32
- " to be equal to #{Assert::U.show(@a[0], @c)}."
33
- assert_equal exp, test_run_results(:fail).first.message
34
- end
26
+ assert_that(test_run_result_count).equals(2)
27
+ assert_that(test_run_result_count(:pass)).equals(1)
28
+ assert_that(test_run_result_count(:fail)).equals(1)
35
29
 
30
+ exp =
31
+ "#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
32
+ " to be equal to #{Assert::U.show(args1[0], config1)}."
33
+ assert_that(test_run_results(:fail).first.message).equals(exp)
34
+ end
36
35
  end
37
36
 
38
37
  class AssertNotEqualTests < Assert::Context
39
38
  include Assert::Test::TestHelpers
40
39
 
41
40
  desc "`assert_not_equal`"
42
- setup do
43
- desc = @desc = "assert not equal fail desc"
44
- a = @a = ["1", "1", desc]
45
- @test = Factory.test do
46
- assert_not_equal(*a) # fail
47
- assert_not_equal(1, 2) # pass
41
+ subject {
42
+ args = args1
43
+ Factory.test do
44
+ assert_not_equal(*args) # fail
45
+ assert_not_equal(1, 2) # pass
48
46
  end
49
- @c = @test.config
50
- @test.run(&test_run_callback)
51
- end
52
- subject{ @test }
47
+ }
48
+
49
+ let(:desc1) { "assert not equal fail desc" }
50
+ let(:args1) { ["1", "1", desc1] }
51
+ let(:config1) { subject.config }
53
52
 
54
53
  should "produce results as expected" do
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)
58
- end
54
+ subject.run(&test_run_callback)
59
55
 
60
- should "have a fail message with custom and generic explanations" do
61
- exp = "#{@a[2]}\nExpected #{Assert::U.show(@a[1], @c)}"\
62
- " to not be equal to #{Assert::U.show(@a[0], @c)}."
63
- assert_equal exp, test_run_results(:fail).first.message
64
- end
56
+ assert_that(test_run_result_count).equals(2)
57
+ assert_that(test_run_result_count(:pass)).equals(1)
58
+ assert_that(test_run_result_count(:fail)).equals(1)
65
59
 
60
+ exp =
61
+ "#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
62
+ " to not be equal to #{Assert::U.show(args1[0], config1)}."
63
+ assert_that(test_run_results(:fail).first.message).equals(exp)
64
+ end
66
65
  end
67
66
 
68
67
  class EqualOrderTests < Assert::Context
69
68
  include Assert::Test::TestHelpers
70
69
 
71
70
  desc "with objects that define custom equality operators"
72
- setup do
73
- is_class = Class.new do
74
- def ==(other); true; end
75
- end
76
- @is = is_class.new
77
71
 
78
- is_not_class = Class.new do
79
- def ==(other); false; end
80
- end
81
- @is_not = is_not_class.new
82
- end
72
+ let(:is_class) { Class.new do; def ==(other); true; end; end }
73
+ let(:is_not_class) { Class.new do; def ==(other); false; end; end }
74
+
75
+ let(:is1) { is_class.new }
76
+ let(:is_not1) { is_not_class.new }
83
77
 
84
78
  should "use the equality operator of the exp value" do
85
- assert_equal @is, @is_not
86
- assert_not_equal @is_not, @is
79
+ assert_that(is1).equals(is_not1)
80
+ assert_that(is_not1).does_not_equal(is1)
87
81
  end
88
-
89
82
  end
90
83
 
91
84
  class DiffTests < Assert::Context
92
85
  include Assert::Test::TestHelpers
93
86
 
94
87
  desc "with objects that should use diff when showing"
95
- setup do
96
- @exp_obj = "I'm a\nstring"
97
- @act_obj = "I am a \nstring"
98
-
99
- @c = Factory.modes_off_config
100
- @c.use_diff_proc(Assert::U.default_use_diff_proc)
101
- @c.run_diff_proc(Assert::U.syscmd_diff_proc)
102
88
 
103
- @exp_obj_show = Assert::U.show_for_diff(@exp_obj, @c)
104
- @act_obj_show = Assert::U.show_for_diff(@act_obj, @c)
105
- end
89
+ let(:config1) {
90
+ Factory.modes_off_config.tap do |config|
91
+ config.use_diff_proc(Assert::U.default_use_diff_proc)
92
+ config.run_diff_proc(Assert::U.syscmd_diff_proc)
93
+ end
94
+ }
106
95
 
96
+ let(:exp_obj1) { "I'm a\nstring" }
97
+ let(:act_obj1) { "I am a \nstring" }
98
+ let(:exp_obj_show1) { Assert::U.show_for_diff(exp_obj1, config1) }
99
+ let(:act_obj_show1) { Assert::U.show_for_diff(act_obj1, config1) }
107
100
  end
108
101
 
109
102
  class AssertEqualDiffTests < DiffTests
110
103
  desc "`assert_equal`"
111
- setup do
112
- exp_obj, act_obj = @exp_obj, @act_obj
113
- @test = Factory.test(@c) do
104
+ subject {
105
+ exp_obj, act_obj = exp_obj1, act_obj1
106
+ Factory.test(config1) do
114
107
  assert_equal(exp_obj, act_obj)
115
108
  end
116
- @test.run(&test_run_callback)
117
- end
118
- subject{ @test }
109
+ }
119
110
 
120
111
  should "include diff output in the fail messages" do
121
- exp = "Expected does not equal actual, diff:\n"\
122
- "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @act_obj_show)}"
123
- assert_equal exp, test_run_results(:fail).first.message
124
- end
112
+ subject.run(&test_run_callback)
125
113
 
114
+ exp =
115
+ "Expected does not equal actual, diff:\n"\
116
+ "#{Assert::U.syscmd_diff_proc.call(exp_obj_show1, act_obj_show1)}"
117
+ assert_that(test_run_results(:fail).first.message).equals(exp)
118
+ end
126
119
  end
127
120
 
128
121
  class AssertNotEqualDiffTests < DiffTests
129
122
  desc "`assert_not_equal`"
130
- setup do
131
- exp_obj, act_obj = @exp_obj, @act_obj
132
- @test = Factory.test(@c) do
123
+ subject {
124
+ exp_obj = exp_obj1
125
+ Factory.test(config1) do
133
126
  assert_not_equal(exp_obj, exp_obj)
134
127
  end
135
- @test.run(&test_run_callback)
136
- end
137
- subject{ @test }
128
+ }
138
129
 
139
130
  should "include diff output in the fail messages" do
140
- exp = "Expected equals actual, diff:\n"\
141
- "#{Assert::U.syscmd_diff_proc.call(@exp_obj_show, @exp_obj_show)}"
142
- assert_equal exp, test_run_results(:fail).first.message
143
- end
131
+ subject.run(&test_run_callback)
144
132
 
133
+ exp =
134
+ "Expected equals actual, diff:\n"\
135
+ "#{Assert::U.syscmd_diff_proc.call(exp_obj_show1, exp_obj_show1)}"
136
+ assert_that(test_run_results(:fail).first.message).equals(exp)
137
+ end
145
138
  end
146
-
147
139
  end
@@ -9,59 +9,55 @@ module Assert::Assertions
9
9
  include Assert::Test::TestHelpers
10
10
 
11
11
  desc "`assert_file_exists`"
12
- setup do
13
- desc = @desc = "assert file exists empty fail desc"
14
- args = @args = ["/a/path/to/some/file/that/no/exists", desc]
15
- @test = Factory.test do
12
+ subject {
13
+ args = args1
14
+ Factory.test do
16
15
  assert_file_exists(__FILE__) # pass
17
16
  assert_file_exists(*args) # fail
18
17
  end
19
- @c = @test.config
20
- @test.run(&test_run_callback)
21
- end
22
- subject{ @test }
18
+ }
19
+
20
+ let(:desc1) { "assert file exists fail desc" }
21
+ let(:args1) { ["/a/path/to/some/file/that/no/exists", desc1] }
22
+ let(:config1) { subject.config }
23
23
 
24
24
  should "produce results as expected" do
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)
28
- end
25
+ subject.run(&test_run_callback)
29
26
 
30
- should "have a fail message with custom and generic explanations" do
31
- exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to exist."
32
- assert_equal exp, test_run_results(:fail).first.message
33
- end
27
+ assert_that(test_run_result_count).equals(2)
28
+ assert_that(test_run_result_count(:pass)).equals(1)
29
+ assert_that(test_run_result_count(:fail)).equals(1)
34
30
 
31
+ exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to exist."
32
+ assert_that(test_run_results(:fail).first.message).equals(exp)
33
+ end
35
34
  end
36
35
 
37
36
  class AssertNotFileExistsTests < Assert::Context
38
37
  include Assert::Test::TestHelpers
39
38
 
40
39
  desc "`assert_not_file_exists`"
41
- setup do
42
- desc = @desc = "assert not file exists empty fail desc"
43
- args = @args = [__FILE__, desc]
44
- @test = Factory.test do
45
- assert_not_file_exists("/a/path/to/some/file/that/no/exists") # pass
46
- assert_not_file_exists(*args) # fail
40
+ subject {
41
+ args = args1
42
+ Factory.test do
43
+ assert_not_file_exists("/file/path") # pass
44
+ assert_not_file_exists(*args) # fail
47
45
  end
48
- @c = @test.config
49
- @test.run(&test_run_callback)
50
- end
51
- subject{ @test }
46
+ }
47
+
48
+ let(:desc1) { "assert not file exists fail desc" }
49
+ let(:args1) { [__FILE__, desc1] }
50
+ let(:config1) { subject.config }
52
51
 
53
52
  should "produce results as expected" do
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)
57
- end
53
+ subject.run(&test_run_callback)
58
54
 
59
- should "have a fail message with custom and generic explanations" do
60
- exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to not exist."
61
- assert_equal exp, test_run_results(:fail).first.message
62
- end
55
+ assert_that(test_run_result_count).equals(2)
56
+ assert_that(test_run_result_count(:pass)).equals(1)
57
+ assert_that(test_run_result_count(:fail)).equals(1)
63
58
 
59
+ exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not exist."
60
+ assert_that(test_run_results(:fail).first.message).equals(exp)
61
+ end
64
62
  end
65
-
66
63
  end
67
-