assert 0.6.0 → 0.7.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.
@@ -0,0 +1,63 @@
1
+ require 'assert'
2
+
3
+ require 'assert/rake_tasks/scope'
4
+
5
+ module Assert::RakeTasks
6
+
7
+ class ScopeTests < Assert::Context
8
+ desc "the scope rake tasks handler"
9
+ setup do
10
+ @scope_root = 'test/fixtures'
11
+ @handler = Assert::RakeTasks::Scope.new(File.join(@scope_root, 'test_root'))
12
+ end
13
+ subject { @handler }
14
+
15
+ should have_class_methods :test_file_suffix
16
+ should have_instance_methods :namespace, :nested_files, :path_file_list, :to_test_task
17
+ should have_instance_methods :test_tasks, :scopes
18
+
19
+ should "know its the test file suffix" do
20
+ assert_equal "_test.rb", subject.class.test_file_suffix
21
+ end
22
+
23
+ should "know its namespace" do
24
+ assert_equal :test_root, subject.namespace
25
+ assert_equal :shallow, Assert::RakeTasks::Scope.new(File.join(@scope_root, 'test_root/shallow')).namespace
26
+ end
27
+
28
+ should "know its nested files" do
29
+ assert_equal 6, subject.nested_files.size
30
+ assert_empty Assert::RakeTasks::Scope.new('does/not/exist').nested_files
31
+
32
+ h = Assert::RakeTasks::Scope.new("#{@scope_root}/test_root/shallow")
33
+ assert_equal 2, h.nested_files.size
34
+ end
35
+
36
+ should "know its path file" do
37
+ assert_empty subject.path_file_list
38
+
39
+ h = Assert::RakeTasks::Scope.new("#{@scope_root}/test_root/shallow")
40
+ assert_equal 1, h.path_file_list.size
41
+ end
42
+
43
+ should "convert to a test task" do
44
+ assert_not Assert::RakeTasks::Scope.new('does/not/exist').to_test_task
45
+
46
+ tt = subject.to_test_task
47
+ assert_kind_of TestTask, tt
48
+ assert_equal subject.nested_files.size+subject.path_file_list.size, tt.files.size
49
+ end
50
+
51
+ should "have a test task for each standalone test file" do
52
+ assert_equal 2, subject.test_tasks.size
53
+ assert_kind_of TestTask, subject.test_tasks.first
54
+ end
55
+
56
+ should "have a scope for each immediate test dir or test dir/file in the scope" do
57
+ assert_equal 2, subject.scopes.size
58
+ assert_kind_of Scope, subject.scopes.first
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,80 @@
1
+ require 'assert'
2
+
3
+ require 'assert/rake_tasks/test_task'
4
+
5
+ module Assert::RakeTasks
6
+
7
+ class TestTaskTests < Assert::Context
8
+ desc "the test task"
9
+ setup do
10
+ @task = Assert::RakeTasks::TestTask.new('thing')
11
+ @some_thing = Assert::RakeTasks::TestTask.new('test/some/thing')
12
+ end
13
+ subject { @task }
14
+
15
+ should have_accessors :path, :files
16
+ should have_instance_methods :relative_path, :scope_description, :description, :name
17
+ should have_instance_methods :file_list, :ruby_args, :show_loaded_files?
18
+
19
+ should "default with empty files collection" do
20
+ assert_equal [], subject.files
21
+ end
22
+
23
+ should "know its relative path" do
24
+ assert_equal "", subject.relative_path
25
+ assert_equal "some/thing", @some_thing.relative_path
26
+ end
27
+
28
+ should "know its scope description" do
29
+ assert_equal "", subject.scope_description
30
+ assert_equal " for some/thing", @some_thing.scope_description
31
+ end
32
+
33
+ should "know its task description" do
34
+ assert_equal "Run all tests", subject.description
35
+ assert_equal "Run all tests for some/thing", @some_thing.description
36
+ end
37
+
38
+ should "know its name" do
39
+ assert_equal :thing, @task.name
40
+ assert_equal :thing, @some_thing.name
41
+ end
42
+
43
+ should "build a file list string" do
44
+ subject.files = ["test_one_test.rb", "test_two_test.rb"]
45
+ assert_equal "\"test_one_test.rb\" \"test_two_test.rb\"", subject.file_list
46
+ end
47
+
48
+ should "know its ruby args" do
49
+ subject.files = ["test_one_test.rb", "test_two_test.rb"]
50
+ assert_equal "-rrubygems \"#{subject.send(:rake_loader)}\" #{subject.file_list}", subject.ruby_args
51
+ end
52
+
53
+ end
54
+
55
+ class VerboseTests < TestTaskTests
56
+ setup do
57
+ @orig_env_setting = ENV["show_loaded_files"]
58
+ ENV["show_loaded_files"] = 'false'
59
+ end
60
+ teardown do
61
+ ENV["show_loaded_files"] = @orig_env_setting
62
+ end
63
+
64
+ should "not show loaded files by default" do
65
+ assert_equal false, subject.show_loaded_files?
66
+ end
67
+ end
68
+
69
+ class EnvVerboseTests < VerboseTests
70
+ desc "if the show_loaded_files env setting is true"
71
+ setup do
72
+ ENV["show_loaded_files"] = 'true'
73
+ end
74
+
75
+ should "show loaded files" do
76
+ assert_equal true, subject.show_loaded_files?
77
+ end
78
+ end
79
+
80
+ end
@@ -37,13 +37,13 @@ class Assert::ResultSet
37
37
  @view_s = ""
