assert 2.0.0.rc.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +1 -1
  2. data/{LICENSE → LICENSE.txt} +0 -0
  3. data/Rakefile +1 -3
  4. data/assert.gemspec +15 -15
  5. data/lib/assert.rb +1 -2
  6. data/lib/assert/assert_runner.rb +2 -1
  7. data/lib/assert/assertions.rb +153 -189
  8. data/lib/assert/version.rb +1 -1
  9. data/test/helper.rb +74 -51
  10. data/test/{fixtures → support}/inherited_stuff.rb +0 -0
  11. data/test/{test → system}/running_tests.rb +16 -43
  12. data/test/{assert_test.rb → unit/assert_tests.rb} +0 -0
  13. data/test/unit/assertions/assert_block_tests.rb +57 -0
  14. data/test/unit/assertions/assert_empty_tests.rb +58 -0
  15. data/test/unit/assertions/assert_equal_tests.rb +59 -0
  16. data/test/unit/assertions/assert_file_exists_tests.rb +59 -0
  17. data/test/unit/assertions/assert_includes_tests.rb +61 -0
  18. data/test/unit/assertions/assert_instance_of_tests.rb +61 -0
  19. data/test/unit/assertions/assert_kind_of_tests.rb +60 -0
  20. data/test/unit/assertions/assert_match_tests.rb +59 -0
  21. data/test/unit/assertions/assert_nil_tests.rb +59 -0
  22. data/test/unit/assertions/assert_raises_tests.rb +73 -0
  23. data/test/unit/assertions/assert_respond_to_tests.rb +63 -0
  24. data/test/unit/assertions/assert_same_tests.rb +65 -0
  25. data/test/unit/assertions_tests.rb +65 -0
  26. data/test/unit/context/basic_singleton_tests.rb +86 -0
  27. data/test/unit/context/setup_teardown_singleton_tests.rb +105 -0
  28. data/test/unit/context/test_should_singleton_tests.rb +134 -0
  29. data/test/{context_test.rb → unit/context_tests.rb} +53 -131
  30. data/test/{macro_test.rb → unit/macro_tests.rb} +15 -11
  31. data/test/{result_test.rb → unit/result_tests.rb} +27 -26
  32. data/test/{runner_test.rb → unit/runner_tests.rb} +1 -2
  33. data/test/{suite_test.rb → unit/suite_tests.rb} +63 -95
  34. data/test/{test_test.rb → unit/test_tests.rb} +45 -77
  35. data/test/{view/base_tests.rb → unit/view_tests.rb} +0 -1
  36. metadata +63 -104
  37. data/CHANGELOG.md +0 -33
  38. data/test/assertions/assert_block_test.rb +0 -39
  39. data/test/assertions/assert_empty_test.rb +0 -43
  40. data/test/assertions/assert_equal_test.rb +0 -43
  41. data/test/assertions/assert_file_exists_test.rb +0 -43
  42. data/test/assertions/assert_includes_test.rb +0 -44
  43. data/test/assertions/assert_instance_of_test.rb +0 -43
  44. data/test/assertions/assert_kind_of_test.rb +0 -43
  45. data/test/assertions/assert_match_test.rb +0 -43
  46. data/test/assertions/assert_nil_test.rb +0 -43
  47. data/test/assertions/assert_not_block_test.rb +0 -39
  48. data/test/assertions/assert_not_empty_test.rb +0 -43
  49. data/test/assertions/assert_not_equal_test.rb +0 -43
  50. data/test/assertions/assert_not_file_exists_test.rb +0 -43
  51. data/test/assertions/assert_not_included_test.rb +0 -44
  52. data/test/assertions/assert_not_instance_of_test.rb +0 -43
  53. data/test/assertions/assert_not_kind_of_test.rb +0 -43
  54. data/test/assertions/assert_not_match_test.rb +0 -43
  55. data/test/assertions/assert_not_nil_test.rb +0 -43
  56. data/test/assertions/assert_not_respond_to_test.rb +0 -43
  57. data/test/assertions/assert_not_same_test.rb +0 -45
  58. data/test/assertions/assert_nothing_raised_test.rb +0 -46
  59. data/test/assertions/assert_raises_test.rb +0 -49
  60. data/test/assertions/assert_respond_to_test.rb +0 -43
  61. data/test/assertions/assert_same_test.rb +0 -45
  62. data/test/assertions_test.rb +0 -60
  63. data/test/context/class_methods_test.rb +0 -531
  64. data/test/fixtures/sample_context.rb +0 -13
  65. data/test/fixtures/test_root/one_test.rb +0 -0
  66. data/test/fixtures/test_root/parent/area_one/area_test.rb +0 -0
  67. data/test/fixtures/test_root/shallow/deeply/nested_test.rb +0 -0
  68. data/test/fixtures/test_root/shallow/nested_test.rb +0 -0
  69. data/test/fixtures/test_root/shallow_test.rb +0 -0
  70. data/test/fixtures/test_root/two_test.rb +0 -0
  71. data/test/suite/context_info_test.rb +0 -42
