assert 2.18.2 → 2.19.2

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 +4 -2
  3. data/README.md +7 -6
  4. data/assert.gemspec +5 -2
  5. data/bin/assert +1 -0
  6. data/lib/assert.rb +2 -0
  7. data/lib/assert/actual_value.rb +143 -0
  8. data/lib/assert/assert_runner.rb +2 -0
  9. data/lib/assert/assertions.rb +82 -20
  10. data/lib/assert/cli.rb +2 -0
  11. data/lib/assert/config.rb +2 -0
  12. data/lib/assert/config_helpers.rb +2 -0
  13. data/lib/assert/context.rb +33 -37
  14. data/lib/assert/context/let_dsl.rb +16 -0
  15. data/lib/assert/context/method_missing.rb +22 -0
  16. data/lib/assert/context/setup_dsl.rb +3 -0
  17. data/lib/assert/context/subject_dsl.rb +26 -24
  18. data/lib/assert/context/suite_dsl.rb +3 -0
  19. data/lib/assert/context/test_dsl.rb +3 -0
  20. data/lib/assert/context_info.rb +2 -0
  21. data/lib/assert/default_runner.rb +2 -0
  22. data/lib/assert/default_suite.rb +2 -0
  23. data/lib/assert/default_view.rb +2 -0
  24. data/lib/assert/factory.rb +2 -0
  25. data/lib/assert/file_line.rb +2 -0
  26. data/lib/assert/macro.rb +2 -0
  27. data/lib/assert/macros/methods.rb +6 -4
  28. data/lib/assert/result.rb +8 -1
  29. data/lib/assert/runner.rb +2 -0
  30. data/lib/assert/stub.rb +45 -0
  31. data/lib/assert/suite.rb +9 -10
  32. data/lib/assert/test.rb +3 -9
  33. data/lib/assert/utils.rb +3 -1
  34. data/lib/assert/version.rb +3 -1
  35. data/lib/assert/view.rb +2 -0
  36. data/lib/assert/view_helpers.rb +2 -0
  37. data/test/helper.rb +28 -28
  38. data/test/support/factory.rb +17 -0
  39. data/test/support/inherited_stuff.rb +2 -0
  40. data/test/system/stub_tests.rb +334 -333
  41. data/test/system/test_tests.rb +101 -109
  42. data/test/unit/actual_value_tests.rb +373 -0
  43. data/test/unit/assert_tests.rb +79 -61
  44. data/test/unit/assertions/assert_block_tests.rb +32 -31
  45. data/test/unit/assertions/assert_changes_tests.rb +99 -0
  46. data/test/unit/assertions/assert_empty_tests.rb +35 -32
  47. data/test/unit/assertions/assert_equal_tests.rb +96 -74
  48. data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
  49. data/test/unit/assertions/assert_includes_tests.rb +40 -37
  50. data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
  51. data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
  52. data/test/unit/assertions/assert_match_tests.rb +36 -33
  53. data/test/unit/assertions/assert_nil_tests.rb +32 -31
  54. data/test/unit/assertions/assert_raises_tests.rb +57 -55
  55. data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
  56. data/test/unit/assertions/assert_same_tests.rb +88 -81
  57. data/test/unit/assertions/assert_true_false_tests.rb +62 -60
  58. data/test/unit/assertions_tests.rb +28 -24
  59. data/test/unit/config_helpers_tests.rb +45 -38
  60. data/test/unit/config_tests.rb +40 -34
  61. data/test/unit/context/let_dsl_tests.rb +12 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -81
  63. data/test/unit/context/subject_dsl_tests.rb +17 -43
  64. data/test/unit/context/suite_dsl_tests.rb +17 -16
  65. data/test/unit/context/test_dsl_tests.rb +52 -52
  66. data/test/unit/context_info_tests.rb +25 -15
  67. data/test/unit/context_tests.rb +186 -179
  68. data/test/unit/default_runner_tests.rb +4 -5
  69. data/test/unit/default_suite_tests.rb +59 -53
  70. data/test/unit/factory_tests.rb +7 -3
  71. data/test/unit/file_line_tests.rb +35 -35
  72. data/test/unit/macro_tests.rb +16 -10
  73. data/test/unit/result_tests.rb +161 -183
  74. data/test/unit/runner_tests.rb +67 -65
  75. data/test/unit/suite_tests.rb +58 -59
  76. data/test/unit/test_tests.rb +120 -139
  77. data/test/unit/utils_tests.rb +45 -45
  78. data/test/unit/view_helpers_tests.rb +56 -52
  79. data/test/unit/view_tests.rb +24 -23
  80. metadata +29 -6
@@ -1,72 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/context/subject_dsl"
3
5
 
4
6
  module Assert::Context::SubjectDSL
5
-
6
7
  class UnitTests < Assert::Context
7
8
  desc "Assert::Context::SubjectDSL"
8
- subject{ @context_class }
9
- end
9
+ subject { Factory.modes_off_context_class(parent_class1) }
10
10
 
11
- class DescriptionsTests < UnitTests
12
- desc "`descriptions` method"
13
- setup do
14
- descs = @descs = ["something amazing", "it really is"]
15
- @context_class = Factory.modes_off_context_class do
16
- descs.each{ |text| desc text }
17
- end
18
- end
19
-
20
- should "return a collection containing any descriptions defined on the class" do
21
- assert_equal @descs, subject.send(:descriptions)
22
- end
11
+ let(:parent_class1) { Factory.modes_off_context_class }
12
+ let(:subject_block1) { Proc.new {} }
23
13
  end
24
14
 
25
15
  class DescriptionTests < UnitTests
26
16
  desc "`description` method"
27
- setup do
28
- parent_text = @parent_desc = "parent description"
29
- @parent_class = Factory.modes_off_context_class do
30
- desc parent_text
31
- end
32
- text = @desc = "and the description for this context"
33
- @context_class = Factory.modes_off_context_class(@parent_class) do
34
- desc text
35
- end
36
- end
37
17
 
