assert 2.18.0 → 2.19.0

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