@@ -1,12 +1,11 @@
1
1
  require 'assert'
2
-
3
2
  require 'assert/suite'
4
3
  require 'assert/view/base'
5
4
  require 'assert/runner'
6
5
 
7
6
  class Assert::Runner
8
7
 
9
- class BasicTest < Assert::Context
8
+ class BasicTests < Assert::Context
10
9
  desc "a basic runner"
11
10
  setup do
12
11
  @suite = Assert::Suite.new
@@ -1,76 +1,55 @@
1
1
  require 'assert'
2
-
3
2
  require 'assert/suite'
4
- require 'assert/context'
5
3
  require 'assert/test'
6
- require 'test/fixtures/inherited_stuff'
7
- require 'test/fixtures/sample_context'
8
-
4
+ require 'test/support/inherited_stuff'
9
5
 
10
6
  class Assert::Suite
11
7
 
12
- class BasicTest < Assert::Context
8
+ class BasicTests < Assert::Context
13
9
  desc "an basic suite"
14
10
  setup do
15
11
  @suite = Assert::Suite.new
16
12
  end
17
- subject { @suite }
18
-
19
- should have_instance_methods :ordered_tests, :results, :ordered_results
20
- should have_instance_methods :count, :test_count, :result_count
21
- should have_instance_methods :setup, :startup, :teardown, :shutdown
13
+ subject{ @suite }
22
14
 
23
- should have_accessors :tests, :test_methods
24
- should have_accessors :start_time, :end_time
25
- should have_instance_method :run_time
15
+ should have_imeths :ordered_tests, :results, :ordered_results, :run_time
16
+ should have_imeths :count, :test_count, :result_count
17
+ should have_imeths :setup, :startup, :teardown, :shutdown
18
+ should have_accessors :tests, :test_methods, :start_time, :end_time
26
19
 
27
20
  should "determine a klass' local public test methods" do
28
- assert_equal(
29
- ["test_subclass_stuff", "test_mixin_stuff", "test_repeated"].sort,
30
- subject.send(:local_public_test_methods, SubStuff).sort.collect(&:to_s)
31
- )
21
+ exp = ["test_subclass_stuff", "test_mixin_stuff", "test_repeated"].sort
22
+ act = subject.send(:local_public_test_methods, SubStuff).sort.map(&:to_s)
23
+ assert_equal(exp, act)
32
24
  end
33
25
 
34
- should "have zero run time by default" do
26
+ should "have zero a run time by default" do
35
27
  assert_equal 0, subject.run_time
36
28
  end
37
29
 
38
30
  end
39
31
 
40
- class WithTestsTest < Assert::Context
32
+ class WithTestsTests < Assert::Context
41
33
  desc "a suite with tests"
42
34
  setup do
35
+ ci = Factory.context_info(Factory.context_class)
43
36
  @suite = Assert::Suite.new