38
18
  should "return a string of all the inherited descriptions" do
39
- exp_desc = "parent description and the description for this context"
40
- assert_equal exp_desc, @context_class.description
19
+ parent_class1.desc("parent description")
20
+ subject.desc("and the description for this context")
21
+
22
+ exp = "parent description and the description for this context"
23
+ assert_that(subject.description).equals(exp)
41
24
  end
42
25
  end
43
26
 
44
27
  class SubjectFromLocalTests < UnitTests
45
28
  desc "`subject` method using local context"
46
- setup do
47
- subject_block = @subject_block = ::Proc.new{ @something }
48
- @context_class = Factory.modes_off_context_class do
49
- subject(&subject_block)
50
- end
51
- end
52
29
 
53
30
  should "set the subject block on the context class" do
54
- assert_equal @subject_block, @context_class.subject
31
+ subject.subject(&subject_block1)
32
+
33
+ assert_that(subject.subject).equals(subject_block1)
55
34
  end
56
35
  end
57
36
 
58
37
  class SubjectFromParentTests < UnitTests
59
38
  desc "`subject` method using parent context"
60
- setup do
61
- parent_block = @parent_block = ::Proc.new{ @something }
62
- @parent_class = Factory.modes_off_context_class do
63
- subject(&parent_block)
64
- end
65
- @context_class = Factory.modes_off_context_class(@parent_class)
66
- end
67
39
 
68
- should "default to it's parents subject block" do
69
- assert_equal @parent_block, @context_class.subject
40
+ should "default to its parents subject block" do
41
+ parent_class1.subject(&subject_block1)
42
+
43
+ assert_that(subject.subject).equals(subject_block1)
70
44
  end
71
45
  end
72
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/context/suite_dsl"
3
5
 
@@ -6,38 +8,37 @@ require "assert/suite"
6
8
  module Assert::Context::SuiteDSL
7
9
  class UnitTests < Assert::Context
8
10
  desc "Assert::Context::SuiteDSL"
9
- setup do
10
- @custom_suite = Factory.modes_off_suite
11
- @context_class = Factory.context_class
12
- end
13
- subject{ @context_class }
11
+ subject { Factory.context_class(parent_class1) }
12
+
13
+ let(:parent_class1) { Factory.context_class }
14
+ let(:custom_suite1) { Factory.modes_off_suite }
14
15
 
15
16
  should "use `Assert.suite` by default" do
16
- assert_equal Assert.suite, subject.suite
17
+ assert_that(subject.suite).equals(Assert.suite)
17
18
  end
18
19
 
19
20
  should "use any given custom suite" do
20
- subject.suite(@custom_suite)
21
- assert_equal @custom_suite, subject.suite
21
+ subject.suite(custom_suite1)
22
+ assert_that(subject.suite).equals(custom_suite1)
22
23
  end
23
24
  end
24
25
 
25
26
  class SuiteFromParentTests < UnitTests
26
27
  desc "`suite` method using parent context"
28
+
27
29
  setup do
28
- @parent_class = Factory.context_class
29
- @parent_class.suite(@custom_suite)
30
- @context_class = Factory.context_class(@parent_class)
30
+ parent_class1.suite(custom_suite1)
31
31
  end
32
32
 
33
- should "default to it's parent's suite" do
34
- assert_equal @custom_suite, subject.suite
33
+ let(:custom_suite2) { Factory.modes_off_suite }
34
+
35
+ should "default to its parent's suite" do
36
+ assert_that(subject.suite).equals(custom_suite1)
35
37
  end
36
38
 
37
39
  should "use any given custom suite" do
38
- another_suite = Factory.modes_off_suite
39
- subject.suite(another_suite)
40
- assert_equal another_suite, subject.suite
40
+ subject.suite(custom_suite2)
41
+ assert_that(subject.suite).equals(custom_suite2)
41
42
  end
42
43
  end
43
44
  end
@@ -1,151 +1,151 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/context/test_dsl"
3
5
 
4
6
  module Assert::Context::TestDSL
5
7
  class UnitTests < Assert::Context
6
8
  desc "Assert::Context::TestDSL"
7
- setup do
8
- @test_desc = "be true"
9
- @test_block = ::Proc.new{ assert(true) }
10
- end
9
+
10
+ let(:test_desc1) { "be true" }
11
+ let(:test_block1) { Proc.new{ assert(true) } }
11
12
 
12
13
  should "build a test using `test` with a desc and code block" do
13
- d, b = @test_desc, @test_block
14
+ d, b = test_desc1, test_block1
14
15
  context, test = build_eval_context{ test(d, &b) }
15
16
 
16
- assert_equal 1, context.class.suite.tests_to_run_count
17
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
17
18
 
18
- assert_kind_of Assert::Test, test
19
- assert_equal @test_desc, test.name
20
- assert_equal @test_block, test.code
19
+ assert_that(test).is_kind_of(Assert::Test)
20
+ assert_that(test.name).equals(test_desc1)
21
+ assert_that(test.code).equals(test_block1)
21
22
  end
22
23
 
23
24
  should "build a test using `should` with a desc and code block" do
24
- d, b = @test_desc, @test_block
25
+ d, b = test_desc1, test_block1
25
26
  context, test = build_eval_context{ should(d, &b) }
26
27
 
27
- assert_equal 1, context.class.suite.tests_to_run_count
28
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
28
29
 
29
- assert_kind_of Assert::Test, test
30
- assert_equal "should #{@test_desc}", test.name
31
- assert_equal @test_block, test.code
30
+ assert_that(test).is_kind_of(Assert::Test)
31
+ assert_that(test.name).equals("should #{test_desc1}")
32
+ assert_that(test.code).equals(test_block1)
32
33
  end
