assert 2.18.2 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/assert.gemspec +1 -1
  4. data/lib/assert/actual_value.rb +127 -0
  5. data/lib/assert/assertions.rb +11 -20
  6. data/lib/assert/context.rb +13 -5
  7. data/lib/assert/context/let_dsl.rb +13 -0
  8. data/lib/assert/context/method_missing.rb +19 -0
  9. data/lib/assert/macros/methods.rb +4 -4
  10. data/lib/assert/stub.rb +4 -0
  11. data/lib/assert/version.rb +1 -1
  12. data/test/helper.rb +23 -25
  13. data/test/support/factory.rb +15 -0
  14. data/test/system/stub_tests.rb +348 -333
  15. data/test/system/test_tests.rb +111 -109
  16. data/test/unit/actual_value_tests.rb +335 -0
  17. data/test/unit/assert_tests.rb +84 -59
  18. data/test/unit/assertions/assert_block_tests.rb +32 -31
  19. data/test/unit/assertions/assert_empty_tests.rb +35 -32
  20. data/test/unit/assertions/assert_equal_tests.rb +81 -75
  21. data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
  22. data/test/unit/assertions/assert_includes_tests.rb +40 -37
  23. data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
  24. data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
  25. data/test/unit/assertions/assert_match_tests.rb +36 -33
  26. data/test/unit/assertions/assert_nil_tests.rb +32 -31
  27. data/test/unit/assertions/assert_raises_tests.rb +55 -55
  28. data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
  29. data/test/unit/assertions/assert_same_tests.rb +91 -80
  30. data/test/unit/assertions/assert_true_false_tests.rb +64 -60
  31. data/test/unit/assertions_tests.rb +15 -13
  32. data/test/unit/config_helpers_tests.rb +36 -35
  33. data/test/unit/config_tests.rb +33 -34
  34. data/test/unit/context/let_dsl_tests.rb +10 -0
  35. data/test/unit/context/setup_dsl_tests.rb +70 -81
  36. data/test/unit/context/subject_dsl_tests.rb +16 -43
  37. data/test/unit/context/suite_dsl_tests.rb +16 -16
  38. data/test/unit/context/test_dsl_tests.rb +50 -54
  39. data/test/unit/context_info_tests.rb +16 -15
  40. data/test/unit/context_tests.rb +170 -157
  41. data/test/unit/default_runner_tests.rb +2 -5
  42. data/test/unit/default_suite_tests.rb +51 -53
  43. data/test/unit/factory_tests.rb +3 -3
  44. data/test/unit/file_line_tests.rb +31 -33
  45. data/test/unit/macro_tests.rb +9 -10
  46. data/test/unit/result_tests.rb +150 -163
  47. data/test/unit/runner_tests.rb +63 -63
  48. data/test/unit/suite_tests.rb +57 -54
  49. data/test/unit/test_tests.rb +134 -126
  50. data/test/unit/utils_tests.rb +41 -45
  51. data/test/unit/view_helpers_tests.rb +55 -52
  52. data/test/unit/view_tests.rb +20 -22
  53. metadata +11 -4
@@ -10,23 +10,24 @@ require "assert/view"
10
10
  class Assert::Runner
11
11
  class UnitTests < Assert::Context
12
12
  desc "Assert::Runner"
13
- subject{ Assert::Runner }
13
+ subject { Assert::Runner }
14
14
 
15
15
  should "include the config helpers" do
16
- assert_includes Assert::ConfigHelpers, subject
16
+ assert_that(subject).includes(Assert::ConfigHelpers)
17
17
  end
18
18
  end
19
19
 
20
20
  class InitTests < UnitTests
21
21
  desc "when init"
22
- setup do
23
- @config = Factory.modes_off_config
24
- @config.suite Assert::DefaultSuite.new(@config)
25
- @config.view Assert::View.new(@config, StringIO.new("", "w+"))
22
+ subject { runner1 }
26
23
 
27
- @runner = Assert::Runner.new(@config)
24
+ setup do
25
+ config1.suite Assert::DefaultSuite.new(config1)
26
+ config1.view Assert::View.new(config1, StringIO.new("", "w+"))
28
27
  end
29
- subject{ @runner }
28
+
29
+ let(:config1) { Factory.modes_off_config }
30
+ let(:runner1) { Assert::Runner.new(config1) }
30
31
 
31
32
  should have_readers :config
32
33
  should have_imeths :runner, :run
@@ -35,116 +36,115 @@ class Assert::Runner
35
36
  should have_imeths :before_test, :after_test, :on_result
36
37
 
37
38
  should "know its config" do
38
- assert_equal @config, subject.config
39
+ assert_that(subject.config).equals(config1)
39
40
  end
40
41
 
41
42
  should "override the config helper's runner value with itself" do
42
- assert_equal subject, subject.runner
43
+ assert_that(subject.runner).equals(subject)
43
44
  end
44
45
  end
45
46
 
46
47
  class RunTests < InitTests
47
48
  desc "and run"
48
- setup do
49
- @runner_class = Class.new(Assert::Runner) do
50
- include CallbackMixin
51
- end
52
- suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
53
- view_class = Class.new(Assert::View){ include CallbackMixin }
54
49
 
50
+ setup do
55
51
  @view_output = ""