44
- context_class = Factory.context_class
45
37
  @suite.tests = [
46
- Factory.test("should do nothing", Factory.context_info(context_class)),
47
- Factory.test("should pass", Factory.context_info(context_class)) do
48
- assert(1==1)
49
- refute(1==0)
50
- end,
51
- Factory.test("should fail", Factory.context_info(context_class)) do
52
- ignore
53
- assert(1==0)
54
- refute(1==1)
55
- end,
56
- Factory.test("should be ignored", Factory.context_info(context_class)) do
57
- ignore
58
- end,
59
- Factory.test("should skip", Factory.context_info(context_class)) do
60
- skip
61
- ignore
62
- assert(1==1)
63
- end,
64
- Factory.test("should error", Factory.context_info(context_class)) do
65
- raise Exception
66
- ignore
67
- assert(1==1)
68
- end
38
+ Factory.test("should nothing", ci){ },
39
+ Factory.test("should pass", ci){ assert(1==1); refute(1==0) },
40
+ Factory.test("should fail", ci){ ignore; assert(1==0); refute(1==1) },
41
+ Factory.test("should ignored", ci){ ignore },
42
+ Factory.test("should skip", ci){ skip; ignore; assert(1==1) },
43
+ Factory.test("should error", ci){ raise Exception; ignore; assert(1==1) }
69
44
  ]
70
45
  @suite.tests.each(&:run)
71
46
  end
72
47
  subject{ @suite }
73
48
 
49
+ should "build test instances to run" do
50
+ assert_kind_of Assert::Test, subject.tests.first
51
+ end
52
+
74
53
  should "know how many tests it has" do
75
54
  assert_equal 6, subject.test_count
76
55
  end
@@ -107,10 +86,6 @@ class Assert::Suite
107
86
  assert_equal 1, subject.result_count(:error)
108
87
  end
109
88
 
110
- end
111
-
112
- class CountTest < WithTestsTest
113
-
114
89
  should "count its tests" do
115
90
  assert_equal subject.test_count, subject.count(:tests)
116
91
  end
@@ -146,58 +121,33 @@ class Assert::Suite
146
121
 
147
122
  end
148
123
 
149
-
150
- class TestsTest < WithTestsTest
151
-
152
- should "build test instances to run" do
153
- assert_kind_of Assert::Test, subject.tests.first
154
- end
155
-
156
- end
157
-
158
-
159
-
160
- class SetupTest < Assert::Context
161
- desc "a suite with a setup"
124
+ class SetupTests < Assert::Context
125
+ desc "a suite with a setup block"
162
126
  setup do
163
127
  @setup_status = nil
164
128
  @suite = Assert::Suite.new
165
129
  @setup_blocks = []
166
130
  @setup_blocks << ::Proc.new{ @setup_status = "setup" }
167
131
  @setup_blocks << ::Proc.new{ @setup_status += " has been run" }
168
- @setup_blocks.each do |setup_block|
169
- @suite.setup(&setup_block)
170
- end
171
- @expected = "setup has been run"
132
+ @setup_blocks.each{ |setup_block| @suite.setup(&setup_block) }
172
133
  end
173
134
  subject{ @setup_status }
174
135
 
175
136
  should "set the setup status to the correct message" do
176
137
  @suite.setup
177
- assert_equal @expected, subject
138
+ assert_equal "setup has been run", subject
178
139
  end
179
140
 
180
- end
181
-
182
-
183
-
184
- class SetupsTest < SetupTest
185
- desc "when calling the setups method"
186
- setup do
187
- @setups = @suite.send(:setups)
188
- end
189
- subject{ @setups }
190
-
191
- should "include the setup we defined on the suite" do
141
+ should "return the setup blocks with the #setups method" do
142
+ setups = @suite.send(:setups)
192
143
  @setup_blocks.each do |setup_block|
193
- assert_includes setup_block, subject
144
+ assert_includes setup_block, setups
194
145
  end
195
146
  end
196
- end
197
-
198
147
 
148
+ end
199
149
 
200
- class TeardownTest < Assert::Context
150
+ class TeardownTests < Assert::Context
201
151
  desc "a suite with a teardown"
202
152
  setup do
203
153
  @teardown_status = nil
@@ -205,10 +155,7 @@ class Assert::Suite
205
155
  @teardown_blocks = []