33
34
 
34
35
  should "build a test that skips with no msg when `test_eventually` called" do
35
- d, b = @test_desc, @test_block
36
+ d, b = test_desc1, test_block1
36
37
  context, test = build_eval_context{ test_eventually(d, &b) }
37
38
  err = capture_err(Assert::Result::TestSkipped) do
38
39
  context.instance_eval(&test.code)
39
40
  end
40
41
 
41
- assert_equal 1, context.class.suite.tests_to_run_count
42
- assert_equal "TODO", err.message
43
- assert_equal 1, err.backtrace.size
42
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
43
+ assert_that(err.message).equals("TODO")
44
+ assert_that(err.backtrace.size).equals(1)
44
45
  end
45
46
 
46
47
  should "build a test that skips with no msg when `should_eventually` called" do
47
- d, b = @test_desc, @test_block
48
+ d, b = test_desc1, test_block1
48
49
  context, test = build_eval_context{ should_eventually(d, &b) }
49
50
  err = capture_err(Assert::Result::TestSkipped) do
50
51
  context.instance_eval(&test.code)
51
52
  end
52
53
 
53
- assert_equal 1, context.class.suite.tests_to_run_count
54
- assert_equal "TODO", err.message
55
- assert_equal 1, err.backtrace.size
54
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
55
+ assert_that(err.message).equals("TODO")
56
+ assert_that(err.backtrace.size).equals(1)
56
57
  end
57
58
 
58
59
  should "skip with the msg \"TODO\" when `test` called with no block" do
59
- d = @test_desc
60
+ d = test_desc1
60
61
  context, test = build_eval_context { test(d) } # no block passed
61
62
  err = capture_err(Assert::Result::TestSkipped) do
62
63
  context.instance_eval(&test.code)
63
64
  end
64
65
 
65
- assert_equal 1, context.class.suite.tests_to_run_count
66
- assert_equal "TODO", err.message
67
- assert_equal 1, err.backtrace.size
66
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
67
+ assert_that(err.message).equals("TODO")
68
+ assert_that(err.backtrace.size).equals(1)
68
69
  end
69
70
 
70
71
  should "skip with the msg \"TODO\" when `should` called with no block" do
71
- d = @test_desc
72
+ d = test_desc1
72
73
  context, test = build_eval_context { should(d) } # no block passed
73
74
  err = capture_err(Assert::Result::TestSkipped) do
74
75
  context.instance_eval(&test.code)
75
76
  end
76
77
 
77
- assert_equal 1, context.class.suite.tests_to_run_count
78
- assert_equal "TODO", err.message
79
- assert_equal 1, err.backtrace.size
78
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
79
+ assert_that(err.message).equals("TODO")
80
+ assert_that(err.backtrace.size).equals(1)
80
81
  end
81
82
 
82
83
  should "skip with the msg \"TODO\" when `test_eventually` called with no block" do
83
- d = @test_desc
84
+ d = test_desc1
84
85
  context, test = build_eval_context{ test_eventually(d) } # no block given
85
86
  err = capture_err(Assert::Result::TestSkipped) do
86
87
  context.instance_eval(&test.code)
87
88
  end
88
89
 
89
- assert_equal 1, context.class.suite.tests_to_run_count
90
- assert_equal "TODO", err.message
91
- assert_equal 1, err.backtrace.size
90
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
91
+ assert_that(err.message).equals("TODO")
92
+ assert_that(err.backtrace.size).equals(1)
92
93
  end
93
94
 
94
95
  should "skip with the msg \"TODO\" when `should_eventually` called with no block" do
95
- d = @test_desc
96
+ d = test_desc1
96
97
  context, test = build_eval_context{ should_eventually(d) } # no block given
97
98
  err = capture_err(Assert::Result::TestSkipped) do
98
99
  context.instance_eval(&test.code)
99
100
  end
100
101
 
101
- assert_equal 1, context.class.suite.tests_to_run_count
102
- assert_equal "TODO", err.message
103
- assert_equal 1, err.backtrace.size
102
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
103
+ assert_that(err.message).equals("TODO")
104
+ assert_that(err.backtrace.size).equals(1)
104
105
  end
105
106
 
106
107
  should "build a test from a macro using `test`" do
107
- d, b = @test_desc, @test_block
108
+ d, b = test_desc1, test_block1
108
109
  m = Assert::Macro.new{ test(d, &b); test(d, &b) }
109
110
  context_class = Factory.modes_off_context_class{ test(m) }
110
111
 
111
- assert_equal 2, context_class.suite.tests_to_run_count
112
+ assert_that(context_class.suite.tests_to_run_count).equals(2)
112
113
  end
113
114
 
114
115
  should "build a test from a macro using `should`" do
115
- d, b = @test_desc, @test_block
116
+ d, b = test_desc1, test_block1
116
117
  m = Assert::Macro.new{ should(d, &b); should(d, &b) }
117
118
  context_class = Factory.modes_off_context_class{ should(m) }
118
119
 
119
- assert_equal 2, context_class.suite.tests_to_run_count
120
+ assert_that(context_class.suite.tests_to_run_count).equals(2)
120
121
  end
121
122
 
122
123
  should "build a test that skips from a macro using `test_eventually`" do
123
- d, b = @test_desc, @test_block
124
+ d, b = test_desc1, test_block1
124
125
  m = Assert::Macro.new{ test(d, &b); test(d, &b) }
125
126
  context, test = build_eval_context{ test_eventually(m) }
126
127
 
127
- assert_equal 1, context.class.suite.tests_to_run_count
128
- assert_raises(Assert::Result::TestSkipped) do
128
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
129
+ assert_that {
129
130
  context.instance_eval(&test.code)
130
- end
131
+ }.raises(Assert::Result::TestSkipped)
131
132
  end