38
38
  @view = @result_set.view = FakeView.new(nil, StringIO.new(@view_s, "w+"))
39
39
 
40
- @pass_result = Assert::Result::Pass.new("test", "pass", [])
40
+ @pass_result = Assert::Result::Pass.new(Factory.test("test"), "pass", [])
41
41
  @result_set << @pass_result
42
- @fail_result = Assert::Result::Fail.new("test", "fail", [])
42
+ @fail_result = Assert::Result::Fail.new(Factory.test("test"), "fail", [])
43
43
  @result_set << @fail_result
44
- @skip_result = Assert::Result::Skip.new("test", RuntimeError.new)
44
+ @skip_result = Assert::Result::Skip.new(Factory.test("test"), Assert::Result::TestSkipped.new)
45
45
  @result_set << @skip_result
46
- @error_result = Assert::Result::Error.new("test", RuntimeError.new)
46
+ @error_result = Assert::Result::Error.new(Factory.test("test"), RuntimeError.new)
47
47
  @result_set << @error_result
48
48
  end
49
49
  subject{ @view }
@@ -31,12 +31,13 @@ module Assert::Result
31
31
  class BaseTest < Assert::Context
32
32
  desc "a base result"
33
33
  setup do
34
- @result = Assert::Result::Base.new("a test name", "a message", ["line 1", "line2"])
34
+ @test = Factory.test("a test name")
35
+ @result = Assert::Result::Base.new(@test, "a message", ["line 1", "line2"])
35
36
  end
36
37
  subject{ @result }
37
38
 
38
- should have_readers :test_name, :message, :backtrace
39
- should have_instance_methods :to_sym, :to_s, :trace
39
+ should have_readers :test, :message, :backtrace
40
+ should have_instance_methods :test_name, :name, :to_sym, :to_s, :trace
40
41
 
41
42
  Assert::Result.types.keys.each do |type|
42
43
  should "respond to the instance method ##{type}?" do
@@ -48,8 +49,12 @@ module Assert::Result
48
49
  end
49
50
  end
50
51
 
52
+ should "know its test" do
53
+ assert_equal @test, subject.test
54
+ end
55
+
51
56
  should "nil out empty messages" do
52
- assert_equal nil, Assert::Result::Base.new("a test name", "").message
57
+ assert_equal nil, Assert::Result::Base.new(@test, "").message
53
58
  end