206
156
  @teardown_blocks << ::Proc.new{ @teardown_status += " has been run" }
207
157
  @teardown_blocks << ::Proc.new{ @teardown_status = "teardown" }
208
- @teardown_blocks.each do |teardown_block|
209
- @suite.teardown(&teardown_block)
210
- end
211
- @expected = "teardown has been run"
158
+ @teardown_blocks.each{ |teardown_block| @suite.teardown(&teardown_block) }
212
159
  end
213
160
 
214
161
  should "set the teardown status to the correct message" do
@@ -216,22 +163,43 @@ class Assert::Suite
216
163
  assert_equal "teardown has been run", @teardown_status
217
164
  end
218
165
 
166
+ should "return the teardown blocks with the #teardowns method" do
167
+ teardowns = @suite.send(:teardowns)
168
+ @teardown_blocks.each do |setup_block|
169
+ assert_includes setup_block, teardowns
170
+ end
171
+ end
172
+
219
173
  end
220
174
 
175
+ class ContextInfoTests < Assert::Context
176
+ desc "a suite's context info"
177
+ setup do
178
+ @caller = caller
179
+ @klass = Assert::Context
180
+ @info = Assert::Suite::ContextInfo.new(@klass, nil, @caller.first)
181
+ end
182
+ subject{ @info }
221
183
 
184
+ should have_readers :called_from, :first_caller, :klass, :file
222
185
 
223
- class TeardownsTest < TeardownTest
224
- desc "when calling the teardowns method"
225
- setup do
226
- @teardowns = @suite.send(:teardowns)
186
+ should "set its klass on init" do
187
+ assert_equal @klass, subject.klass
227
188
  end
228
- subject{ @teardowns }
229
189
 
230
- should "include the teardown we defined on the suite" do
231
- @teardown_blocks.each do |teardown_block|
232
- assert_includes teardown_block, subject
233
- end
190
+ should "set its called_from to the first caller on init" do
191
+ assert_equal @caller.first, subject.first_caller
234
192
  end
193
+
194
+ should "set its file from caller info on init" do
195
+ assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ''), subject.file
196
+ end
197
+
198
+ should "not have any file info if no caller is given" do
199
+ info = Assert::Suite::ContextInfo.new(@klass)
200
+ assert_nil info.file
201
+ end
202
+
235
203
  end
236
204
 
237
205
  end
@@ -1,19 +1,15 @@
1
1
  require 'assert'
2
+ require 'assert/test'
2
3
 
3
4
  class Assert::Test
4
5
 
5
- class BasicTest < Assert::Context
6
- desc "Assert test"
6
+ class BasicTests < Assert::Context
7
+ desc "a test obj"
7
8
  setup do
8
- test_name = "should do something amazing"
9
9
  @test_code = lambda{ assert(true) }
10
- context_desc = "context class"
11
- @context_class = Factory.context_class do
12
- desc context_desc
13
- end
14
- @context_info = Factory.context_info(@context_class)
15
- @test = Factory.test(test_name, @context_info, @test_code)
16
- @expected_name = [ context_desc, test_name.gsub(/^test:\s+should/, "should") ].join(" ")
10
+ @context_class = Factory.context_class { desc "context class" }
11
+ @context_info = Factory.context_info(@context_class)
12
+ @test = Factory.test("should do something amazing", @context_info, @test_code)
17
13
  end
18
14
  teardown do
19
15
  TEST_ASSERT_SUITE.tests.clear
@@ -21,15 +17,16 @@ class Assert::Test
21
17
  subject{ @test }
22
18
 
23
19
  should have_readers :name, :code, :context_info
24
- should have_accessor :results, :output
25
- should have_instance_methods :run, :result_count, :context_class
26
- should have_instance_methods *Assert::Result.types.keys.collect{|k| "#{k}_results".to_sym }
20
+ should have_accessors :results, :output
21
+ should have_imeths :run, :result_count, :context_class
22
+ should have_imeths *Assert::Result.types.keys.collect{ |k| "#{k}_results" }
27
23
 