132
133
 
133
134
  should "build a test that skips from a macro using `should_eventually`" do
134
- d, b = @test_desc, @test_block
135
+ d, b = test_desc1, test_block1
135
136
  m = Assert::Macro.new{ should(d, &b); should(d, &b) }
136
137
  context, test = build_eval_context{ should_eventually(m) }
137
138
 
138
- assert_equal 1, context.class.suite.tests_to_run_count
139
- assert_raises(Assert::Result::TestSkipped) do
139
+ assert_that(context.class.suite.tests_to_run_count).equals(1)
140
+ assert_that {
140
141
  context.instance_eval(&test.code)
141
- end
142
-
142
+ }.raises(Assert::Result::TestSkipped)
143
143
  end
144
144
 
145
145
  private
146
146
 
147
147
  def build_eval_context(&build_block)
148
- context_class = Factory.modes_off_context_class &build_block
148
+ context_class = Factory.modes_off_context_class(&build_block)
149
149
  test = context_class.suite.sorted_tests_to_run.to_a.last
150
150
  [context_class.new(test, test.config, proc{ |r| }), test]
151
151
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/context_info"
3
5
 
@@ -6,47 +8,55 @@ require "assert/context"
6
8
  class Assert::ContextInfo
7
9
  class UnitTests < Assert::Context
8
10
  desc "Assert::ContextInfo"
11
+ subject { unit_class }
12
+
13
+ let(:unit_class) { Assert::ContextInfo }
14
+ end
15
+
16
+ class InitTests < UnitTests
17
+ desc "when init"
18
+ subject { unit_class.new(context1, nil, @caller.first) }
19
+
9
20
  setup do
10
21
  @caller = caller
11
- @klass = Assert::Context
12
- @info = Assert::ContextInfo.new(@klass, nil, @caller.first)
13
22
  end
14
- subject{ @info }
23
+
24
+ let(:context1) { Assert::Context }
15
25
 
16
26
  should have_readers :called_from, :klass, :file
17
27
  should have_imeths :test_name
18
28
 
19
29
  should "set its klass on init" do
20
- assert_equal @klass, subject.klass
30
+ assert_that(subject.klass).equals(context1)
21
31
  end
22
32
 
23
33
  should "set its called_from to the called_from or first caller on init" do
24
- info = Assert::ContextInfo.new(@klass, @caller.first, nil)
25
- assert_equal @caller.first, info.called_from
34
+ info = Assert::ContextInfo.new(context1, @caller.first, nil)
35
+ assert_that(info.called_from).equals(@caller.first)
26
36
 
27
- info = Assert::ContextInfo.new(@klass, nil, @caller.first)
28
- assert_equal @caller.first, info.called_from
37
+ info = Assert::ContextInfo.new(context1, nil, @caller.first)
38
+ assert_that(info.called_from).equals(@caller.first)
29
39
  end
30
40
 
31
41
  should "set its file from caller info on init" do
32
- assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ""), subject.file
42
+ assert_that(subject.file).equals(@caller.first.gsub(/\:[0-9]+.*$/, ""))
33
43
  end
34
44
 
35
45
  should "not have any file info if no caller is given" do
36
- info = Assert::ContextInfo.new(@klass)
37
- assert_nil info.file
46
+ info = Assert::ContextInfo.new(context1)
47
+ assert_that(info.file).is_nil
38
48
  end
39
49
 
40
50
  should "know how to build the contextual test name for a given name" do
41
51
  desc = Factory.string
42
52
  name = Factory.string
43
53
 
44
- assert_equal name, subject.test_name(name)
45
- assert_equal "", subject.test_name("")
46
- assert_equal "", subject.test_name(nil)
54
+ assert_that(subject.test_name(name)).equals(name)
55
+ assert_that(subject.test_name("")).equals("")
56
+ assert_that(subject.test_name(nil)).equals("")
47
57
 
48
58
  Assert.stub(subject.klass, :description){ desc }
49
- assert_equal "#{desc} #{name}", subject.test_name(name)
59
+ assert_that(subject.test_name(name)).equals("#{desc} #{name}")
50
60
  end
51
61
  end
52
62
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/context"
3
5
 
@@ -8,345 +10,353 @@ require "assert/utils"
8
10
  class Assert::Context
9
11
  class UnitTests < Assert::Context
10
12
  desc "Assert::Context"
13
+ subject { unit_class }
14
+
15
+ let(:unit_class) { Assert::Context }
16
+
17
+ # DSL methods
18
+ should have_imeths :description, :desc, :describe, :subject, :suite, :let
19
+ should have_imeths :setup_once, :before_once, :startup
20
+ should have_imeths :teardown_once, :after_once, :shutdown
21
+ should have_imeths :setup, :before, :setups, :run_setups
22
+ should have_imeths :teardown, :after, :teardowns, :run_teardowns
23
+ should have_imeths :around, :arounds, :run_arounds
24
+ should have_imeths :test, :test_eventually, :test_skip
25
+ should have_imeths :should, :should_eventually, :should_skip
26
+ end
27
+
28
+ class InitTests < UnitTests
29
+ desc "when init"
30
+ subject { context_class1.new(test1, test1.config, result_callback1) }
31
+
11
32
  setup do
12
- @test = Factory.test
13
- @context_class = @test.context_class
14
33
  @callback_result = nil
15
- @test_results = []
16
- @result_callback = proc do |result|
17
- @callback_result = result
18
- @test_results << result
19
- end
20
- @context = @context_class.new(@test, @test.config, @result_callback)
21
34
  end
22
- subject{ @context }
23
35
 