54
59
 
55
60
  should "show only its class and message when inspected" do
@@ -83,7 +88,8 @@ module Assert::Result
83
88
  class PassTest < Assert::Context
84
89
  desc "a pass result"
85
90
  setup do
86
- @result = Assert::Result::Pass.new("test", "passed", [])
91
+ @test = Factory.test("a test name")
92
+ @result = Assert::Result::Pass.new(@test, "passed", [])
87
93
  end
88
94
  subject { @result }
89
95
 
@@ -98,7 +104,11 @@ module Assert::Result
98
104
  end
99
105
 
100
106
  should "know its to_sym" do
101
- assert_equal :passed, subject.to_sym
107
+ assert_equal :pass, subject.to_sym
108
+ end
109
+
110
+ should "know its name" do
111
+ assert_equal "Pass", subject.name
102
112
  end
103
113
 
104
114
  should "include PASS in its to_s" do
@@ -106,73 +116,74 @@ module Assert::Result
106
116
  end
107
117
  end
108
118
 
109
- class FailTest < Assert::Context
110
- desc "a fail result"
119
+ class IgnoreTest < Assert::Context
120
+ desc "an ignore result"
111
121
  setup do
112
- @result = Assert::Result::Fail.new("test", "failed", [])
122
+ @test = Factory.test("a test name")
123
+ @result = Assert::Result::Ignore.new(@test, "ignored", [])
113
124
  end
114
125
  subject { @result }
115
126
 
116
- should "be fail?" do
117
- assert_equal true, subject.fail?
127
+ should "be ignore?" do
128
+ assert_equal true, subject.ignore?
118
129
  end
119
130
 
120
- Assert::Result.types.keys.reject{|k| k == :fail}.each do |type|
131
+ Assert::Result.types.keys.reject{|k| k == :ignore}.each do |type|
121
132
  should "not be #{type}?" do
122
133
  assert_equal false, subject.send("#{type}?")
123
134
  end
124
135
  end
125
136
 
126
137
  should "know its to_sym" do
127
- assert_equal :failed, subject.to_sym
138
+ assert_equal :ignore, subject.to_sym
128
139
  end
129
140
 
130
- should "include FAIL in its to_s" do
131
- assert subject.to_s.include?("FAIL")
141
+ should "know its name" do
142
+ assert_equal "Ignore", subject.name
143
+ end
144
+
145
+ should "include IGNORE in its to_s" do
146
+ assert subject.to_s.include?("IGNORE")
132
147
  end
133
148
  end
134
149
 
135
- class IgnoreTest < Assert::Context
136
- desc "an ignore result"
150
+ class FailureRuntimeErrorTest < Assert::Context
151
+
152
+ should "be a runtime error" do
153
+ assert_kind_of RuntimeError, Assert::Result::TestFailure.new
154
+ end
155
+
156
+ end
157
+
158
+ class FailTest < Assert::Context
159
+ desc "a fail result"
137
160
  setup do
138
- @result = Assert::Result::Ignore.new("test", "ignored", [])
161
+ @test = Factory.test("a test name")
162
+ @result = Assert::Result::Fail.new(@test, "failed", [])
139
163
  end
140
164
  subject { @result }
141
165
 
142
- should "be ignore?" do
143
- assert_equal true, subject.ignore?
166
+ should "be fail?" do
167
+ assert_equal true, subject.fail?
144
168
  end
145
169
 
146
- Assert::Result.types.keys.reject{|k| k == :ignore}.each do |type|
170
+ Assert::Result.types.keys.reject{|k| k == :fail}.each do |type|
147
171
  should "not be #{type}?" do
148
172
  assert_equal false, subject.send("#{type}?")
149
173
  end
150
174
  end
151
175
 
152
176
  should "know its to_sym" do
153
- assert_equal :ignored, subject.to_sym
154
- end
155
-
156
- should "include IGNORE in its to_s" do
157
- assert subject.to_s.include?("IGNORE")
177
+ assert_equal :fail, subject.to_sym
158
178
  end