28
- should "set it's test name to the context description with the passed in name cleaned" do
29
- assert_equal @expected_name, subject.name
24
+ should "build its name from the context description" do
25
+ exp_name = "context class should do something amazing"
26
+ assert_equal exp_name, subject.name
30
27
  end
31
28
 
32
- should "set it's context class and code from its initialize" do
29
+ should "know it's context class and code" do
33
30
  assert_equal @context_class, subject.context_class
34
31
  assert_equal @test_code, subject.code
35
32
  end
@@ -39,22 +36,16 @@ class Assert::Test
39
36
  end
40
37
 
41
38
  should "have a custom inspect that only shows limited attributes" do
42
- attributes_string = [ :name, :context_info, :results ].collect do |method|
39
+ attrs_string = [:name, :context_info, :results].collect do |method|
43
40
  "@#{method}=#{subject.send(method).inspect}"
44
41
  end.join(" ")
45
- expected = "#<#{subject.class} #{attributes_string}>"
42
+ expected = "#<#{subject.class} #{attrs_string}>"
46
43
  assert_equal expected, subject.inspect
47
44
  end
48
45
 
49
46
  end
50
47
 
51
-
52
- # testing <type>_results methods and result_count(<type>)
53
- class ResultsTest < BasicTest
54
- desc "methods from Assert::Result.types"
55
- end
56
-
57
- class PassFailIgnoreTest < ResultsTest
48
+ class PassFailIgnoreTotalTests < BasicTests
58
49
  setup do
59
50
  @test = Factory.test("pass fail ignore test", @context_info) do
60
51
  ignore("something")
@@ -68,74 +59,58 @@ class Assert::Test
68
59
  end
69
60
  subject{ @test }
70
61
 
71
- should "return the pass results with #pass_results" do
62
+ should "know its pass results" do
72
63
  assert_kind_of Array, subject.pass_results
73
64
  assert_equal 2, subject.pass_results.size
74
65
  subject.pass_results.each do |result|
75
66
  assert_kind_of Assert::Result::Pass, result
76
67
  end
68
+ assert_equal subject.pass_results.size, subject.result_count(:pass)
77
69
  end
78
70
 
79
- should "return the size of #pass_results with #result_count(:pass)" do
80
- assert_equal(subject.pass_results.size, subject.result_count(:pass))
81
- end
82
-
83
- should "return the fail results with #fail_results" do
71
+ should "know its fail results" do
84
72
  assert_kind_of Array, subject.fail_results
85
73
  assert_equal 2, subject.fail_results.size
86
74
  subject.fail_results.each do |result|
87
75
  assert_kind_of Assert::Result::Fail, result
88
76
  end
77
+ assert_equal subject.fail_results.size, subject.result_count(:fail)
89
78
  end
90
79
 
91
- should "return the size of #fail_results with #result_count(:fail)" do
92
- assert_equal(subject.fail_results.size, subject.result_count(:fail))
93
- end
94
-
95
- should "return the ignore results with #ignore_results" do
80
+ should "know its ignore results" do
96
81
  assert_kind_of Array, subject.ignore_results
97
82
  assert_equal 2, subject.ignore_results.size
98
83
  subject.ignore_results.each do |result|
99
84
  assert_kind_of Assert::Result::Ignore, result
100
85
  end
86
+ assert_equal subject.ignore_results.size, subject.result_count(:ignore)
101
87
  end
102
88
 
103
- should "return the size of #ignore_results with #result_count(:ignore)" do
104
- assert_equal(subject.ignore_results.size, subject.result_count(:ignore))
105
- end
106
-
107
- should "return the total number of tests with #result_count" do
89
+ should "know the total number of results" do
108
90
  assert_equal(6, subject.result_count)
109
91
  end
110
92
 
111
93
  end
112
94
 
113
-
114
-
115
- class SkipHandlingTest < ResultsTest
95
+ class SkipHandlingTests < BasicTests
116
96
  setup do
117
97
  @test = Factory.test("skip test", @context_info) { skip }
118
98
  @test.run
119
99
  end
120
100
  subject{ @test }
121
101
 