24
- # DSL methods
25
- should have_cmeths :description, :desc, :describe, :subject, :suite
26
- should have_cmeths :setup_once, :before_once, :startup
27
- should have_cmeths :teardown_once, :after_once, :shutdown
28
- should have_cmeths :setup, :before, :setups, :run_setups
29
- should have_cmeths :teardown, :after, :teardowns, :run_teardowns
30
- should have_cmeths :around, :arounds, :run_arounds
31
- should have_cmeths :test, :test_eventually, :test_skip
32
- should have_cmeths :should, :should_eventually, :should_skip
33
-
34
- should have_imeths :assert, :assert_not, :refute
36
+ let(:test1) { Factory.test }
37
+ let(:context_class1) { test1.context_class }
38
+ let(:test_results1) { [] }
39
+ let(:result_callback1) {
40
+ proc { |result| @callback_result = result; test_results1 << result }
41
+ }
42
+ let(:halt_config1) { Assert::Config.new(:halt_on_fail => true) }
43
+ let(:msg1) { Factory.string }
44
+
45
+ should have_imeths :assert, :assert_not, :refute, :assert_that
35
46
  should have_imeths :pass, :ignore, :fail, :flunk, :skip
36
47
  should have_imeths :pending, :with_backtrace, :subject
37
48
 
38
49
  should "collect context info" do
39
50
  test = @__assert_running_test__
40
- assert_match(/test\/unit\/context_tests.rb$/, test.context_info.file)
41
- assert_equal self.class, test.context_info.klass
51
+ assert_that(test.context_info.file).matches(/test\/unit\/context_tests.rb$/)
52
+ assert_that(test.context_info.klass).equals(self.class)
42
53
  end
54
+
43
55
  private
44
56
 
45
57
  ASSERT_TEST_PATH_REGEX = /\A#{File.join(ROOT_PATH, "test", "")}/
46
58
 
47
59
  def assert_with_bt_set(exp_with_bt, result)
48
60
  with_backtrace(caller) do
49
- assert_true result.with_bt_set?
61
+ assert_that(result.with_bt_set?).is_true
50
62
 
51
63
  exp = Assert::Result::Backtrace.to_s(exp_with_bt+[(result.backtrace.filtered.first)])
52
- assert_equal exp, result.trace
53
- assert_equal exp_with_bt.first, result.src_line
64
+ assert_that(result.trace).equals(exp)
65
+ assert_that(result.src_line).equals(exp_with_bt.first)
54
66
  end
55
67
  end
56
68
 
57
69
  def assert_not_with_bt_set(result)
58
70
  with_backtrace(caller) do
59
- assert_false result.with_bt_set?
71
+ assert_that(result.with_bt_set?).is_false
60
72
 
61
- assert_equal result.src_line, result.trace
62
- assert_equal result.backtrace.filtered.first.to_s, result.src_line
73
+ assert_that(result.trace).equals(result.src_line)
74
+ assert_that(result.src_line).equals(result.backtrace.filtered.first.to_s)
63
75
  end
64
76
  end
65
77
  end
66
78
 
67
- class SkipTests < UnitTests
79
+ class SkipTests < InitTests
68
80
  desc "skip method"
81
+
69
82
  setup do
70
- @skip_msg = "I need to implement this in the future."
71
- begin; @context.skip(@skip_msg); rescue StandardError => @exception; end
83
+ begin; subject.skip(msg1); rescue StandardError => @exception; end
72
84
  @result = Factory.skip_result(@exception)
73
85
  end
74
- subject{ @result }
75
86
 
76
87
  should "raise a test skipped exception and set its message" do
77
- assert_kind_of Assert::Result::TestSkipped, @exception
78
- assert_equal @skip_msg, @exception.message
79
- assert_equal @skip_msg, subject.message
88
+ assert_that(@exception).is_kind_of(Assert::Result::TestSkipped)
89
+ assert_that(@exception.message).equals(msg1)
90
+ assert_that(@result.message).equals(msg1)
80
91
  end
81
92
 
82
93
  should "not call the result callback" do
83
- assert_nil @callback_result
94
+ assert_that(@callback_result).is_nil
84
95
  end
85
96
 
86
97
  should "use any given called from arg as the exception backtrace" do
87
- assert_not_equal 1, @exception.backtrace.size
98
+ assert_that(@exception.backtrace.size).does_not_equal(1)
88
99
 
89
100
  called_from = Factory.string
90
- begin; @context.skip(@skip_msg, called_from); rescue StandardError => exception; end
91
- assert_equal 1, exception.backtrace.size
92
- assert_equal called_from, exception.backtrace.first
101
+ begin; subject.skip(msg1, called_from); rescue StandardError => exception; end
102
+ assert_that(exception.backtrace.size).equals(1)
103
+ assert_that(exception.backtrace.first).equals(called_from)
93
104
  end
94
105
  end
95
106
 
96
- class IgnoreTests < UnitTests
107
+ class IgnoreTests < InitTests
97
108
  desc "ignore method"
109
+
98
110
  setup do
99
- @ignore_msg = "Ignore this for now, will do later."
100
- @result = @context.ignore(@ignore_msg)
111
+ @result = subject.ignore(msg1)
101
112
  end
102
- subject{ @result }
103
113
 
104
114
  should "create an ignore result and set its message" do
105
- assert_kind_of Assert::Result::Ignore, subject
106
- assert_equal @ignore_msg, subject.message
115
+ assert_that(@result).is_kind_of(Assert::Result::Ignore)
116
+ assert_that(@result.message).equals(msg1)
107
117
  end
108
118
 
109
119
  should "call the result callback" do
110
- assert_equal @result, @callback_result
120
+ assert_that(@callback_result).equals(@result)
111
121
  end
112
122
  end
113
123
 
114
- class PassTests < UnitTests
124
+ class PassTests < InitTests
115
125
  desc "pass method"
126
+
116
127
  setup do
117
- @pass_msg = "That's right, it works."
118
- @result = @context.pass(@pass_msg)
128
+ @result = subject.pass(msg1)
119
129
  end