159
- end
160
179
 
161
- class FromExceptionTest < Assert::Context
162
- before do
163
- begin
164
- raise Exception, "test error"
165
- rescue Exception => err
166
- @exception = err
167
- end
168
- @result = Assert::Result::FromException.new("test", @exception)
180
+ should "know its name" do
181
+ assert_equal "Fail", subject.name
169
182
  end
170
- subject{ @result }
171
183
 
172
- should "have the same backtrace as the original exception it was created from" do
173
- assert_equal @exception.backtrace, subject.backtrace
184
+ should "include FAIL in its to_s" do
185
+ assert subject.to_s.include?("FAIL")
174
186
  end
175
-
176
187
  end
177
188
 
178
189
  class SkippedRuntimeErrorTest < Assert::Context
@@ -183,10 +194,17 @@ module Assert::Result
183
194
 
184
195
  end
185
196
 
186
- class SkipTest < FromExceptionTest
197
+ class SkipTest < Assert::Context
187
198
  desc "a skip result"
188
199
  setup do
189
- @result = Assert::Result::Skip.new("test", @exception)
200
+ @test = Factory.test("a test name")
201
+ @exception = nil
202
+ begin
203
+ raise TestSkipped, "test ski["
204
+ rescue Exception => err
205
+ @exception = err
206
+ end
207
+ @result = Assert::Result::Skip.new(@test, @exception)
190
208
  end
191
209
  subject { @result }
192
210
 
@@ -201,7 +219,11 @@ module Assert::Result
201
219
  end
202
220
 
203
221
  should "know its to_sym" do
204
- assert_equal :skipped, subject.to_sym
222
+ assert_equal :skip, subject.to_sym
223
+ end
224
+
225
+ should "know its name" do
226
+ assert_equal "Skip", subject.name
205
227
  end
206
228
 
207
229
  should "include SKIP in its to_s" do
@@ -209,10 +231,17 @@ module Assert::Result
209
231
  end
210
232
  end
211
233
 
212
- class ErrorTest < FromExceptionTest
234
+ class ErrorTest < Assert::Context
213
235
  desc "an error result"
214
236
  setup do
215
- @result = Assert::Result::Error.new("test", @exception)
237
+ @test = Factory.test("a test name")
238
+ @exception = nil
239
+ begin
240
+ raise Exception, "test error"
241
+ rescue Exception => err
242
+ @exception = err
243
+ end
244
+ @result = Assert::Result::Error.new(@test, @exception)
216
245
  end
217
246
  subject { @result }
218
247
 
@@ -227,7 +256,11 @@ module Assert::Result
227
256
  end
228
257
 
229
258
  should "know its to_sym" do
230
- assert_equal :errored, subject.to_sym
259
+ assert_equal :error, subject.to_sym
260
+ end
261
+
262
+ should "know its name" do
263
+ assert_equal "Error", subject.name
231
264
  end
232
265
 
233
266
  should "include ERRORED in its to_s" do
@@ -0,0 +1,42 @@
1
+ require 'assert'
2
+
3
+ class Assert::Suite::ContextInfo
4
+
5
+ class BasicTests < Assert::Context
6
+ desc "a suite's context info"
7
+ setup do
8
+ @caller = caller
9
+ @klass = Assert::Context
10
+ @info = Assert::Suite::ContextInfo.new(@klass, @caller.first)
11
+ end
12
+ subject { @info }
13
+
14
+ should have_readers :klass, :called_from, :file
15
+
16
+ should "set its klass on init" do
17
+ assert_equal @klass, subject.klass
18
+ end
19
+
20
+ should "set its called_from to the first caller on init" do
21
+ assert_equal @caller.first, subject.called_from
22
+ end
23
+
24
+ should "set its file from caller info on init" do
25
+ assert_equal @caller.first.gsub(/\:[0-9]+.*$/, ''), subject.file
26
+ end
27
+
28
+ end
29
+
30
+ class KlassOnlyTests < BasicTests
31
+ desc "w/ only klass information"
32
+ setup do
33
+ @info = Assert::Suite::ContextInfo.new(@klass)
34
+ end
35
+
36
+ should "not have any file info" do
37
+ assert_nil subject.file
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -16,25 +16,14 @@ class Assert::Suite
16
16
  end