122
- should "return the skip results with #skip_results" do
102
+ should "know its skip results" do
123
103
  assert_kind_of Array, subject.skip_results
124
104
  assert_equal 1, subject.skip_results.size
125
105
  subject.skip_results.each do |result|
126
106
  assert_kind_of Assert::Result::Skip, result
127
107
  end
128
- end
129
-
130
- should "return the size of #skip_results with #result_count(:skip)" do
131
- assert_equal(subject.skip_results.size, subject.result_count(:skip))
108
+ assert_equal subject.skip_results.size, subject.result_count(:skip)
132
109
  end
133
110
 
134
111
  end
135
112
 
136
-
137
-
138
- class ErrorHandlingTest < ResultsTest
113
+ class ErrorHandlingTests < BasicTests
139
114
  setup do
140
115
  @test = Factory.test("error test", @context_info) do
141
116
  raise StandardError, "WHAT"
@@ -144,23 +119,18 @@ class Assert::Test
144
119
  end
145
120
  subject{ @test }
146
121
 
147
- should "return the error results with #error_results" do
122
+ should "know its error results" do
148
123
  assert_kind_of Array, subject.error_results
149
124
  assert_equal 1, subject.error_results.size
150
125
  subject.error_results.each do |result|
151
126
  assert_kind_of Assert::Result::Error, result
152
127
  end
153
- end
154
-
155
- should "return the size of #error_results with #result_count(:error)" do
156
- assert_equal(subject.error_results.size, subject.result_count(:error))
128
+ assert_equal subject.error_results.size, subject.result_count(:error)
157
129
  end
158
130
 
159
131
  end
160
132
 
161
-
162
-
163
- class ComparingTest < BasicTest
133
+ class ComparingTests < BasicTests
164
134
  desc "<=> another test"
165
135
  setup do
166
136
  @test = Factory.test("mmm")
@@ -184,19 +154,19 @@ class Assert::Test
184
154
 
185
155
  end
186
156
 
187
- class CaptureOutTest < BasicTest
157
+ class CaptureOutTests < BasicTests
188
158
  desc "when capturing std out"
189
- setup {
159
+ setup do
190
160
  @test = Factory.test("stdout") {
191
161
  puts "std out from the test"
192
162
  assert true
193
163
  }
194
164
  @orig_show = Assert.config.show_output
195
165
  Assert.config.show_output false
196
- }
197
- teardown {
166
+ end
167
+ teardown do
198
168
  Assert.config.show_output @orig_show
199
- }
169
+ end
200
170
 
201
171
  should "capture any io from the test" do
202
172
  @test.run
@@ -205,30 +175,28 @@ class Assert::Test
205
175
 
206
176
  end
207
177
 
208
- class FullCaptureOutTest < CaptureOutTest
178
+ class FullCaptureOutTests < CaptureOutTests
209
179
  desc "across setup, teardown, and meth calls"
210
180
  setup do
211
- @test = Factory.test("fullstdouttest") {
181
+ @test = Factory.test("fullstdouttest") do
212
182
  puts "std out from the test"
213
- assert a_method_an_assert_calls.inspect
214
- }
183
+ assert a_method_an_assert_calls
184
+ end
215
185
  @test.context_class.setup { puts "std out from the setup" }
216
186
  @test.context_class.teardown { puts "std out from the teardown" }
217
187
  @test.context_class.send(:define_method, "a_method_an_assert_calls") do
218
188
  puts "std out from a method an assert called"
219
- true
220
189
  end
221
190
  end
222
191
 
223
- should "collect it on itself in the output accessor" do
192
+ should "collect all stdout in the output accessor" do
224
193
  @test.run
225
194
 
226
- assert_equal([
227
- "std out from the setup",
228
- "std out from the test",
229
- "std out from a method an assert called",
230
- "std out from the teardown\n"
231
- ].join("\n"), @test.output)
195
+ exp_out = "std out from the setup\n"\
196
+ "std out from the test\n"\
197
+ "std out from a method an assert called\n"\
198
+ "std out from the teardown\n"
199
+ assert_equal(exp_out, @test.output)
232
200
  end
233
201
  end
234
202