120
- subject{ @result }
121
130
 
122
131
  should "create a pass result and set its message" do
123
- assert_kind_of Assert::Result::Pass, subject
124
- assert_equal @pass_msg, subject.message
132
+ assert_that(@result).is_kind_of(Assert::Result::Pass)
133
+ assert_that(@result.message).equals(msg1)
125
134
  end
126
135
 
127
136
  should "call the result callback" do
128
- assert_equal @result, @callback_result
137
+ assert_that(@callback_result).equals(@result)
129
138
  end
130
139
  end
131
140
 
132
- class FlunkTests < UnitTests
141
+ class FlunkTests < InitTests
133
142
  desc "flunk method"
143
+
134
144
  setup do
135
- @flunk_msg = "It flunked."
136
- @result = @context.flunk(@flunk_msg)
145
+ @result = subject.flunk(msg1)
137
146
  end
138
- subject{ @result }
139
147
 
140
148
  should "create a fail result and set its message" do
141
- assert_kind_of Assert::Result::Fail, subject
142
- assert_equal @flunk_msg, subject.message
149
+ assert_that(@result).is_kind_of(Assert::Result::Fail)
150
+ assert_that(@result.message).equals(msg1)
143
151
  end
144
152
 
145
153
  should "call the result callback" do
146
- assert_equal @result, @callback_result
154
+ assert_that(@callback_result).equals(@result)
147
155
  end
148
156
  end
149
157
 
150
- class FailTests < UnitTests
158
+ class FailTests < InitTests
151
159
  desc "fail method"
160
+
152
161
  setup do
153
- @result = @context.fail
162
+ @result = subject.fail
154
163
  end
155
- subject{ @result }
156
164
 
157
165
  should "create a fail result and set its backtrace" do
158
- assert_kind_of Assert::Result::Fail, subject
159
- assert_equal subject.backtrace.filtered.first.to_s, subject.trace
160
- assert_kind_of Array, subject.backtrace
166
+ assert_that(@result).is_kind_of(Assert::Result::Fail)
167
+ assert_that(@result.trace).equals(@result.backtrace.filtered.first.to_s)
168
+ assert_that(@result.backtrace).is_kind_of(Array)
161
169
  end
162
170
 
163
171
  should "set any given result message" do
164
- fail_msg = "Didn't work"
165
- result = @context.fail(fail_msg)
166
- assert_equal fail_msg, result.message
172
+ result = subject.fail(msg1)
173
+ assert_that(result.message).equals(msg1)
167
174
  end
168
175
 
169
176
  should "call the result callback" do
170
- assert_equal @result, @callback_result
177
+ assert_that(@callback_result).equals(@result)
171
178
  end
172
179
  end
173
180
 
174
- class HaltOnFailTests < UnitTests
181
+ class HaltOnFailTests < InitTests
175
182
  desc "failing when halting on fails"
176
- setup do
177
- @halt_config = Assert::Config.new(:halt_on_fail => true)
178
- @context = @context_class.new(@test, @halt_config, @result_callback)
179
- @fail_msg = "something failed"
180
- end
181
- subject{ @result }
183
+ subject { context_class1.new(test1, halt_config1, result_callback1) }
182
184
 
183
185
  should "raise an exception with the failure's message" do
184
- begin; @context.fail(@fail_msg); rescue StandardError => err; end
185
- assert_kind_of Assert::Result::TestFailure, err
186
- assert_equal @fail_msg, err.message
186
+ begin; subject.fail(msg1); rescue StandardError => err; end
187
+ assert_that(err).is_kind_of(Assert::Result::TestFailure)
188
+ assert_that(err.message).equals(msg1)
187
189
 
188
190
  result = Assert::Result::Fail.for_test(Factory.test("something"), err)
189
- assert_equal @fail_msg, result.message
191
+ assert_that(result.message).equals(msg1)
190
192
  end
191
193
 
192
194
  should "not call the result callback" do
193
- assert_nil @callback_result
195
+ assert_that(@callback_result).is_nil
194
196
  end
195
197
  end
196
198
 
197
- class AssertTests < UnitTests
199
+ class AssertTests < InitTests
198
200
  desc "assert method"
199
- setup do
200
- @fail_desc = "my fail desc"
201
- @what_failed = "what failed"
202
- end
201
+
202
+ let(:what_failed) { Factory.string }
203
203
 
204
204
  should "return a pass result given a `true` assertion" do
205
- result = subject.assert(true, @fail_desc){ @what_failed }
206
- assert_kind_of Assert::Result::Pass, result
207
- assert_equal "", result.message
205
+ result = subject.assert(true, msg1){ what_failed }
206
+ assert_that(result).is_kind_of(Assert::Result::Pass)
207
+ assert_that(result.message).equals("")
208
208
  end
209
209
 
210
210
  should "return a fail result given a `false` assertion" do
211
- result = subject.assert(false, @fail_desc){ @what_failed }
212
- assert_kind_of Assert::Result::Fail, result
211
+ result = subject.assert(false, msg1){ what_failed }
212
+ assert_that(result).is_kind_of(Assert::Result::Fail)
213
213
  end
214
214
 
215
215
  should "pp the assertion value in the fail message by default" do