56
52
 
57
- @config.suite suite_class.new(@config)
58
- @config.view view_class.new(@config, StringIO.new(@view_output, "w+"))
53
+ suite_class = Class.new(Assert::DefaultSuite){ include CallbackMixin }
54
+ view_class = Class.new(Assert::View){ include CallbackMixin }
59
55
 
60
- @ci = Factory.context_info(Factory.modes_off_context_class)
61
- @test = Factory.test("should pass", @ci){ assert(1==1) }
62
- @config.suite.on_test(@test)
56
+ config1.suite suite_class.new(config1)
57
+ config1.view view_class.new(config1, StringIO.new(@view_output, "w+"))
58
+ config1.suite.on_test(test1)
63
59
 
64
- @runner = @runner_class.new(@config)
65
- @result = @runner.run
60
+ @result = subject.run
66
61
  end
67
62
 
63
+ let(:runner_class1) { Class.new(Assert::Runner) { include CallbackMixin } }
64
+ let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
65
+ let(:test1) { Factory.test("should pass", ci1){ assert(1==1) } }
66
+ let(:runner1) { runner_class1.new(config1) }
67
+
68
68
  should "return the fail+error result count as an integer exit code" do
69
- assert_equal 0, @result
69
+ assert_that(@result).equals(0)
70
70
 
71
71
  fail_count = Factory.integer
72
72
  error_count = Factory.integer
73
73
  Assert.stub(subject, :fail_result_count){ fail_count }
74
74
  Assert.stub(subject, :error_result_count){ error_count }
75
- Assert.stub(@test, :run){ } # no-op
76
- result = @runner.run
75
+ Assert.stub(test1, :run){ } # no-op
76
+ result = runner1.run
77
77
 
78
78
  exp = fail_count + error_count
79
- assert_equal exp, result
79
+ assert_that(result).equals(exp)
80
80
  end
81
81
 
82
82
  should "run all callbacks on itself, the suite and the view" do
83
83
  # itself
84
- assert_true subject.on_start_called
85
- assert_equal [@test], subject.before_test_called
86
- assert_instance_of Assert::Result::Pass, subject.on_result_called.last
87
- assert_equal [@test], subject.after_test_called
88
- assert_true subject.on_finish_called
84
+ assert_that(subject.on_start_called).is_true
85
+ assert_that(subject.before_test_called).equals([test1])
86
+ assert_that(subject.on_result_called.last).is_instance_of(Assert::Result::Pass)
87
+ assert_that(subject.after_test_called).equals([test1])
88
+ assert_that(subject.on_finish_called).is_true
89
89
 
90
90
  # suite
91
- suite = @config.suite
92
- assert_true suite.on_start_called
93
- assert_equal [@test], suite.before_test_called
94
- assert_instance_of Assert::Result::Pass, suite.on_result_called.last
95
- assert_equal [@test], suite.after_test_called
96
- assert_true suite.on_finish_called
91
+ suite = config1.suite
92
+ assert_that(suite.on_start_called).is_true
93
+ assert_that(suite.before_test_called).equals([test1])
94
+ assert_that(suite.on_result_called.last).is_instance_of(Assert::Result::Pass)
95
+ assert_that(suite.after_test_called).equals([test1])
96
+ assert_that(suite.on_finish_called).is_true
97
97
 
98
98
  # view
99
- view = @config.view
100
- assert_true view.on_start_called
101
- assert_equal [@test], view.before_test_called
102
- assert_instance_of Assert::Result::Pass, view.on_result_called.last
103
- assert_equal [@test], view.after_test_called
104
- assert_true view.on_finish_called
99
+ view = config1.view
100
+ assert_that(view.on_start_called).is_true
101
+ assert_that(view.before_test_called).equals([test1])
102
+ assert_that(view.on_result_called.last).is_instance_of(Assert::Result::Pass)
103
+ assert_that(view.after_test_called).equals([test1])
104
+ assert_that(view.on_finish_called).is_true
105
105
  end
106
106
 
107
107
  should "describe running the tests in random order if there are tests" do
108
108
  exp = "Running tests in random order, " \
109
109
  "seeded with \"#{subject.runner_seed}\"\n"
110
- assert_includes exp, @view_output
110
+ assert_that(@view_output).includes(exp)
111
111
 
112
112
  @view_output.gsub!(/./, "")
113
- @config.suite.clear_tests_to_run
113
+ config1.suite.clear_tests_to_run
114
114
  subject.run
115
- assert_not_includes exp, @view_output
115
+ assert_that(@view_output).does_not_include(exp)
116
116
  end
117
117
 
118
118
  should "run only a single test if a single test is configured" do
119
- test = Factory.test("should pass", @ci){ assert(1==1) }
120
- @config.suite.clear_tests_to_run
121
- @config.suite.on_test(test)
122
- @config.single_test test.file_line.to_s
119
+ test = Factory.test("should pass", ci1){ assert(1==1) }
120
+ config1.suite.clear_tests_to_run
121
+ config1.suite.on_test(test)
122
+ config1.single_test test.file_line.to_s
123
123
 
124
- runner = @runner_class.new(@config).tap(&:run)
125
- assert_equal [test], runner.before_test_called
124
+ runner = runner_class1.new(config1).tap(&:run)
125
+ assert_that(runner.before_test_called).equals([test])
126
126
  end