17
17
  subject { @suite }
18
18
 
19
- should have_instance_method :<<
20
- should have_instance_methods :contexts, :tests, :ordered_tests, :ordered_results
19
+ should have_instance_methods :ordered_tests, :results, :ordered_results
21
20
  should have_instance_methods :count, :test_count, :result_count
22
21
  should have_instance_methods :setup, :startup, :teardown, :shutdown
23
22
 
23
+ should have_accessors :tests, :test_methods
24
24
  should have_accessors :start_time, :end_time
25
25
  should have_instance_method :run_time, :runner_seed
26
26
 
27
- should "be a hash" do
28
- assert_kind_of ::Hash, subject
29
- end
30
-
31
- should "push contexts on itself" do
32
- context_class = Factory.context_class
33
- subject << context_class
34
- assert_equal true, subject.has_key?(context_class)
35
- assert_equal [], subject[context_class]
36
- end
37
-
38
27
  should "determine a klass' local public test methods" do
39
28
  assert_equal(
40
29
  ["test_subclass_stuff", "test_mixin_stuff", "test_repeated"].sort,
@@ -53,26 +42,26 @@ class Assert::Suite
53
42
  setup do
54
43
  @suite = Assert::Suite.new
55
44
  context_class = Factory.context_class
56
- @suite[context_class] = [
57
- Factory.test("should do nothing", context_class),
58
- Factory.test("should pass", context_class) do
45
+ @suite.tests = [
46
+ Factory.test("should do nothing", Factory.context_info(context_class)),
47
+ Factory.test("should pass", Factory.context_info(context_class)) do
59
48
  assert(1==1)
60
49
  refute(1==0)
61
50
  end,
62
- Factory.test("should fail", context_class) do
51
+ Factory.test("should fail", Factory.context_info(context_class)) do
63
52
  ignore
64
53
  assert(1==0)
65
54
  refute(1==1)
66
55
  end,
67
- Factory.test("should be ignored", context_class) do
56
+ Factory.test("should be ignored", Factory.context_info(context_class)) do
68
57
  ignore
69
58
  end,
70
- Factory.test("should skip", context_class) do
59
+ Factory.test("should skip", Factory.context_info(context_class)) do
71
60
  skip
72
61
  ignore
73
62
  assert(1==1)
74
63
  end,
75
- Factory.test("should error", context_class) do
64
+ Factory.test("should error", Factory.context_info(context_class)) do
76
65
  raise Exception
77
66
  ignore
78
67
  assert(1==1)
@@ -167,32 +156,6 @@ class Assert::Suite
167
156
  end
168
157
 
169
158
 
170
- class PrepTest < Assert::Context
171
- desc "a suite with a context with local public test meths"
172
- setup do
173
- @suite = Assert::Suite.new
174
- @suite << TwoTests
175
- end
176
- subject{ @suite }
177
-
178
- should "create tests from any local public test methods with a prep call" do
179
- subject.send(:prep)
180
- assert_equal 2, subject.test_count(TwoTests)
181
- end
182
-
183
- should "not double count local public test methods with multiple prep calls" do
184
- subject.send(:prep)
185
- subject.send(:prep)
186
- assert_equal 2, subject.test_count(TwoTests)
187
- end
188
-
189
- should "create tests from any local public test methods with a test_count call" do
190
- assert_equal 2, subject.test_count(TwoTests)
191
- end
192
-
193
- end
194
-
195
-
196
159
 
197
160
  class SetupTest < Assert::Context
198
161
  desc "a suite with a setup"