216
- exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, @test.config)}`."
217
- result = subject.assert(false, @fail_desc)
216
+ exp_def_what = "Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
217
+ result = subject.assert(false, msg1)
218
218
 
219
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
219
+ assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
220
220
  end
221
221
 
222
222
  should "use a custom fail message if one is given" do
223
- result = subject.assert(false, @fail_desc){ @what_failed }
224
- assert_equal [@fail_desc, @what_failed].join("\n"), result.message
223
+ result = subject.assert(false, msg1){ what_failed }
224
+ assert_that(result.message).equals([msg1, what_failed].join("\n"))
225
225
  end
226
226
 
227
227
  should "return a pass result given a \"truthy\" assertion" do
228
- assert_kind_of Assert::Result::Pass, subject.assert(34)
228
+ assert_that(subject.assert(34)).is_kind_of(Assert::Result::Pass)
229
229
  end
230
230
 
231
231
  should "return a fail result gievn a `nil` assertion" do
232
- assert_kind_of Assert::Result::Fail, subject.assert(nil)
232
+ assert_that(subject.assert(nil)).is_kind_of(Assert::Result::Fail)
233
233
  end
234
234
  end
235
235
 
236
- class AssertNotTests < UnitTests
236
+ class AssertNotTests < InitTests
237
237
  desc "assert_not method"
238
- setup do
239
- @fail_desc = "my fail desc"
240
- end
241
238
 
242
239
  should "return a pass result given a `false` assertion" do
243
- result = subject.assert_not(false, @fail_desc)
244
- assert_kind_of Assert::Result::Pass, result
245
- assert_equal "", result.message
240
+ result = subject.assert_not(false, msg1)
241
+ assert_that(result).is_kind_of(Assert::Result::Pass)
242
+ assert_that(result.message).equals("")
246
243
  end
247
244
 
248
245
  should "return a fail result given a `true` assertion" do
249
- result = subject.assert_not(true, @fail_desc)
250
- assert_kind_of Assert::Result::Fail, result
246
+ result = subject.assert_not(true, msg1)
247
+ assert_that(result).is_kind_of(Assert::Result::Fail)
251
248
  end
252
249
 
253
250
  should "pp the assertion value in the fail message by default" do
254
- exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true, @test.config)}`."
255
- result = subject.assert_not(true, @fail_desc)
251
+ exp_def_what = "Failed assert_not: assertion was `#{Assert::U.show(true, test1.config)}`."
252
+ result = subject.assert_not(true, msg1)
256
253
 
257
- assert_equal [@fail_desc, exp_def_what].join("\n"), result.message
254
+ assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
258
255
  end
259
256
 
260
257
  should "return a fail result given a \"truthy\" assertion" do
261
- assert_kind_of Assert::Result::Fail, subject.assert_not(34)
258
+ assert_that(subject.assert_not(34)).is_kind_of(Assert::Result::Fail)
262
259
  end
263
260
 
264
261
  should "return a pass result given a `nil` assertion" do
265
- assert_kind_of Assert::Result::Pass, subject.assert_not(nil)
262
+ assert_that(subject.assert_not(nil)).is_kind_of(Assert::Result::Pass)
266
263
  end
267
264
  end
268
265
 
269
- class SubjectTests < UnitTests
266
+ class AssertThatTests < InitTests
267
+ desc "`assert_that` method"
268
+
269
+ setup do
270
+ Assert.stub_tap_on_call(Assert::ActualValue, :new) { |_, call|
271
+ @actual_value_new_call = call
272
+ }
273
+ end
274
+
275
+ let(:actual_value) { Factory.string }
276
+
277
+ should "build an Assert::ActualValue" do
278
+ assert_instance_of Assert::ActualValue, subject.assert_that(actual_value)
279
+ assert_equal [actual_value], @actual_value_new_call.pargs
280
+ assert_equal({ context: subject }, @actual_value_new_call.kargs)
281
+ end
282
+ end
283
+
284
+ class SubjectTests < InitTests
270
285
  desc "subject method"
286
+ subject { context_class1.new(test1, test1.config, proc{ |result| }) }
287
+
271
288
  setup do
272
- expected = @expected = "amazing"
273
- @context_class = Factory.modes_off_context_class do
274
- subject{ @something = expected }
275
- end
276
- @context = @context_class.new(@test, @test.config, proc{ |result| })
277
- @subject = @context.subject
289
+ expected = expected1
290
+ context_class1.subject { @something = expected }
291
+ @subject = subject.subject
278
292
  end
279
- subject{ @subject }
293
+
294
+ let(:context_class1) { Factory.modes_off_context_class }
295
+ let(:expected1) { Factory.string }
280
296
 
281
297
  should "instance evaluate the block set with the class setup method" do
282
- assert_equal @expected, subject
298
+ assert_that(@subject).equals(expected1)
283
299
  end
284
300
  end
285
301
 
286
- class PendingTests < UnitTests
302
+ class PendingTests < InitTests
287
303
  desc "`pending` method"
288
- setup do
289
- block2 = proc { fail; pass; }
290
- @block1 = proc { pending(&block2) } # test nesting
291
- end
304
+
305
+ let(:block2) { proc { fail; pass; } }
306
+ let(:block1) { block = block2; proc { pending(&block) } } # test nesting
292
307
 
293
308
  should "make fails skips and make passes fails" do
294
- @context.fail "not affected"
295
- @context.pass
296
- @context.pending(&@block1)
309
+ subject.fail "not affected"
310
+ subject.pass
311
+ subject.pending(&block1)
297
312
 
298
- assert_equal 4, @test_results.size
299
- norm_fail, norm_pass, pending_fail, pending_pass = @test_results
313
+ assert_that(test_results1.size).equals(4)
314
+ norm_fail, norm_pass, pending_fail, pending_pass = test_results1
300
315
 
301
- assert_kind_of Assert::Result::Fail, norm_fail
302
- assert_kind_of Assert::Result::Pass, norm_pass
316
+ assert_that(norm_fail).is_kind_of(Assert::Result::Fail)
317
+ assert_that(norm_pass).is_kind_of(Assert::Result::Pass)
303
318
 
304
- assert_kind_of Assert::Result::Skip, pending_fail
305
- assert_includes "Pending fail", pending_fail.message
319
+ assert_that(pending_fail).is_kind_of(Assert::Result::Skip)
320
+ assert_that(pending_fail.message).includes("Pending fail")
306
321
 