127
127
 
128
128
  should "not run any tests if a single test is configured but can't be found" do
129
- test = Factory.test("should pass", @ci){ assert(1==1) }
130
- @config.suite.clear_tests_to_run
131
- @config.suite.on_test(test)
132
- @config.single_test Factory.string
129
+ test = Factory.test("should pass", ci1){ assert(1==1) }
130
+ config1.suite.clear_tests_to_run
131
+ config1.suite.on_test(test)
132
+ config1.single_test Factory.string
133
133
 
134
- runner = @runner_class.new(@config).tap(&:run)
135
- assert_nil runner.before_test_called
134
+ runner = runner_class1.new(config1).tap(&:run)
135
+ assert_that(runner.before_test_called).is_nil
136
136
  end
137
137
 
138
138
  should "describe running only a single test if a single test is configured" do
139
- @config.suite.clear_tests_to_run
140
- @config.suite.on_test(@test)
141
- @config.single_test @test.file_line.to_s
139
+ config1.suite.clear_tests_to_run
140
+ config1.suite.on_test(test1)
141
+ config1.single_test test1.file_line.to_s
142
142
  @view_output.gsub!(/./, "")
143
143
  subject.run
144
144
 
145
145
  exp = "Running test: #{subject.single_test_file_line}, " \
146
146
  "seeded with \"#{subject.runner_seed}\"\n"
147
- assert_includes exp, @view_output
147
+ assert_that(@view_output).includes(exp)
148
148
  end
149
149
  end
150
150
 
@@ -9,25 +9,24 @@ class Assert::Suite
9
9
 
10
10
  class UnitTests < Assert::Context
11
11
  desc "Assert::Suite"
12
- subject{ Assert::Suite }
12
+ subject { Assert::Suite }
13
13
 
14
14
  should "include the config helpers" do
15
- assert_includes Assert::ConfigHelpers, subject
15
+ assert_that(subject).includes(Assert::ConfigHelpers)
16
16
  end
17
17
 
18
18
  should "know its test method regex" do
19
- assert_match "test#{Factory.string}", subject::TEST_METHOD_REGEX
20
- assert_not_match "#{Factory.string}test", subject::TEST_METHOD_REGEX
19
+ assert_that(subject::TEST_METHOD_REGEX).matches("test#{Factory.string}")
20
+ assert_that(subject::TEST_METHOD_REGEX).does_not_match("#{Factory.string}test")
21
21
  end
22
22
  end
23
23
 
24
24
  class InitTests < UnitTests
25
25
  desc "when init"
26
- setup do
27
- @config = Factory.modes_off_config
28
- @suite = Assert::Suite.new(@config)
29
- end
30
- subject{ @suite }
26
+ subject { suite1 }
27
+
28
+ let(:config1) { Factory.modes_off_config }
29
+ let(:suite1) { Assert::Suite.new(config1) }
31
30
 
32
31
  should have_readers :config, :test_methods, :setups, :teardowns
33
32
  should have_accessors :start_time, :end_time
@@ -43,34 +42,34 @@ class Assert::Suite
43
42
  should have_imeths :before_test, :after_test, :on_result
44
43
 
45
44
  should "know its config" do
46
- assert_equal @config, subject.config
45
+ assert_that(subject.config).equals(config1)
47
46
  end
48
47
 
49
48
  should "default its attrs" do
50
- assert_equal [], subject.test_methods
51
- assert_equal [], subject.setups
52
- assert_equal [], subject.teardowns
49
+ assert_that(subject.test_methods).equals([])
50
+ assert_that(subject.setups).equals([])
51
+ assert_that(subject.teardowns).equals([])
53
52
 
54
- assert_equal subject.start_time, subject.end_time
53
+ assert_that(subject.end_time).equals(subject.start_time)
55
54
  end
56
55
 
57
56
  should "override the config helper's suite value with itself" do
58
- assert_equal subject, subject.suite
57
+ assert_that(subject.suite).equals(subject)
59
58
  end
60
59
 
61
60
  should "not provide any test/result count implementations" do
62
- assert_nil subject.test_count
63
- assert_nil subject.pass_result_count
64
- assert_nil subject.fail_result_count
65
- assert_nil subject.error_result_count
66
- assert_nil subject.skip_result_count
67
- assert_nil subject.ignore_result_count
61
+ assert_that(subject.test_count).is_nil
62
+ assert_that(subject.pass_result_count).is_nil
63
+ assert_that(subject.fail_result_count).is_nil
64
+ assert_that(subject.error_result_count).is_nil
65
+ assert_that(subject.skip_result_count).is_nil
66
+ assert_that(subject.ignore_result_count).is_nil
68
67
  end
69
68
 
70
69
  should "know its run time and rates" do
71
- assert_equal 0, subject.run_time
72
- assert_equal 0, subject.test_rate
73
- assert_equal 0, subject.result_rate
70
+ assert_that(subject.run_time).equals(0)
71
+ assert_that(subject.test_rate).equals(0)
72
+ assert_that(subject.result_rate).equals(0)
74
73
 
75
74
  time = Factory.integer(3).to_f
76
75
  subject.end_time = subject.start_time + time
