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_kind_of`"
11
- setup do
12
- desc = @desc = "assert kind 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_kind_of(String, "object") # pass
16
15
  assert_kind_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 kind 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 a kind 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 a kind 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_kind_of`"
40
- setup do
41
- desc = @desc = "assert not kind 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_kind_of(*args) # fail
45
45
  assert_not_kind_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 kind 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 a kind 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 a kind of #{args1[0]}."
63
+ assert_that(test_run_results(:fail).first.message).equals(exp)
62
64
  end
63
65
  end
64
66
  end
65
-
@@ -8,28 +8,29 @@ module Assert::Assertions
8
8
  include Assert::Test::TestHelpers
9
9
 
10
10
  desc "`assert_match`"
11
- setup do
12
- desc = @desc = "assert match fail desc"
13
- args = @args = ["not", "a string", desc]
14
- @test = Factory.test do
11
+ subject {
12
+ args = args1
13
+ Factory.test do
15
14
  assert_match(/a/, "a string") # pass
16
15
  assert_match(*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 match fail desc" }
20
+ let(:args1) { ["not", "a string", 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)}"\
31
- " to match #{Assert::U.show(@args[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 match #{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,29 +38,29 @@ module Assert::Assertions
37
38
  include Assert::Test::TestHelpers
38
39
 
39
40
  desc "`assert_not_match`"
40
- setup do
41
- desc = @desc = "assert not match fail desc"
42
- args = @args = [/a/, "a string", desc]
43
- @test = Factory.test do
41
+ subject {
42
+ args = args1
43
+ Factory.test do
44
44
  assert_not_match(*args) # fail
45
45
  assert_not_match("not", "a string") # 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 match fail desc" }
50
+ let(:args1) { [/a/, "a string", 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)}"\
60
- " to not match #{Assert::U.show(@args[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 match #{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
  end
65
-
@@ -8,27 +8,27 @@ module Assert::Assertions
8
8
  include Assert::Test::TestHelpers
9
9
 
10
10
  desc "`assert_nil`"
11
- setup do
12
- desc = @desc = "assert nil empty fail desc"
13
- args = @args = [1, desc]
14
- @test = Factory.test do
11
+ subject {
12
+ args = args1
13
+ Factory.test do
15
14
  assert_nil(nil) # pass
16
15
  assert_nil(*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 nil empty fail desc" }
20
+ let(:args1) { [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[1]}\nExpected #{Assert::U.show(@args[0], @c)} to be nil."
31
- 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 = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be nil."
31
+ assert_that(test_run_results(:fail).first.message).equals(exp)
32
32
  end
33
33
  end
34
34
 
@@ -36,28 +36,27 @@ module Assert::Assertions
36
36
  include Assert::Test::TestHelpers
37
37
 
38
38
  desc "`assert_not_nil`"
39
- setup do
40
- desc = @desc = "assert not nil empty fail desc"
41
- args = @args = [nil, desc]
42
- @test = Factory.test do
39
+ subject {
40
+ args = args1
41
+ Factory.test do
43
42
  assert_not_nil(1) # pass
44
43
  assert_not_nil(*args) # fail
45
44
  end
46
- @c = @test.config
47
- @test.run(&test_run_callback)
48
- end
49
- subject{ @test }
45
+ }
46
+
47
+ let(:desc1) { "assert not nil empty fail desc" }
48
+ let(:args1) { [nil, desc1] }
49
+ let(:config1) { subject.config }
50
50
 
51
51
  should "produce results as expected" do
52
- assert_equal 2, test_run_result_count
53
- assert_equal 1, test_run_result_count(:pass)
54
- assert_equal 1, test_run_result_count(:fail)
55
- end
52
+ subject.run(&test_run_callback)
56
53
 
57
- should "have a fail message with custom and generic explanations" do
58
- exp = "#{@args[1]}\nExpected #{Assert::U.show(@args[0], @c)} to not be nil."
59
- assert_equal exp, test_run_results(:fail).first.message
54
+ assert_that(test_run_result_count).equals(2)
55
+ assert_that(test_run_result_count(:pass)).equals(1)
56
+ assert_that(test_run_result_count(:fail)).equals(1)
57
+
58
+ exp = "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be nil."
59
+ assert_that(test_run_results(:fail).first.message).equals(exp)
60
60
  end
61
61
  end
62
62
  end
63
-
@@ -6,54 +6,55 @@ module Assert::Assertions
6
6
  include Assert::Test::TestHelpers
7
7
 
8
8
  desc "`assert_raises`"
9
- setup do
10
- d = @d = "assert raises fail desc"
11
- @test = Factory.test do
12
- assert_raises(StandardError, RuntimeError){ raise(StandardError) } # pass
13
- assert_raises(StandardError, RuntimeError, d){ raise(Exception) } # fail
14
- assert_raises(RuntimeError, d){ raise(StandardError) } # fail
15
- assert_raises(RuntimeError, d){ true } # fail
16
- assert_raises(d){ true } # fail
9
+ subject {
10
+ desc = desc1
11
+ Factory.test do
12
+ assert_raises(StandardError, RuntimeError) { raise(StandardError) } # pass
13
+ assert_raises(StandardError, RuntimeError, desc) { raise(Exception) } # fail
14
+ assert_raises(RuntimeError, desc) { raise(StandardError) } # fail
15
+ assert_raises(RuntimeError, desc) { true } # fail
16
+ assert_raises(desc) { true } # fail
17
17
  end
18
- @test.run(&test_run_callback)
19
- end
20
- subject{ @test }
18
+ }
19
+
20
+ let(:desc1) { "assert raises fail desc" }
21
21
 
22
22
  should "produce results as expected" do
23
- assert_equal 5, test_run_result_count
24
- assert_equal 1, test_run_result_count(:pass)
25
- assert_equal 4, test_run_result_count(:fail)
26
- end
23
+ subject.run(&test_run_callback)
27
24
 
28
- should "have a fail message with custom and generic explanations" do
29
- exp = [
30
- "#{@d}\nStandardError or RuntimeError exception expected, not:",
31
- "#{@d}\nRuntimeError exception expected, not:",
32
- "#{@d}\nRuntimeError exception expected but nothing raised.",
33
- "#{@d}\nAn exception expected but nothing raised."
34
- ]
25
+ assert_that(test_run_result_count).equals(5)
26
+ assert_that(test_run_result_count(:pass)).equals(1)
27
+ assert_that(test_run_result_count(:fail)).equals(4)
28
+
29
+ exp =
30
+ [
31
+ "#{desc1}\nStandardError or RuntimeError exception expected, not:",
32
+ "#{desc1}\nRuntimeError exception expected, not:",
33
+ "#{desc1}\nRuntimeError exception expected but nothing raised.",
34
+ "#{desc1}\nAn exception expected but nothing raised.",
35
+ ]
35
36
  messages = test_run_results(:fail).map(&:message)
36
- messages.each_with_index{ |msg, n| assert_match(/^#{exp[n]}/, msg) }
37
+ messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
37
38
  end
38
39
 
39
40
  should "return any raised exception instance" do
40
41
  error = nil
41
42
  error_msg = Factory.string
42
- test = Factory.test do
43
- error = assert_raises(RuntimeError){ raise(RuntimeError, error_msg) }
44
- end
43
+
44
+ test =
45
+ Factory.test do
46
+ error = assert_raises(RuntimeError) { raise(RuntimeError, error_msg) }
47
+ end
45
48
  test.run
46
49
 
47
- assert_not_nil error
48
- assert_kind_of RuntimeError, error
49
- assert_equal error_msg, error.message
50
+ assert_that(error).is_not_nil
51
+ assert_that(error).is_kind_of(RuntimeError)
52
+ assert_that(error.message).equals(error_msg)
50
53
 
51
- test = Factory.test do
52
- error = assert_raises(RuntimeError){ }
53
- end
54
+ test = Factory.test { error = assert_raises(RuntimeError) {} }
54
55
  test.run
55
56
 
56
- assert_nil error
57
+ assert_that(error).is_nil
57
58
  end
58
59
  end
59
60
 
@@ -61,33 +62,32 @@ module Assert::Assertions
61
62
  include Assert::Test::TestHelpers
62
63
 
63
64
  desc "`assert_nothing_raised`"
64
- setup do
65
- d = @d = "assert nothing raised fail desc"
66
- @test = Factory.test do
67
- anr = :assert_nothing_raised
68
- self.send(anr, StandardError, RuntimeError, d){ raise(StandardError) } # fail
69
- self.send(anr, RuntimeError){ raise(StandardError) } # pass
70
- self.send(anr, d){ raise(RuntimeError) } # fail
71
- self.send(anr){ true } # pass
65
+ subject {
66
+ desc = desc1
67
+ Factory.test do
68
+ assert_nothing_raised(StandardError, RuntimeError, desc) { raise(StandardError) } # fail
69
+ assert_nothing_raised(RuntimeError) { raise(StandardError) } # pass
70
+ assert_nothing_raised(desc) { raise(RuntimeError) } # fail
71
+ assert_nothing_raised { true } # pass
72
72
  end
73
- @test.run(&test_run_callback)
74
- end
75
- subject{ @test }
73
+ }
74
+
75
+ let(:desc1) { "assert nothing raised fail desc" }
76
76
 
77
77
  should "produce results as expected" do
78
- assert_equal 4, test_run_result_count
79
- assert_equal 2, test_run_result_count(:pass)
80
- assert_equal 2, test_run_result_count(:fail)
81
- end
78
+ subject.run(&test_run_callback)
79
+
80
+ assert_that(test_run_result_count).equals(4)
81
+ assert_that(test_run_result_count(:pass)).equals(2)
82
+ assert_that(test_run_result_count(:fail)).equals(2)
82
83
 
83
- should "have a fail message with custom and generic explanations" do
84
- exp = [
85
- "#{@d}\nStandardError or RuntimeError exception not expected, but raised:",
86
- "#{@d}\nAn exception not expected, but raised:"
87
- ]
84
+ exp =
85
+ [
86
+ "#{desc1}\nStandardError or RuntimeError exception not expected, but raised:",
87
+ "#{desc1}\nAn exception not expected, but raised:",
88
+ ]
88
89
  messages = test_run_results(:fail).map(&:message)
89
- messages.each_with_index{ |msg, n| assert_match(/^#{exp[n]}/, msg) }
90
+ messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
90
91
  end
91
92
  end
92
93
  end
93
-
@@ -8,29 +8,30 @@ module Assert::Assertions
8
8
  include Assert::Test::TestHelpers
9
9
 
10
10
  desc "`assert_respond_to`"
11
- setup do
12
- desc = @desc = "assert respond to fail desc"
13
- args = @args = [:abs, "1", desc]
14
- @test = Factory.test do
11
+ subject {
12
+ args = args1
13
+ Factory.test do
15
14
  assert_respond_to(:abs, 1) # pass
16
15
  assert_respond_to(*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 respond to fail desc" }
20
+ let(:args1) { [:abs, "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)} (#{@args[1].class})"\
32
- " to respond to `#{@args[0]}`."
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)} (#{args1[1].class})"\
33
+ " to respond to `#{args1[0]}`."
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_respond_to`"
41
- setup do
42
- desc = @desc = "assert not respond to fail desc"
43
- args = @args = [:abs, 1, desc]
44
- @test = Factory.test do
42
+ subject {
43
+ args = args1
44
+ Factory.test do
45
45
  assert_not_respond_to(*args) # fail
46
46
  assert_not_respond_to(:abs, "1") # pass
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 respond to fail desc" }
51
+ let(:args1) { [:abs, 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)} (#{@args[1].class})"\
62
- " to not respond to `#{@args[0]}`."
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)} (#{args1[1].class})"\
64
+ " to not respond to `#{args1[0]}`."
65
+ assert_that(test_run_results(:fail).first.message).equals(exp)
64
66
  end
65
67
  end
66
68
  end
67
-