ZenTest 3.11.1 → 4.0.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.
@@ -1,134 +0,0 @@
1
- require 'test/unit/assertions'
2
-
3
- ##
4
- # Extra assertions for Test::Unit
5
-
6
- module Test::Unit::Assertions
7
- has_miniunit = defined? ::Mini
8
-
9
- if has_miniunit then
10
- alias :assert_include :assert_includes
11
- alias :deny :refute
12
- alias :deny_empty :refute_empty
13
- alias :deny_equal :refute_equal
14
- alias :deny_include :refute_includes
15
- alias :deny_includes :refute_includes
16
- alias :deny_nil :refute_nil
17
- alias :util_capture :capture_io
18
- else
19
-
20
- alias :refute_nil :assert_not_nil
21
-
22
- ##
23
- # Asserts that +obj+ responds to #empty? and #empty? returns true.
24
-
25
- def assert_empty(obj)
26
- assert_respond_to obj, :empty?
27
- assert_block "#{obj.inspect} expected to be empty." do obj.empty? end
28
- end
29
-
30
- ##
31
- # Like assert_in_delta but better dealing with errors proportional
32
- # to the sizes of +a+ and +b+.
33
-
34
- def assert_in_epsilon(a, b, epsilon, message = nil)
35
- return assert(true) if a == b # count assertion
36
-
37
- error = ((a - b).to_f / ((b.abs > a.abs) ? b : a)).abs
38
- message ||= "#{a} expected to be within #{epsilon * 100}% of #{b}, was #{error}"
39
-
40
- assert_block message do error <= epsilon end
41
- end
42
-
43
- ##
44
- # Asserts that +collection+ includes +obj+.
45
-
46
- def assert_include collection, obj, msg = nil
47
- assert_respond_to collection, :include?
48
-
49
- message ||= "#{collection.inspect}\ndoes not include\n#{obj.inspect}."
50
- assert_block message do collection.include?(obj) end
51
- end
52
-
53
- alias assert_includes assert_include
54
-
55
- ##
56
- # Asserts that +boolean+ is not false or nil.
57
-
58
- def deny(boolean, message = nil)
59
- _wrap_assertion do
60
- assert_block(build_message(message, "Failed refutation, no message given.")) { not boolean }
61
- end
62
- end
63
-
64
- ##
65
- # Asserts that +obj+ responds to #empty? and #empty? returns false.
66
-
67
- def deny_empty(obj)
68
- assert_respond_to obj, :empty?
69
- assert_block "#{obj.inspect} expected to have stuff." do !obj.empty? end
70
- end
71
-
72
- ##
73
- # Alias for assert_not_equal
74
-
75
- alias deny_equal assert_not_equal # rescue nil # rescue for miniunit
76
-
77
- ##
78
- # Asserts that +obj+ responds to #include? and that obj does not include
79
- # +item+.
80
-
81
- def deny_include(collection, obj, message = nil)
82
- assert_respond_to collection, :include?
83
- message ||= "#{collection.inspect} includes #{obj.inspect}."
84
- assert_block message do !collection.include? obj end
85
- end
86
-
87
- alias deny_includes deny_include
88
-
89
- ##
90
- # Asserts that +obj+ is not nil.
91
-
92
- alias deny_nil assert_not_nil
93
-
94
- ##
95
- # Captures $stdout and $stderr to StringIO objects and returns them.
96
- # Restores $stdout and $stderr when done.
97
- #
98
- # Usage:
99
- # def test_puts
100
- # out, err = capture do
101
- # puts 'hi'
102
- # STDERR.puts 'bye!'
103
- # end
104
- # assert_equal "hi\n", out.string
105
- # assert_equal "bye!\n", err.string
106
- # end
107
-
108
- def util_capture
109
- require 'stringio'
110
- orig_stdout = $stdout.dup
111
- orig_stderr = $stderr.dup
112
- captured_stdout = StringIO.new
113
- captured_stderr = StringIO.new
114
- $stdout = captured_stdout
115
- $stderr = captured_stderr
116
- yield
117
- captured_stdout.rewind
118
- captured_stderr.rewind
119
- return captured_stdout.string, captured_stderr.string
120
- ensure
121
- $stdout = orig_stdout
122
- $stderr = orig_stderr
123
- end
124
- end
125
- end
126
-
127
- class Object # :nodoc:
128
- unless respond_to? :path2class then
129
- def path2class(path) # :nodoc:
130
- path.split('::').inject(Object) { |k,n| k.const_get n }
131
- end
132
- end
133
- end
134
-
data/test/test_help.rb DELETED
@@ -1,36 +0,0 @@
1
- # ActionPack
2
- module ActionController; end
3
- module ActionController::Flash; end
4
- class ActionController::Flash::FlashHash < Hash; end
5
- class ActionController::TestSession < Hash; end
6
-
7
- class ActionController::TestRequest
8
- attr_accessor :session
9
- end
10
- class ActionController::TestResponse; end
11
-
12
- class ApplicationController; end
13
-
14
- module ActionView; end
15
- module ActionView::Helpers; end
16
- module ActionView::Helpers::ActiveRecordHelper; end
17
- module ActionView::Helpers::TagHelper; end
18
- module ActionView::Helpers::TextHelper; end
19
- module ActionView::Helpers::FormTagHelper; end
20
- module ActionView::Helpers::FormOptionsHelper; end
21
- module ActionView::Helpers::FormHelper; end
22
- module ActionView::Helpers::UrlHelper; end
23
- module ActionView::Helpers::AssetTagHelper; end
24
-
25
- class << Test::Unit::TestCase
26
- attr_accessor :use_transactional_fixtures
27
- attr_accessor :use_instantiated_fixtures
28
- end
29
-
30
- # ActionMailer
31
- module ActionMailer; end
32
- class ActionMailer::Base
33
- def self.deliveries=(arg); end unless defined? @@defined
34
- @@defined = true
35
- end
36
-
@@ -1,229 +0,0 @@
1
- require 'test/unit' if $0 == __FILE__
2
- require 'test/test_autotest'
3
- require 'autotest/rails'
4
-
5
- class TestRailsAutotest < TestAutotest
6
-
7
- def setup
8
- super
9
-
10
- @test_class = 'RouteTest'
11
- @test = 'test/unit/route_test.rb'
12
- @other_test = 'test/other_blah_test.rb'
13
- @impl = 'app/models/route.rb'
14
- @inner_test = 'test/outer/inner_test.rb'
15
- @outer_test = 'test/outer_test.rb'
16
- @inner_test_class = "OuterTest::InnerTest"
17
-
18
- @rails_unit_tests = [@test]
19
-
20
- @rails_controller_tests = %w(test/controllers/admin/themes_controller_test.rb
21
- test/controllers/articles_controller_test.rb
22
- test/controllers/dummy_controller_test.rb
23
- test/controllers/route_controller_test.rb)
24
-
25
- @rails_view_tests = %w(test/views/admin/themes_view_test.rb
26
- test/views/articles_view_test.rb
27
- test/views/layouts_view_test.rb
28
- test/views/route_view_test.rb)
29
-
30
- @rails_functional_tests = %w(test/functional/admin/themes_controller_test.rb
31
- test/functional/articles_controller_test.rb
32
- test/functional/dummy_controller_test.rb
33
- test/functional/route_controller_test.rb)
34
-
35
- # These files aren't put in @file_map, so add them to it
36
- @extra_files = %w(test/controllers/admin/themes_controller_test.rb
37
- test/controllers/articles_controller_test.rb
38
- test/controllers/dummy_controller_test.rb
39
- test/functional/articles_controller_test.rb
40
- test/functional/dummy_controller_test.rb
41
- test/views/admin/themes_view_test.rb
42
- test/views/articles_view_test.rb
43
- test/views/layouts_view_test.rb)
44
-
45
- @files.clear
46
-
47
- (@rails_unit_tests +
48
- @rails_controller_tests +
49
- @rails_view_tests +
50
- @rails_functional_tests +
51
- @extra_files +
52
- [@impl]).flatten.each_with_index do |path, t|
53
- @files[path] = Time.at(t+1)
54
- end
55
-
56
- @a.find_order = @files.keys
57
- @a.last_mtime = @files.values.sort.last
58
- end
59
-
60
- # Overridden from superclass... the scenario just doesn't happen the same way.
61
- def test_consolidate_failures_multiple_matches
62
- @test2 = 'test/unit/route_again_test.rb'
63
- @files[@test2] = Time.at(42)
64
- @files['app/views/routes/edit.rhtml'] = Time.at(42)
65
- @files['app/views/routes/list.rhtml'] = Time.at(42)
66
-
67
- @a.find_order = @files.keys
68
-
69
- result = @a.consolidate_failures([['test_unmatched', @test_class]])
70
- expected = {"test/unit/route_test.rb"=>["test_unmatched"]}
71
- assert_equal expected, result
72
- assert_equal '', @a.output.string
73
- end
74
-
75
- def test_reorder_random
76
- @a.order = :random
77
-
78
- srand 42
79
- expected, size = @files.dup, @files.size
80
- expected = expected.sort_by { rand(size) }
81
-
82
- srand 42
83
- result = @a.reorder(@files.dup)
84
-
85
- assert_equal expected, result
86
- end
87
-
88
- def test_test_files_for
89
- empty = []
90
- assert_equal empty, @a.test_files_for('blah.rb')
91
- assert_equal empty, @a.test_files_for('test_blah.rb')
92
-
93
- # controllers
94
- util_test_files_for('app/controllers/admin/themes_controller.rb',
95
- 'test/controllers/admin/themes_controller_test.rb',
96
- 'test/functional/admin/themes_controller_test.rb')
97
-
98
- util_test_files_for('app/controllers/application.rb',
99
- @rails_controller_tests,
100
- @rails_view_tests,
101
- @rails_functional_tests)
102
-
103
- util_test_files_for('app/controllers/route_controller.rb',
104
- 'test/controllers/route_controller_test.rb',
105
- 'test/functional/route_controller_test.rb')
106
-
107
- util_test_files_for('app/controllers/notest_controller.rb')
108
-
109
- # helpers
110
- util_test_files_for('app/helpers/application_helper.rb',
111
- @rails_view_tests,
112
- @rails_functional_tests)
113
-
114
- util_test_files_for('app/helpers/route_helper.rb',
115
- 'test/views/route_view_test.rb',
116
- 'test/functional/route_controller_test.rb')
117
-
118
- # model
119
- util_test_files_for('app/models/route.rb',
120
- @test)
121
-
122
- util_test_files_for('app/models/notest.rb')
123
-
124
- # views
125
- util_test_files_for('app/views/layouts/default.rhtml',
126
- 'test/views/layouts_view_test.rb')
127
-
128
- util_test_files_for('app/views/route/index.rhtml',
129
- 'test/views/route_view_test.rb',
130
- 'test/functional/route_controller_test.rb')
131
-
132
- util_test_files_for('app/views/route/xml.rxml',
133
- 'test/views/route_view_test.rb',
134
- 'test/functional/route_controller_test.rb')
135
-
136
- util_test_files_for('app/views/shared/notest.rhtml')
137
-
138
- util_test_files_for('app/views/articles/flag.rhtml',
139
- 'test/views/articles_view_test.rb',
140
- 'test/functional/articles_controller_test.rb')
141
-
142
- # tests
143
- util_test_files_for('test/fixtures/routes.yml',
144
- @test,
145
- 'test/controllers/route_controller_test.rb',
146
- 'test/views/route_view_test.rb',
147
- 'test/functional/route_controller_test.rb')
148
-
149
- util_test_files_for('test/test_helper.rb',
150
- @rails_unit_tests, @rails_controller_tests,
151
- @rails_view_tests, @rails_functional_tests)
152
-
153
- util_test_files_for(@test, @test)
154
-
155
- util_test_files_for('test/controllers/route_controller_test.rb',
156
- 'test/controllers/route_controller_test.rb')
157
-
158
- util_test_files_for('test/views/route_view_test.rb',
159
- 'test/views/route_view_test.rb')
160
-
161
- util_test_files_for('test/functional/route_controller_test.rb',
162
- 'test/functional/route_controller_test.rb')
163
-
164
- util_test_files_for('test/functional/admin/themes_controller_test.rb',
165
- 'test/functional/admin/themes_controller_test.rb')
166
-
167
- # global conf thingies
168
- util_test_files_for('config/boot.rb',
169
- @rails_unit_tests, @rails_controller_tests,
170
- @rails_view_tests, @rails_functional_tests)
171
-
172
- util_test_files_for('config/database.yml',
173
- @rails_unit_tests, @rails_controller_tests,
174
- @rails_view_tests, @rails_functional_tests)
175
-
176
- util_test_files_for('config/environment.rb',
177
- @rails_unit_tests, @rails_controller_tests,
178
- @rails_view_tests, @rails_functional_tests)
179
-
180
- util_test_files_for('config/environments/test.rb',
181
- @rails_unit_tests, @rails_controller_tests,
182
- @rails_view_tests, @rails_functional_tests)
183
-
184
- util_test_files_for('config/routes.rb',
185
- @rails_controller_tests,
186
- @rails_view_tests, @rails_functional_tests)
187
-
188
- # ignored crap
189
- util_test_files_for('vendor/plugins/cartographer/lib/keys.rb')
190
-
191
- util_test_files_for('Rakefile')
192
- end
193
-
194
- def test_consolidate_failures_multiple_matches_before
195
- @test_class = 'BlahTest'
196
- @files.clear
197
- @files['app/model/blah.rb'] = Time.at(42)
198
- @files['app/model/different_blah.rb'] = Time.at(42)
199
- @files['test/unit/blah_test.rb'] = Time.at(42)
200
- @files['test/unit/different_blah_test.rb'] = Time.at(42)
201
-
202
- @a.find_order = @files.keys
203
-
204
- result = @a.consolidate_failures([['test_matched', @test_class]])
205
- expected = { 'test/unit/blah_test.rb' => [ 'test_matched' ] }
206
- assert_equal expected, result
207
- assert_equal "", @a.output.string
208
- end
209
-
210
- def util_test_files_for(file, *expected)
211
- assert_equal(expected.flatten.sort.uniq,
212
- @a.test_files_for(file).sort.uniq, "tests for #{file}")
213
- end
214
-
215
- def test_path_to_classname
216
- # rails
217
- util_path_to_classname 'BlahTest', 'test/blah_test.rb'
218
- util_path_to_classname 'BlahTest', 'test/unit/blah_test.rb'
219
- util_path_to_classname 'BlahTest', 'test/functional/blah_test.rb'
220
- util_path_to_classname 'BlahTest', 'test/integration/blah_test.rb'
221
- util_path_to_classname 'BlahTest', 'test/views/blah_test.rb'
222
- util_path_to_classname 'BlahTest', 'test/controllers/blah_test.rb'
223
- util_path_to_classname 'BlahTest', 'test/helpers/blah_test.rb'
224
-
225
- util_path_to_classname('OuterTest::InnerTest',
226
- 'test/controllers/outer/inner_test.rb')
227
- end
228
- end
229
-
@@ -1,58 +0,0 @@
1
- require 'test/unit'
2
- require 'test/zentest_assertions'
3
-
4
- unless defined? $TESTING_RTC then
5
- $TESTING_RTC = true
6
-
7
- begin
8
- require 'test/rails'
9
- rescue LoadError, NameError
10
- $TESTING_RTC = false
11
- end
12
- end
13
-
14
- class TRController < ApplicationController
15
- end if $TESTING_RTC
16
-
17
- class TestRailsControllerTestCase < Test::Rails::ControllerTestCase
18
-
19
- def setup
20
- @controller_class_name = 'TRController'
21
- super
22
- end
23
-
24
- def assigns
25
- { 'ivar' => 'value' }
26
- end
27
-
28
- def test_assert_assigned
29
- assert_assigned :ivar
30
- assert_assigned :ivar, 'value'
31
-
32
- assert_raise Test::Unit::AssertionFailedError do
33
- assert_assigned :no_ivar
34
- end
35
-
36
- e = assert_raise Test::Unit::AssertionFailedError do
37
- assert_assigned :ivar, 'bad_value'
38
- end
39
-
40
- expected = <<-EOF.strip
41
- assert_assigned :ivar.
42
- <\"bad_value\"> expected but was
43
- <\"value\">.
44
- EOF
45
-
46
- assert_equal expected, e.message
47
- end
48
-
49
- def test_deny_assigned
50
- deny_assigned :no_ivar
51
-
52
- assert_raise Test::Unit::AssertionFailedError do
53
- deny_assigned :ivar
54
- end
55
- end
56
-
57
- end if $TESTING_RTC
58
-