@@ -78,67 +77,71 @@ class Assert::Suite
78
77
  Assert.stub(subject, :test_count){ count }
79
78
  Assert.stub(subject, :result_count){ count }
80
79
 
81
- assert_equal time, subject.run_time
82
- assert_equal (subject.test_count / subject.run_time), subject.test_rate
83
- assert_equal (subject.result_count / subject.run_time), subject.result_rate
80
+ assert_that(subject.run_time).equals(time)
81
+ assert_that(subject.test_rate).equals((subject.test_count / subject.run_time))
82
+ assert_that(subject.result_rate).equals((subject.result_count / subject.run_time))
84
83
  end
85
84
 
86
85
  should "add setup procs" do
87
86
  status = nil
88
- @suite.setup{ status = "setups" }
89
- @suite.startup{ status += " have been run" }
87
+ suite1.setup{ status = "setups" }
88
+ suite1.startup{ status += " have been run" }
90
89
 
91
- assert_equal 2, subject.setups.count
90
+ assert_that(subject.setups.count).equals(2)
92
91
  subject.setups.each(&:call)
93
- assert_equal "setups have been run", status
92
+ assert_that(status).equals("setups have been run")
94
93
  end
95
94
 
96
95
  should "add teardown procs" do
97
96
  status = nil
98
- @suite.teardown{ status = "teardowns" }
99
- @suite.shutdown{ status += " have been run" }
97
+ suite1.teardown{ status = "teardowns" }
98
+ suite1.shutdown{ status += " have been run" }
100
99
 
101
- assert_equal 2, subject.teardowns.count
100
+ assert_that(subject.teardowns.count).equals(2)
102
101
  subject.teardowns.each(&:call)
103
- assert_equal "teardowns have been run", status
102
+ assert_that(status).equals("teardowns have been run")
104
103
  end
105
104
  end
106
105
 
107
106
  class WithTestsLoadedTests < InitTests
108
107
  desc "with tests loaded"
108
+
109
109
  setup do
110
- ci = proc{ Factory.context_info(Factory.modes_off_context_class) }
111
- @tests = [
112
- Factory.test("should nothing", ci.call){ },
113
- Factory.test("should pass", ci.call){ assert(1==1); refute(1==0) },
114
- Factory.test("should fail", ci.call){ ignore; assert(1==0); refute(1==1) },
115
- Factory.test("should ignore", ci.call){ ignore },
116
- Factory.test("should skip", ci.call){ skip; ignore; assert(1==1) },
117
- Factory.test("should error", ci.call){ raise Exception; ignore; assert(1==1) }
118
- ]
119
- @tests.each{ |test| @suite.on_test(test) }
110
+ tests1.each{ |test| suite1.on_test(test) }
120
111
  end
121
112
 
113
+ let(:ci1) { proc{ Factory.context_info(Factory.modes_off_context_class) } }
114
+ let(:tests1) {
115
+ [
116
+ Factory.test("should nothing", ci1.call){ },
117
+ Factory.test("should pass", ci1.call){ assert(1==1); refute(1==0) },
118
+ Factory.test("should fail", ci1.call){ ignore; assert(1==0); refute(1==1) },
119
+ Factory.test("should ignore", ci1.call){ ignore },
120
+ Factory.test("should skip", ci1.call){ skip; ignore; assert(1==1) },
121
+ Factory.test("should error", ci1.call){ raise Exception; ignore; assert(1==1) }
122
+ ]
123
+ }
124
+
122
125
  should "know its tests-to-run attrs" do
123
- assert_equal @tests.size, subject.tests_to_run_count
124
- assert_true subject.tests_to_run?
126
+ assert_that(subject.tests_to_run_count).equals(tests1.size)
127
+ assert_that(subject.tests_to_run?).is_true
125
128
 
126
129
  subject.clear_tests_to_run
127
130
 
128
- assert_equal 0, subject.tests_to_run_count
129
- assert_false subject.tests_to_run?
131
+ assert_that(subject.tests_to_run_count).equals(0)
132
+ assert_that(subject.tests_to_run?).is_false
130
133
  end
131
134
 
132
135
  should "find a test to run given a file line" do
133
- test = @tests.sample
134
- assert_same test, subject.find_test_to_run(test.file_line)
136
+ test = tests1.sample
137
+ assert_that(subject.find_test_to_run(test.file_line)).is_the_same_as(test)
135
138
  end
136
139
 
137
140
  should "know its sorted tests to run" do
138
141
  sorted_tests = subject.sorted_tests_to_run{ 1 }
139
- assert_equal @tests.size, sorted_tests.size
140
- assert_kind_of Assert::Test, sorted_tests.first
141
- assert_same sorted_tests.first, subject.sorted_tests_to_run{ 1 }.first
142
+ assert_that(sorted_tests.size).equals(tests1.size)
143
+ assert_that(sorted_tests.first).is_kind_of(Assert::Test)
144
+ assert_that(subject.sorted_tests_to_run{ 1 }.first).is_the_same_as(sorted_tests.first)
142
145
  end
143
146
  end
144
147
  end
@@ -8,58 +8,57 @@ require "assert/result"
8
8
  class Assert::Test
9
9
  class UnitTests < Assert::Context
