assert 2.18.0 → 2.19.0

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