307
- assert_kind_of Assert::Result::Fail, pending_pass
308
- assert_includes "Pending pass", pending_pass.message
322
+ assert_that(pending_pass).is_kind_of(Assert::Result::Fail)
323
+ assert_that(pending_pass.message).includes("Pending pass")
309
324
  end
310
325
  end
311
326
 
312
327
  class PendingWithHaltOnFailTests < PendingTests
313
328
  desc "when halting on fails"
314
- setup do
315
- @halt_config = Assert::Config.new(:halt_on_fail => true)
316
- @context = @context_class.new(@test, @halt_config, @result_callback)
317
- end
318
- subject{ @result }
329
+ subject { context_class1.new(test1, halt_config1, result_callback1) }
319
330
 
320
331
  should "make fails skips and stop the test" do
321
- begin; @context.pending(&@block1); rescue StandardError => err; end
322
- assert_kind_of Assert::Result::TestSkipped, err
323
- assert_includes "Pending fail", err.message
332
+ begin; subject.pending(&block1); rescue StandardError => err; end
333
+ assert_that(err).is_kind_of(Assert::Result::TestSkipped)
334
+ assert_that(err.message).includes("Pending fail")
324
335
 
325
- assert_equal 0, @test_results.size # it halted before the pending pass
336
+ assert_that(test_results1.size).equals(0) # it halted before the pending pass
326
337
  end
327
338
  end
328
339
 
329
- class WithBacktraceTests < UnitTests
340
+ class WithBacktraceTests < InitTests
330
341
  desc "`with_backtrace` method"
331
- setup do
332
- @from_bt = ["called_from_here", Factory.string]
333
- @from_block = proc { ignore; fail; pass; skip "todo"; }
334
- end
342
+
343
+ let(:from_bt1) { ["called_from_here", Factory.string] }
344
+ let(:from_block1) { proc { ignore; fail; pass; skip "todo"; } }
335
345
 
336
346
  should "alter non-error block results' bt with given bt's first line" do
337
- @context.fail "not affected"
347
+ subject.fail "not affected"
338
348
  begin
339
- @context.with_backtrace(@from_bt, &@from_block)
349
+ subject.with_backtrace(from_bt1, &from_block1)
340
350
  rescue Assert::Result::TestSkipped => e
341
- @test_results << Assert::Result::Skip.for_test(@test, e)
351
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
342
352
  end
343
353
 
344
- assert_equal 5, @test_results.size
345
- norm_fail, with_ignore, with_fail, with_pass, _with_skip = @test_results
354
+ assert_that(test_results1.size).equals(5)
355
+ norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
346
356
 
347
357
  assert_not_with_bt_set norm_fail
348
358
 
349
- exp = [@from_bt.first]
359
+ exp = [from_bt1.first]
350
360
  assert_with_bt_set exp, with_ignore
351
361
  assert_with_bt_set exp, with_fail
352
362
  assert_with_bt_set exp, with_pass
@@ -354,30 +364,32 @@ class Assert::Context
354
364
  end
355
365
  end
356
366
 
357
- class WithNestedBacktraceTests < UnitTests
367
+ class WithNestedBacktraceTests < InitTests
358
368
  desc "`with_backtrace` method nested"
359
- setup do
360
- @from_bt1 = ["called_from_here 1", Factory.string]
361
- @from_bt2 = from_bt2 = ["called_from_here 2", Factory.string]
362
369
 
363
- from_block2 = proc { ignore; fail; pass; skip "todo"; }
364
- @from_block1 = proc { with_backtrace(from_bt2, &from_block2) }
365
- end
370
+ let(:from_bt1) { ["called_from_here 1", Factory.string] }
371
+ let(:from_bt2) { ["called_from_here 2", Factory.string] }
372
+ let(:from_block2) { proc { ignore; fail; pass; skip "todo"; } }
373
+ let(:from_block1) {
374
+ from_bt = from_bt2
375
+ from_block = from_block2
376
+ proc { with_backtrace(from_bt, &from_block) }
377
+ }
366
378
 
367
379
  should "alter non-error block results' bt with nested wbt accrued first lines" do
368
- @context.fail "not affected"
380
+ subject.fail "not affected"
369
381
  begin
370
- @context.with_backtrace(@from_bt1, &@from_block1)
382
+ subject.with_backtrace(from_bt1, &from_block1)
371
383
  rescue Assert::Result::TestSkipped => e
372
- @test_results << Assert::Result::Skip.for_test(@test, e)
384
+ test_results1 << Assert::Result::Skip.for_test(test1, e)
373
385
  end
374
386
 
375
- assert_equal 5, @test_results.size
376
- norm_fail, with_ignore, with_fail, with_pass, with_skip = @test_results
387
+ assert_that(test_results1.size).equals(5)
388
+ norm_fail, with_ignore, with_fail, with_pass, _with_skip = test_results1
377
389
 
378
390
  assert_not_with_bt_set norm_fail
379
391
 
380
- exp = [@from_bt1.first, @from_bt2.first]
392
+ exp = [from_bt1.first, from_bt2.first]
381
393
  assert_with_bt_set exp, with_ignore
382
394
  assert_with_bt_set exp, with_fail
383
395
  assert_with_bt_set exp, with_pass
@@ -385,16 +397,11 @@ class Assert::Context
385
397
  end
386
398
  end
387
399
 
388
- class InspectTests < UnitTests
400
+ class InspectTests < InitTests
389
401
  desc "inspect method"
390
- setup do
391
- @expected = "#<#{@context.class}>"
392
- @inspect = @context.inspect
393
- end
394
- subject{ @inspect }
395
402
 
396
403
  should "just show the name of the class" do
397
- assert_equal @expected, subject
404
+ assert_that(subject.inspect).equals("#<#{subject.class}>")
398
405
  end
399
406
  end
400
407
  end