10
10
  desc "Assert::Test"
11
- setup do
12
- @context_class = Factory.modes_off_context_class{ desc "context class" }
13
- @context_info = Factory.context_info(@context_class)
14
- @config = Factory.modes_off_config
15
- @test_code = proc{ assert(true) }
16
- end
17
- subject{ Assert::Test }
11
+ subject { Assert::Test }
12
+
13
+ let(:context_class1) { Factory.modes_off_context_class { desc "context class" } }
14
+ let(:context_info1) { Factory.context_info(context_class1) }
15
+ let(:config1) { Factory.modes_off_config }
16
+ let(:test_code1) { proc { assert(true) } }
18
17
 
19
18
  should have_imeths :name_file_line_context_data, :for_block, :for_method
20
19
 
21
20
  should "know how to build the name and file line given context" do
22
21
  test_name = Factory.string
23
- data = subject.name_file_line_context_data(@context_info, test_name)
22
+ data = subject.name_file_line_context_data(context_info1, test_name)
24
23
 
25
- exp = @context_info.test_name(test_name)
26
- assert_equal exp, data[:name]
24
+ exp = context_info1.test_name(test_name)
25
+ assert_that(data[:name]).equals(exp)
27
26
 
28
- exp = @context_info.called_from
29
- assert_equal exp, data[:file_line]
27
+ exp = context_info1.called_from
28
+ assert_that(data[:file_line]).equals(exp)
30
29
  end
31
30
 
32
31
  should "build tests for a block" do
33
32
  name = Factory.string
34
- test = subject.for_block(name, @context_info, @config, &@test_code)
33
+ test = subject.for_block(name, context_info1, config1, &test_code1)
35
34
 
36
- exp = Assert::FileLine.parse(@context_info.called_from)
37
- assert_equal exp, test.file_line
35
+ exp = Assert::FileLine.parse(context_info1.called_from)
36
+ assert_that(test.file_line).equals(exp)
38
37
 
39
- exp = @context_info.test_name(name)
40
- assert_equal exp, test.name
38
+ exp = context_info1.test_name(name)
39
+ assert_that(test.name).equals(exp)
41
40
 
42
- assert_equal @context_info, test.context_info
43
- assert_equal @config, test.config
44
- assert_equal @test_code, test.code
41
+ assert_that(test.context_info).equals(context_info1)
42
+ assert_that(test.config).equals(config1)
43
+ assert_that(test.code).equals(test_code1)
45
44
  end
46
45
 
47
46
  should "build tests for a method" do
48
47
  meth = "a_test_method"
49
- test = subject.for_method(meth, @context_info, @config)
48
+ test = subject.for_method(meth, context_info1, config1)
50
49
 
51
- exp = Assert::FileLine.parse(@context_info.called_from)
52
- assert_equal exp, test.file_line
50
+ exp = Assert::FileLine.parse(context_info1.called_from)
51
+ assert_that(test.file_line).equals(exp)
53
52
 
54
- exp = @context_info.test_name(meth)
55
- assert_equal exp, test.name
53
+ exp = context_info1.test_name(meth)
54
+ assert_that(test.name).equals(exp)
56
55
 
57
- assert_equal @context_info, test.context_info
58
- assert_equal @config, test.config
56
+ assert_that(test.context_info).equals(context_info1)
57
+ assert_that(test.config).equals(config1)
59
58
 
60
- assert_kind_of Proc, test.code
59
+ assert_that(test.code).is_kind_of(Proc)
61
60
  self.instance_eval(&test.code)
62
- assert_true @a_test_method_called
61
+ assert_that(@a_test_method_called).is_true
63
62
  end
64
63
 
65
64
  def a_test_method
@@ -69,60 +68,61 @@ class Assert::Test
69
68
 
70
69
  class InitWithDataTests < UnitTests
71
70
  desc "when init with data"
72
- setup do
73
- @file_line = Assert::FileLine.new(Factory.string, Factory.integer.to_s)
74
- @meta_data = {
75
- :file_line => @file_line.to_s,
71
+ subject { test1 }
72
+
73
+ let(:file_line1) { Assert::FileLine.new(Factory.string, Factory.integer.to_s) }
74
+ let(:meta_data1) {
75
+ {
76
+ :file_line => file_line1.to_s,
76
77
  :name => Factory.string,
77
78
  :output => Factory.string,
78
79
  :run_time => Factory.float(1.0),
79
80
  }
80
-
81
- @run_data = {
82
- :context_info => @context_info,
83
- :config => @config,
84
- :code => @test_code
81
+ }
82
+ let(:run_data1) {
83
+ {
84
+ :context_info => context_info1,
85
+ :config => config1,
86
+ :code => test_code1
85
87
  }
86
-
87
- @test = Assert::Test.new(@meta_data.merge(@run_data))
88
- end
89
- subject{ @test }
88
+ }
89
+ let(:test1) { Assert::Test.new(meta_data1.merge(run_data1)) }
90
90
 
91
91
  should have_imeths :file_line, :file_name, :line_num
92
92
  should have_imeths :name, :output, :run_time
93
93
  should have_imeths :context_info, :context_class, :config, :code, :run
94
94
 
95
95
  should "use any given attrs" do
96
- assert_equal @file_line, subject.file_line
97
- assert_equal @meta_data[:name], subject.name
98
- assert_equal @meta_data[:output], subject.output
99
- assert_equal @meta_data[:run_time], subject.run_time
96
+ assert_that(subject.file_line).equals(file_line1)
97
+ assert_that(subject.name).equals(meta_data1[:name])
98
+ assert_that(subject.output).equals(meta_data1[:output])
99
+ assert_that(subject.run_time).equals(meta_data1[:run_time])
100
100
 
101
- assert_equal @context_info, subject.context_info
102
- assert_equal @config, subject.config
103
- assert_equal @test_code, subject.code
101
+ assert_that(subject.context_info).equals(context_info1)
102
+ assert_that(subject.config).equals(config1)
103
+ assert_that(subject.code).equals(test_code1)
104
104
  end
105
105
 
106
106
  should "default its attrs" do
107
107
  test = Assert::Test.new
108
108
 
109
- assert_equal Assert::FileLine.parse(""), test.file_line
110
- assert_equal "", test.name
111
- assert_equal "", test.output
112
- assert_equal 0, test.run_time
109
+ assert_that(test.file_line).equals(Assert::FileLine.parse(""))
110
+ assert_that(test.name).equals("")
111
+ assert_that(test.output).equals("")
112
+ assert_that(test.run_time).equals(0)
113
113
 
114
- assert_nil test.context_info
115
- assert_nil test.config
116
- assert_nil test.code
114
+ assert_that(test.context_info).is_nil
115
+ assert_that(test.config).is_nil
116
+ assert_that(test.code).is_nil
117
117
  end
118
118
 
119
119
  should "know its context class" do
120
- assert_equal @context_class, subject.context_class
120
+ assert_that(subject.context_class).equals(context_class1)
121
121
  end
122
122
 
123
123
  should "know its file line attrs" do
124
- assert_equal subject.file_line.file, subject.file_name
125
- assert_equal subject.file_line.line.to_i, subject.line_num
124
+ assert_that(subject.file_name).equals(subject.file_line.file)
125
+ assert_that(subject.line_num).equals(subject.file_line.line.to_i)
126
126
  end
127
127
 
128
128
  should "have a custom inspect that only shows limited attributes" do
@@ -130,58 +130,62 @@ class Assert::Test
130
130
  "@#{method}=#{subject.send(method).inspect}"
131
131
  end.join(" ")
132
132
  exp = "#<#{subject.class}:#{"0x0%x" % (subject.object_id << 1)} #{attrs}>"
133
- assert_equal exp, subject.inspect
133
+ assert_that(subject.inspect).equals(exp)
134
134
  end
135
135
  end
136
136
 
137
137
  class PassFailIgnoreHandlingTests < UnitTests
138
138
  include Assert::Test::TestHelpers
139
139
 
140
+ subject { test1 }
141
+
140
142
  setup do
141
- @test = Factory.test("pass fail ignore test", @context_info) do
143
+ subject.context_class.setup do
142
144
  ignore("something")
143
145
  assert(true)
144
146
  assert(false)
145
147
  end
146
- @test.context_class.setup do
148
+ subject.context_class.teardown do
147
149
  ignore("something")
148
150
  assert(true)
149
151
  assert(false)
150
152
  end
151
- @test.context_class.teardown do
153
+ subject.run(&test_run_callback)
154
+ end
155
+
156
+ let(:test1) {
157
+ Factory.test("pass fail ignore test", context_info1) do
152
158
  ignore("something")
153
159
  assert(true)
154
160
  assert(false)
155
161
  end
156
- @test.run(&test_run_callback)
157
- end
158
- subject{ @test }
162
+ }
159
163
 
160
164
  should "capture results in the test and any setups/teardowns" do
161
- assert_equal 9, test_run_results.size
165
+ assert_that(test_run_results.size).equals(9)
162
166
  test_run_results.each do |result|
163
- assert_kind_of Assert::Result::Base, result
167
+ assert_that(result).is_kind_of(Assert::Result::Base)
164
168
  end
165
169
  end
166
170
 
167
171
  should "capture pass results in the test and any setups/teardowns" do
168
- assert_equal 3, test_run_results(:pass).size
172
+ assert_that(test_run_results(:pass).size).equals(3)
169
173
  test_run_results(:pass).each do |result|
170
- assert_kind_of Assert::Result::Pass, result
174
+ assert_that(result).is_kind_of(Assert::Result::Pass)
171
175
  end
172
176
  end
173
177
 
174
178
  should "capture fail results in the test and any setups/teardowns" do
175
- assert_equal 3, test_run_results(:fail).size
179
+ assert_that(test_run_results(:fail).size).equals(3)
176
180
  test_run_results(:fail).each do |result|
177
- assert_kind_of Assert::Result::Fail, result
181
+ assert_that(result).is_kind_of(Assert::Result::Fail)
178
182
  end
179
183
  end
180
184
 
181
185
  should "capture ignore results in the test and any setups/teardowns" do
182
- assert_equal 3, test_run_results(:ignore).size
186
+ assert_that(test_run_results(:ignore).size).equals(3)
183
187
  test_run_results(:ignore).each do |result|
184
- assert_kind_of Assert::Result::Ignore, result
188
+ assert_that(result).is_kind_of(Assert::Result::Ignore)
185
189
  end
186
190
  end
187
191
  end
@@ -192,7 +196,7 @@ class Assert::Test
192
196
  desc "when in halt-on-fail mode"
193
197
 
194
198
  should "capture fail results" do
195
- test = Factory.test("halt-on-fail test", @context_info) do
199
+ test = Factory.test("halt-on-fail test", context_info1) do
196
200
  raise Assert::Result::TestFailure
197
201
  end
198
202
  test.run(&test_run_callback)
@@ -201,7 +205,7 @@ class Assert::Test
201
205
  end
202
206
 
203
207
  should "capture fails in the context setup" do
204
- test = Factory.test("setup halt-on-fail test", @context_info){ }
208
+ test = Factory.test("setup halt-on-fail test", context_info1){ }
205
209
  test.context_class.setup{ raise Assert::Result::TestFailure }
206
210
  test.run(&test_run_callback)
207
211
 
@@ -209,7 +213,7 @@ class Assert::Test
209
213
  end
210
214
 
211
215
  should "capture fails in the context teardown" do
212
- test = Factory.test("teardown halt-on-fail test", @context_info){ }
216
+ test = Factory.test("teardown halt-on-fail test", context_info1){ }
213
217
  test.context_class.teardown{ raise Assert::Result::TestFailure }
214
218
  test.run(&test_run_callback)
215
219
 
@@ -220,9 +224,9 @@ class Assert::Test
220
224
 
221
225
  def assert_failed(test)
222
226
  with_backtrace(caller) do
223
- assert_equal 1, test_run_result_count, "too many/few fail results"
227
+ assert_that(test_run_result_count).equals(1, "too many/few fail results")
224
228
  test_run_results.each do |result|
225
- assert_kind_of Assert::Result::Fail, result, "not a fail result"
229
+ assert_that(result).is_kind_of(Assert::Result::Fail, "not a fail result")
226
230
  end
227
231
  end
228
232
  end
@@ -232,14 +236,14 @@ class Assert::Test
232
236
  include Assert::Test::TestHelpers
233
237
 
234
238
  should "capture skip results" do
235
- test = Factory.test("skip test", @context_info){ skip }
239
+ test = Factory.test("skip test", context_info1){ skip }
236
240
  test.run(&test_run_callback)
237
241
 
238
242
  assert_skipped(test)
239
243
  end
240
244
 
241
245
  should "capture skips in the context setup" do
242
- test = Factory.test("setup skip test", @context_info){ }
246
+ test = Factory.test("setup skip test", context_info1){ }
243
247
  test.context_class.setup{ skip }
244
248
  test.run(&test_run_callback)
245
249
 
@@ -247,7 +251,7 @@ class Assert::Test
247
251
  end
248
252
 
249
253
  should "capture skips in the context teardown" do
250
- test = Factory.test("teardown skip test", @context_info){ }
254
+ test = Factory.test("teardown skip test", context_info1){ }
251
255
  test.context_class.teardown{ skip }
252
256
  test.run(&test_run_callback)
253
257
 
@@ -258,9 +262,9 @@ class Assert::Test
258
262
 
259
263
  def assert_skipped(test)
260
264
  with_backtrace(caller) do
261
- assert_equal 1, test_run_result_count, "too many/few skip results"
265
+ assert_that(test_run_result_count).equals(1, "too many/few skip results")
262
266
  test_run_results.each do |result|
263
- assert_kind_of Assert::Result::Skip, result, "not a skip result"
267
+ assert_that(result).is_kind_of(Assert::Result::Skip, "not a skip result")
264
268
  end
265
269
  end
266
270
  end
@@ -270,7 +274,7 @@ class Assert::Test
270
274
  include Assert::Test::TestHelpers
271
275
 
272
276
  should "capture error results" do
273
- test = Factory.test("error test", @context_info) do
277
+ test = Factory.test("error test", context_info1) do
274
278
  raise StandardError, "WHAT"
275
279
  end
276
280
  test.run(&test_run_callback)
@@ -279,7 +283,7 @@ class Assert::Test
279
283
  end
280
284
 
281
285
  should "capture errors in the context setup" do
282
- test = Factory.test("setup error test", @context_info){ }
286
+ test = Factory.test("setup error test", context_info1){ }
283
287
  test.context_class.setup{ raise "an error" }
284
288
  test.run(&test_run_callback)
285
289
 
@@ -287,7 +291,7 @@ class Assert::Test
287
291
  end
288
292
 
289
293
  should "capture errors in the context teardown" do
290
- test = Factory.test("teardown error test", @context_info){ }
294
+ test = Factory.test("teardown error test", context_info1){ }
291
295
  test.context_class.teardown{ raise "an error" }
292
296
  test.run(&test_run_callback)
293
297
 
@@ -298,100 +302,104 @@ class Assert::Test
298
302
 
299
303
  def assert_errored(test)
300
304
  with_backtrace(caller) do
301
- assert_equal 1, test_run_result_count, "too many/few error results"
305
+ assert_that(test_run_result_count).equals(1, "too many/few error results")
302
306
  test_run_results.each do |result|
303
- assert_kind_of Assert::Result::Error, result, "not an error result"
307
+ assert_that(result).is_kind_of(Assert::Result::Error, "not an error result")
304
308
  end
305
309
  end
306
310
  end
307
311
  end
308
312
 
309
313
  class SignalExceptionHandlingTests < UnitTests
310
-
311
314
  should "raise any signal exceptions and not capture as an error" do
312
- test = Factory.test("signal test", @context_info) do
315
+ test = Factory.test("signal test", context_info1) do
313
316
  raise SignalException, "USR1"
314
317
  end
315
318
 
316
- assert_raises(SignalException){ test.run }
319
+ assert_that(-> { test.run }).raises(SignalException)
317
320
  end
318
321
 
319
322
  should "raises signal exceptions in the context setup" do
320
- test = Factory.test("setup signal test", @context_info){ }
323
+ test = Factory.test("setup signal test", context_info1){ }
321
324
  test.context_class.setup{ raise SignalException, "INT" }
322
325
 
323
- assert_raises(SignalException){ test.run }
326
+ assert_that(-> { test.run }).raises(SignalException)
324
327
  end
325
328
 
326
329
  should "raises signal exceptions in the context teardown" do
327
- test = Factory.test("teardown signal test", @context_info){ }
330
+ test = Factory.test("teardown signal test", context_info1){ }
328
331
  test.context_class.teardown{ raise SignalException, "TERM" }
329
332
 
330
- assert_raises(SignalException){ test.run }
333
+ assert_that(-> { test.run }).raises(SignalException)
331
334
  end
332
335
  end
333
336
 
334
337
  class ComparingTests < UnitTests
335
338
  desc "<=> another test"
336
- setup do
337
- @test = Factory.test("mmm")
338
- end
339
- subject{ @test }
339
+ subject { test1 }
340
+
341
+ let(:test1) { Factory.test("mmm") }
340
342
 
341
343
  should "return 1 with a test named 'aaa' (greater than it)" do
342
- result = @test <=> Factory.test("aaa")
343
- assert_equal(1, result)
344
+ result = test1 <=> Factory.test("aaa")
345
+ assert_that(result).equals(1)
344
346
  end
345
347
 
346
348
  should "return 0 with a test named the same" do
347
- result = @test <=> Factory.test(@test.name)
348
- assert_equal(0, result)
349
+ result = test1 <=> Factory.test(test1.name)
350
+ assert_that(result).equals(0)
349
351
  end
350
352
 
351
353
  should "return -1 with a test named 'zzz' (less than it)" do
352
- result = @test <=> Factory.test("zzz")
353
- assert_equal(-1, result)
354
+ result = test1 <=> Factory.test("zzz")
355
+ assert_that(result).equals(-1)
354
356
  end
355
357
  end
356
358
 
357
359
  class CaptureOutTests < UnitTests
358
360
  desc "when capturing std out"
359
- setup do
360
- @capture_config = Assert::Config.new(:capture_output => true)
361
- @test = Factory.test("stdout", @capture_config) do
361
+
362
+ let(:capture_config1) { Assert::Config.new(:capture_output => true) }
363
+ let(:test1) {
364
+ Factory.test("stdout", capture_config1) do
362
365
  puts "std out from the test"
363
366
  assert true
364
367
  end
365
- end
368
+ }
366
369
 
367
370
  should "capture any io from the test" do
368
- @test.run
369
- assert_equal "std out from the test\n", @test.output
371
+ test1.run
372
+ assert_that(test1.output).equals("std out from the test\n")
370
373
  end
371
374
  end
372
375
 
373
376
  class FullCaptureOutTests < CaptureOutTests
374
377
  desc "across setup, teardown, and meth calls"
378
+
375
379
  setup do
376
- @test = Factory.test("fullstdouttest", @capture_config) do
377
- puts "std out from the test"
378
- assert a_method_an_assert_calls
379
- end
380
- @test.context_class.setup{ puts "std out from the setup" }
381
- @test.context_class.teardown{ puts "std out from the teardown" }
382
- @test.context_class.send(:define_method, "a_method_an_assert_calls") do
380
+ test1.context_class.setup{ puts "std out from the setup" }
381
+ test1.context_class.teardown{ puts "std out from the teardown" }
382
+ test1.context_class.send(:define_method, "a_method_an_assert_calls") do
383
383
  puts "std out from a method an assert called"
384
384
  end
385
385
  end
386
386
 
387
- should "collect all stdout in the output accessor" do
388
- @test.run
387
+ let(:test1) {
388
+ Factory.test("fullstdouttest", capture_config1) do
389
+ puts "std out from the test"
390
+ assert a_method_an_assert_calls
391
+ end
392
+ }
389
393
 
390
- exp_out = "std out from the setup\n"\
391
- "std out from the test\n"\
392
- "std out from a method an assert called\n"\
393
- "std out from the teardown\n"
394
- assert_equal(exp_out, @test.output)
394
+ should "collect all stdout in the output accessor" do
395
+ test1.run
396
+
397
+ exp_out =
398
+ "std out from the setup\n"\
399
+ "std out from the test\n"\
400
+ "std out from a method an assert called\n"\
401
+ "std out from the teardown\n"
402
+ assert_that(test1.output).equals(exp_out)
395
403
  end
396
404
  end
397
405
  end