test-unit 3.1.5 → 3.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86673156c68b86e03890136de7cac26b04ebf6ba
4
- data.tar.gz: e2e15e416b83d09eee253273f981ef4a9c2566f5
3
+ metadata.gz: 04f5af0a0a28c5c1507effb079f6d5e2553e28fa
4
+ data.tar.gz: 87bf6b44575b3c787a4c1ebcc270c0519c4f07be
5
5
  SHA512:
6
- metadata.gz: e6d3ea4e758eb002dad57e91d1db3a7f71ff12e1a6428c115db9c619cbd9b054606f74a8b9aeed216c6ab9d9a37d257d6f4521d9dcfbfa60966073c41b0b67fc
7
- data.tar.gz: 09d14bdfc97c567d50c1b2feaac261cad406256c86bbe9be809c48f012dd845a76be20bd94e29190ce77580bfee96ddbc94f0f309b990eb97521cd22d72b9b59
6
+ metadata.gz: 4e77c28e8a7f9782348fa037220713bfb678bcf287c88957198fce089aa2950fd00762cf643efd45965888ba64e9c5f78af5cff383b95545cb9f7905f4c01a4c
7
+ data.tar.gz: 6855489fa3bc8bb219311e7104d1c34e0fb90d6f75f46315971ad10ac1d5073903445ac473e59f3bececae9b25f8e80d0c78c851a4a3a415f6b3f18cb9142199
@@ -1,5 +1,54 @@
1
1
  # News
2
2
 
3
+ ## 3.1.6 - 2016-01-17 {#version-3-1-6}
4
+
5
+ It's a Ruby on Rails integration improvement release.
6
+
7
+ ### Improvements
8
+
9
+ * Filtered backtrace of power\_assert.
10
+ [GitHub#114]
11
+ * Improved performance to retrieve test defined location.
12
+ * Improved performance to run fixtures in a test.
13
+ * Supported running a test by `yield` in `setup`:
14
+
15
+ Before:
16
+
17
+ def setup
18
+ @file = File.open("x")
19
+ end
20
+
21
+ def teardown
22
+ @file.close
23
+ end
24
+
25
+ After:
26
+
27
+ def setup
28
+ File.open("x") do |file|
29
+ @file = file
30
+ yield
31
+ end
32
+ end
33
+
34
+ * Added `--default-test-path` option that specifies the default path
35
+ that has tests.
36
+ * Made auto runner registration more lazily. Auto runner isn't
37
+ registered automatically until user defines a test. In the
38
+ previous releases, auto runner is registered automatically when
39
+ user defines a test case.
40
+ * Supported specifying a test by location in command line. For
41
+ example, the following command line runs a test that is defined in
42
+ /tmp/test_a.rb at line 10:
43
+
44
+ % ruby -r test-unit -e run_test /tmp/test_a.rb:10
45
+
46
+ ### Fixes
47
+
48
+ * Fixed a bug that test isn't ran. The test has the same name as
49
+ data driven test that is defined in parent test case.
50
+ [GitHub#115]
51
+
3
52
  ## 3.1.5 - 2015-10-09 {#version-3-1-5}
4
53
 
5
54
  It's a Rack integration improvement release.
@@ -7,8 +56,8 @@ It's a Rack integration improvement release.
7
56
  ### Improvements
8
57
 
9
58
  * Renamed experimental top-level `run` method to `run_test` method
10
- because `run` is conflicted with Rack.
11
- [GitHub#32][GitHub:basecamp/pow#303] [Reported by Yevhen Viktorov]
59
+ because `run` is conflicted with Rack.
60
+ [GitHub#32][GitHub:basecamp/pow#303] [Reported by Yevhen Viktorov]
12
61
 
13
62
  ### Thanks
14
63
 
@@ -111,7 +111,10 @@ module Test
111
111
  attributes || StringifyKeyHash.new
112
112
  end
113
113
 
114
- def find_attribute(method_name, name)
114
+ def find_attribute(method_name, name, options={})
115
+ recursive_p = options[:recursive]
116
+ recursive_p = true if recursive_p.nil?
117
+
115
118
  @attributes_table ||= StringifyKeyHash.new
116
119
  if @attributes_table.key?(method_name)
117
120
  attributes = @attributes_table[method_name]
@@ -120,6 +123,7 @@ module Test
120
123
  end
121
124
  end
122
125
 
126
+ return nil unless recursive_p
123
127
  return nil if self == TestCase
124
128
 
125
129
  @cached_parent_test_case ||= ancestors.find do |ancestor|
@@ -128,7 +132,7 @@ module Test
128
132
  ancestor < Test::Unit::Attribute
129
133
  end
130
134
 
131
- @cached_parent_test_case.find_attribute(method_name, name)
135
+ @cached_parent_test_case.find_attribute(method_name, name, options)
132
136
  end
133
137
 
134
138
  @@attribute_observers = StringifyKeyHash.new
@@ -0,0 +1,17 @@
1
+ require "test/unit/test-suite-creator"
2
+
3
+ module Test
4
+ module Unit
5
+ module AutoRunnerLoader
6
+ @loaded = false
7
+ class << self
8
+ def check(test_case, method_name)
9
+ return if @loaded
10
+ return unless TestSuiteCreator.test_method?(test_case, method_name)
11
+ require "test/unit"
12
+ @loaded = true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ require "English"
2
+
1
3
  require 'test/unit/color-scheme'
2
4
  require 'test/unit/priority'
3
5
  require 'test/unit/attribute-matcher'
@@ -94,6 +96,7 @@ module Test
94
96
  collector.excludes.replace(auto_runner.exclude)
95
97
  end
96
98
  collector.base = auto_runner.base
99
+ collector.default_test_paths = auto_runner.default_test_paths
97
100
  collector.filter = auto_runner.filters
98
101
  collector.collect(*auto_runner.to_run)
99
102
  end
@@ -131,7 +134,9 @@ module Test
131
134
  end
132
135
 
133
136
  attr_reader :suite, :runner_options
134
- attr_accessor :filters, :to_run, :pattern, :exclude, :base, :workdir
137
+ attr_accessor :filters, :to_run
138
+ attr_accessor :default_test_paths
139
+ attr_accessor :pattern, :exclude, :base, :workdir
135
140
  attr_accessor :color_scheme, :listeners
136
141
  attr_writer :runner, :collector
137
142
 
@@ -141,6 +146,7 @@ module Test
141
146
  @collector = default_collector
142
147
  @filters = []
143
148
  @to_run = []
149
+ @default_test_paths = []
144
150
  @color_scheme = ColorScheme.default
145
151
  @runner_options = {}
146
152
  @default_arguments = []
@@ -164,7 +170,7 @@ module Test
164
170
  def process_args(args=ARGV)
165
171
  begin
166
172
  args.unshift(*@default_arguments)
167
- options.order!(args) {|arg| @to_run << arg}
173
+ options.order!(args) {|arg| add_test_path(arg)}
168
174
  rescue OptionParser::ParseError => e
169
175
  puts e
170
176
  puts options
@@ -199,10 +205,19 @@ module Test
199
205
  @workdir = w
200
206
  end
201
207
 
208
+ o.on('--default-test-path=PATH',
209
+ "Add PATH to the default test paths.",
210
+ "The PATH is used when user doesn't specify any test path.",
211
+ "You can specify this option multiple times.") do |path|
212
+ @default_test_paths << path
213
+ end
214
+
202
215
  o.on('-a', '--add=TORUN', Array,
203
216
  "Add TORUN to the list of things to run;",
204
- "can be a file or a directory.") do |a|
205
- @to_run.concat(a)
217
+ "can be a file or a directory.") do |paths|
218
+ paths.each do |path|
219
+ add_test_path(path)
220
+ end
206
221
  end
207
222
 
208
223
  @pattern = []
@@ -272,11 +287,7 @@ module Test
272
287
  path, line, = location.split(/:(\d+)/, 2)
273
288
  line = line.to_i unless line.nil?
274
289
  end
275
- @filters << lambda do |test|
276
- test.class.test_defined?(:path => path,
277
- :line => line,
278
- :method_name => test.method_name)
279
- end
290
+ add_location_filter(path, line)
280
291
  end
281
292
 
282
293
  o.on('--attribute=EXPRESSION', String,
@@ -475,6 +486,23 @@ module Test
475
486
  end
476
487
  false
477
488
  end
489
+
490
+ def add_test_path(path)
491
+ if /:(\d+)\z/ =~ path
492
+ line = $1.to_i
493
+ path = $PREMATCH
494
+ add_location_filter(path, line)
495
+ end
496
+ @to_run << path
497
+ end
498
+
499
+ def add_location_filter(path, line)
500
+ @filters << lambda do |test|
501
+ test.class.test_defined?(:path => path,
502
+ :line => line,
503
+ :method_name => test.method_name)
504
+ end
505
+ end
478
506
  end
479
507
  end
480
508
  end
@@ -10,6 +10,7 @@ module Test
10
10
  include Collector
11
11
 
12
12
  attr_reader :patterns, :excludes, :base
13
+ attr_reader :default_test_paths
13
14
 
14
15
  def initialize
15
16
  super
@@ -18,6 +19,7 @@ module Test
18
19
  @patterns = [/\Atest[_\-].+\.rb\z/m, /[_\-]test\.rb\z/]
19
20
  @excludes = []
20
21
  @base = nil
22
+ @default_test_paths = []
21
23
  @require_failed_infos = []
22
24
  end
23
25
 
@@ -26,8 +28,15 @@ module Test
26
28
  @base = base
27
29
  end
28
30
 
31
+ def default_test_paths=(paths)
32
+ @default_test_paths = paths.collect do |path|
33
+ Pathname(path)
34
+ end
35
+ end
36
+
29
37
  def collect(*froms)
30
38
  add_load_path(@base) do
39
+ froms = @default_test_paths if froms.empty?
31
40
  froms = ["."] if froms.empty?
32
41
  test_suites = []
33
42
  already_gathered = find_test_cases
@@ -24,9 +24,11 @@ module Test
24
24
  attr_reader :teardown
25
25
  def initialize(test_case)
26
26
  @test_case = test_case
27
- @setup = HookPoint.new(:after => :append)
28
- @cleanup = HookPoint.new(:before => :prepend)
29
- @teardown = HookPoint.new(:before => :prepend)
27
+ @setup = HookPoint.new(@test_case, :setup, :after => :append)
28
+ @cleanup = HookPoint.new(@test_case, :cleanup, :before => :prepend)
29
+ @teardown = HookPoint.new(@test_case, :teardown, :before => :prepend)
30
+ @cached_before_callbacks = {}
31
+ @cached_after_callbacks = {}
30
32
  end
31
33
 
32
34
  def [](type)
@@ -41,6 +43,19 @@ module Test
41
43
  end
42
44
 
43
45
  def before_callbacks(type)
46
+ @cached_before_callbacks[type] ||= collect_before_callbacks(type)
47
+ end
48
+
49
+ def after_callbacks(type)
50
+ @cached_after_callbacks[type] ||= collect_after_callbacks(type)
51
+ end
52
+
53
+ private
54
+ def target_test_cases
55
+ @cached_target_test_cases ||= collect_target_test_cases
56
+ end
57
+
58
+ def collect_before_callbacks(type)
44
59
  prepend_callbacks = []
45
60
  append_callbacks = []
46
61
  target_test_cases.each do |ancestor|
@@ -51,7 +66,7 @@ module Test
51
66
  merge_callbacks(prepend_callbacks, append_callbacks)
52
67
  end
53
68
 
54
- def after_callbacks(type)
69
+ def collect_after_callbacks(type)
55
70
  prepend_callbacks = []
56
71
  append_callbacks = []
57
72
  target_test_cases.each do |ancestor|
@@ -62,11 +77,6 @@ module Test
62
77
  merge_callbacks(prepend_callbacks, append_callbacks)
63
78
  end
64
79
 
65
- private
66
- def target_test_cases
67
- @cached_target_test_cases ||= collect_target_test_cases
68
- end
69
-
70
80
  def collect_target_test_cases
71
81
  ancestors = @test_case.ancestors
72
82
  base_index = ancestors.index(::Test::Unit::Fixture)
@@ -89,7 +99,9 @@ module Test
89
99
  end
90
100
 
91
101
  class HookPoint
92
- def initialize(default_options)
102
+ def initialize(test_case, type, default_options)
103
+ @test_case = test_case
104
+ @type = type
93
105
  @default_options = default_options
94
106
  @before_prepend_callbacks = []
95
107
  @before_append_callbacks = []
@@ -112,11 +124,24 @@ module Test
112
124
  end
113
125
  before_how = options[:before]
114
126
  after_how = options[:after]
115
- add_callback(method_name_or_callback, before_how, after_how)
127
+ if method_name_or_callback.respond_to?(:call)
128
+ callback = method_name_or_callback
129
+ method_name = callback_method_name(callback)
130
+ @test_case.__send__(:define_method, method_name, &callback)
131
+ else
132
+ method_name = method_name_or_callback
133
+ end
134
+ add_callback(method_name, before_how, after_how)
116
135
  end
117
136
 
118
137
  def unregister(method_name_or_callback)
119
- @unregistered_callbacks << method_name_or_callback
138
+ if method_name_or_callback.respond_to?(:call)
139
+ callback = method_name_or_callback
140
+ method_name = callback_method_name(callback)
141
+ else
142
+ method_name = method_name_or_callback
143
+ end
144
+ @unregistered_callbacks << method_name
120
145
  end
121
146
 
122
147
  def before_prepend_callbacks
@@ -145,6 +170,10 @@ module Test
145
170
  [:prepend, :append].include?(options[key])
146
171
  end
147
172
 
173
+ def callback_method_name(callback)
174
+ "#{@type}_#{callback.object_id}"
175
+ end
176
+
148
177
  def add_callback(method_name_or_callback, before_how, after_how)
149
178
  case before_how
150
179
  when :prepend
@@ -208,38 +237,50 @@ module Test
208
237
  end
209
238
 
210
239
  private
211
- def run_fixture(type, options={})
212
- [
240
+ def run_fixture(type, options={}, &block)
241
+ fixtures = [
213
242
  self.class.fixture.before_callbacks(type),
214
243
  type,
215
244
  self.class.fixture.after_callbacks(type),
216
- ].flatten.each do |method_name_or_callback|
217
- run_fixture_callback(method_name_or_callback, options)
245
+ ].flatten
246
+ if block
247
+ runner = create_fixtures_runner(fixtures, options, &block)
248
+ runner.call
249
+ else
250
+ fixtures.each do |method_name|
251
+ run_fixture_callback(method_name, options)
252
+ end
218
253
  end
219
254
  end
220
255
 
221
- def run_fixture_callback(method_name_or_callback, options)
222
- if method_name_or_callback.respond_to?(:call)
223
- callback = lambda do
224
- instance_eval(&method_name_or_callback)
225
- end
256
+ def create_fixtures_runner(fixtures, options, &block)
257
+ if fixtures.empty?
258
+ block
226
259
  else
227
- return unless respond_to?(method_name_or_callback, true)
228
- callback = lambda do
229
- __send__(method_name_or_callback)
260
+ last_fixture = fixtures.pop
261
+ create_fixtures_runner(fixtures, options) do
262
+ block_is_called = false
263
+ run_fixture_callback(last_fixture, options) do
264
+ block_is_called = true
265
+ block.call
266
+ end
267
+ block.call unless block_is_called
230
268
  end
231
269
  end
270
+ end
232
271
 
272
+ def run_fixture_callback(method_name, options, &block)
273
+ return unless respond_to?(method_name, true)
233
274
  begin
234
- callback.call
275
+ __send__(method_name, &block)
235
276
  rescue Exception
236
277
  raise unless options[:handle_exception]
237
278
  raise unless handle_exception($!)
238
279
  end
239
280
  end
240
281
 
241
- def run_setup
242
- run_fixture(:setup)
282
+ def run_setup(&block)
283
+ run_fixture(:setup, &block)
243
284
  end
244
285
 
245
286
  def run_cleanup
@@ -8,6 +8,13 @@
8
8
  module Test
9
9
  module Unit
10
10
  class TestSuiteCreator # :nodoc:
11
+ class << self
12
+ def test_method?(test_case, method_name)
13
+ /\Atest./ =~ method_name.to_s or
14
+ test_case.find_attribute(method_name, :test)
15
+ end
16
+ end
17
+
11
18
  def initialize(test_case)
12
19
  @test_case = test_case
13
20
  end
@@ -15,7 +22,8 @@ module Test
15
22
  def create
16
23
  suite = TestSuite.new(@test_case.name, @test_case)
17
24
  collect_test_names.each do |test_name|
18
- data_sets = @test_case.find_attribute(test_name, :data)
25
+ data_sets = @test_case.find_attribute(test_name, :data,
26
+ :recursive => false)
19
27
  if data_sets
20
28
  data_sets.each do |data_set|
21
29
  data_set = data_set.call if data_set.respond_to?(:call)
@@ -47,8 +55,7 @@ module Test
47
55
  methods |= @test_case.public_instance_methods(false)
48
56
  method_names = methods.collect(&:to_s)
49
57
  test_names = method_names.find_all do |method_name|
50
- /\Atest./ =~ method_name or
51
- @test_case.find_attribute(method_name, :test)
58
+ self.class.test_method?(@test_case, method_name)
52
59
  end
53
60
  __send__("sort_test_names_in_#{@test_case.test_order}_order", test_names)
54
61
  end
@@ -20,6 +20,7 @@ require 'test/unit/data'
20
20
  require 'test/unit/testsuite'
21
21
  require 'test/unit/test-suite-creator'
22
22
  require 'test/unit/assertion-failed-error'
23
+ require 'test/unit/auto-runner-loader'
23
24
  require 'test/unit/util/backtracefilter'
24
25
  require 'test/unit/util/output'
25
26
  require 'test/unit/util/method-owner-finder'
@@ -104,7 +105,6 @@ module Test
104
105
 
105
106
  class << self
106
107
  def inherited(sub_class) # :nodoc:
107
- require "test/unit"
108
108
  DESCENDANTS << sub_class
109
109
  super
110
110
  end
@@ -120,7 +120,12 @@ module Test
120
120
  source_location = find_attribute(stringified_name, :source_location)
121
121
  if source_location
122
122
  path, line = source_location
123
+ elsif respond_to?(:caller_locations, true)
124
+ location = caller_locations(1, 1)[0]
125
+ path = location.absolute_path || location.path
126
+ line = location.lineno
123
127
  else
128
+ # TODO: Remove me when Ruby 1.9 support is dropped
124
129
  path, line, = caller[0].split(/:(\d+)/, 2)
125
130
  line = line.to_i if line
126
131
  end
@@ -130,6 +135,7 @@ module Test
130
135
  :line => line,
131
136
  }
132
137
  added_method_names[stringified_name] = true
138
+ AutoRunnerLoader.check(self, stringified_name)
133
139
  end
134
140
 
135
141
  def added_method_names # :nodoc:
@@ -281,6 +287,9 @@ module Test
281
287
  else
282
288
  targets = test_description_or_targets
283
289
  attribute(:test, true, {}, *targets)
290
+ targets.each do |target|
291
+ AutoRunnerLoader.check(self, target)
292
+ end
284
293
  end
285
294
  end
286
295
 
@@ -453,14 +462,31 @@ module Test
453
462
  @internal_data.test_started
454
463
  yield(STARTED, name)
455
464
  yield(STARTED_OBJECT, self)
465
+ processed_exception_in_setup = false
456
466
  begin
457
- run_setup
458
- run_test
459
- run_cleanup
460
- add_pass
467
+ catch do |tag|
468
+ run_setup do
469
+ begin
470
+ run_test
471
+ run_cleanup
472
+ add_pass
473
+ rescue Exception
474
+ @internal_data.interrupted
475
+ unless handle_exception($!)
476
+ processed_exception_in_setup = true
477
+ raise
478
+ end
479
+ throw(tag)
480
+ end
481
+ end
482
+ end
461
483
  rescue Exception
462
- @internal_data.interrupted
463
- raise unless handle_exception($!)
484
+ if processed_exception_in_setup
485
+ raise
486
+ else
487
+ @internal_data.interrupted
488
+ raise unless handle_exception($!)
489
+ end
464
490
  ensure
465
491
  begin
466
492
  run_teardown
@@ -1,3 +1,8 @@
1
+ begin
2
+ require 'power_assert'
3
+ rescue LoadError, SyntaxError
4
+ end
5
+
1
6
  module Test
2
7
  module Unit
3
8
  module Util
@@ -6,21 +11,28 @@ module Test
6
11
  TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3]
7
12
  TESTUNIT_RB_FILE = /\.rb\Z/
8
13
 
14
+ POWERASSERT_PREFIX =
15
+ defined?(PowerAssert) ?
16
+ PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] :
17
+ nil
18
+
9
19
  module_function
10
20
  def filter_backtrace(backtrace, prefix=nil)
11
21
  return ["No backtrace"] unless backtrace
12
22
  return backtrace if ENV["TEST_UNIT_ALL_BACKTRACE"]
13
23
 
14
24
  if prefix
15
- split_prefix = prefix.split(TESTUNIT_FILE_SEPARATORS)
25
+ split_prefixes = [prefix.split(TESTUNIT_FILE_SEPARATORS)]
16
26
  else
17
- split_prefix = TESTUNIT_PREFIX
27
+ split_prefixes = [TESTUNIT_PREFIX, POWERASSERT_PREFIX].compact
18
28
  end
19
29
  test_unit_internal_p = lambda do |entry|
20
30
  components = entry.split(TESTUNIT_FILE_SEPARATORS)
21
- split_entry = components[0, split_prefix.size]
22
- next false unless split_entry[0..-2] == split_prefix[0..-2]
23
- split_entry[-1].sub(TESTUNIT_RB_FILE, '') == split_prefix[-1]
31
+ split_prefixes.any? do |split_prefix|
32
+ split_entry = components[0, split_prefix.size]
33
+ next false unless split_entry[0..-2] == split_prefix[0..-2]
34
+ split_entry[-1].sub(TESTUNIT_RB_FILE, '') == split_prefix[-1]
35
+ end
24
36
  end
25
37
 
26
38
  in_user_code = false
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = '3.1.5'
3
+ VERSION = '3.1.6'
4
4
  end
5
5
  end
@@ -75,6 +75,21 @@ class TestData < Test::Unit::TestCase
75
75
  @calc.plus(data["augend"], data["addend"]))
76
76
  end
77
77
  end
78
+
79
+ class TestSuperclass < TestCalc
80
+ data("positive positive" => {:expected => 4, :augend => 3, :addend => 1},
81
+ "positive negative" => {:expected => -1, :augend => 1, :addend => -2})
82
+ def test_plus(data)
83
+ assert_equal(data[:expected],
84
+ @calc.plus(data[:augend], data[:addend]))
85
+ end
86
+
87
+ class TestNormalTestInSubclass < self
88
+ def test_plus
89
+ assert_equal(2, @calc.plus(1, 1))
90
+ end
91
+ end
92
+ end
78
93
  end
79
94
 
80
95
  def setup
@@ -168,13 +183,20 @@ class TestData < Test::Unit::TestCase
168
183
  data("data set" => TestCalc::TestDataSet,
169
184
  "n-data" => TestCalc::TestNData,
170
185
  "dynamic-data-set" => TestCalc::TestDynamicDataSet,
171
- "load-data-set" => TestCalc::TestLoadDataSet)
186
+ "load-data-set" => TestCalc::TestLoadDataSet,
187
+ "superclass" => TestCalc::TestSuperclass)
172
188
  def test_run(test_case)
173
189
  result = _run_test(test_case)
174
190
  assert_equal("2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
175
191
  "0 omissions, 0 notifications", result.to_s)
176
192
  end
177
193
 
194
+ def test_run_normal_test_in_subclass
195
+ result = _run_test(TestCalc::TestSuperclass::TestNormalTestInSubclass)
196
+ assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
197
+ "0 omissions, 0 notifications", result.to_s)
198
+ end
199
+
178
200
  data("data set" => TestCalc::TestDataSet,
179
201
  "n-data" => TestCalc::TestNData,
180
202
  "dynamic-data-set" => TestCalc::TestDynamicDataSet,
@@ -535,6 +535,60 @@ class TestUnitFixture < Test::Unit::TestCase
535
535
  called)
536
536
  end
537
537
 
538
+ def test_setup_with_block
539
+ test_case = Class.new(Test::Unit::TestCase) do
540
+ def called_ids
541
+ @called_ids ||= []
542
+ end
543
+
544
+ def called(id)
545
+ called_ids << id
546
+ end
547
+
548
+ setup
549
+ def setup1
550
+ called(:setup1)
551
+ begin
552
+ yield
553
+ called(:setup1_after_yield)
554
+ ensure
555
+ called(:setup1_teardown)
556
+ end
557
+ end
558
+
559
+ setup
560
+ def setup2
561
+ called(:setup2)
562
+ begin
563
+ yield
564
+ called(:setup2_after_yield)
565
+ ensure
566
+ called(:setup2_teardown)
567
+ end
568
+ end
569
+
570
+ def teardown
571
+ called(:teardown)
572
+ end
573
+
574
+ def test_nothing
575
+ called(:test)
576
+ flunk
577
+ called(:test_after_failure)
578
+ end
579
+ end
580
+
581
+ assert_called_fixtures([
582
+ :setup1,
583
+ :setup2,
584
+ :test,
585
+ :setup2_teardown,
586
+ :setup1_teardown,
587
+ :teardown,
588
+ ],
589
+ test_case)
590
+ end
591
+
538
592
  private
539
593
  def assert_teardown_customizable(expected, parent, options)
540
594
  test_case = Class.new(parent || Test::Unit::TestCase) do
@@ -16,7 +16,7 @@ module Test::Unit::Util
16
16
  %q{tc_thing.rb:3}]
17
17
  assert_equal(backtrace[1..2], filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Should filter out all TestUnit-specific lines")
18
18
 
19
- backtrace = [%q{tc_thing.rb:4:in 'a'},
19
+ backtrace = [%q{tc_thing.rb:4:in 'a'},
20
20
  %q{tc_thing.rb:4:in 'test_stuff'},
21
21
  %q{tc_thing.rb:3}]
22
22
  assert_equal(backtrace, filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Shouldn't filter too much")
@@ -37,5 +37,16 @@ backtrace = [%q{tc_thing.rb:4:in 'a'},
37
37
  def test_nil_backtrace
38
38
  assert_equal(["No backtrace"], filter_backtrace(nil))
39
39
  end
40
+
41
+ def test_power_assert_backtrace
42
+ omit('test for power_assert') unless defined?(PowerAssert)
43
+ blk = Proc.new {caller.find {|i| /power_assert.*in \`start\'/ =~ i}}
44
+ PowerAssert.start(blk) do |pa|
45
+ backtrace = [pa.yield,
46
+ %q{tc_thing.rb:4:in 'a'},
47
+ %q{tc_thing.rb:4:in 'test_stuff'}]
48
+ assert_equal(backtrace[1..2], filter_backtrace(backtrace))
49
+ end
50
+ end
40
51
  end
41
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-09 00:00:00.000000000 Z
12
+ date: 2016-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert
@@ -121,6 +121,7 @@ files:
121
121
  - lib/test/unit/assertions.rb
122
122
  - lib/test/unit/attribute-matcher.rb
123
123
  - lib/test/unit/attribute.rb
124
+ - lib/test/unit/auto-runner-loader.rb
124
125
  - lib/test/unit/autorunner.rb
125
126
  - lib/test/unit/code-snippet-fetcher.rb
126
127
  - lib/test/unit/collector.rb
@@ -228,49 +229,49 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  version: '0'
229
230
  requirements: []
230
231
  rubyforge_project:
231
- rubygems_version: 2.2.2
232
+ rubygems_version: 2.4.5.1
232
233
  signing_key:
233
234
  specification_version: 4
234
235
  summary: An xUnit family unit testing framework for Ruby.
235
236
  test_files:
236
- - test/test-assertions.rb
237
- - test/test-color.rb
238
237
  - test/test-code-snippet.rb
238
+ - test/test-fault-location-detector.rb
239
+ - test/test-attribute.rb
240
+ - test/test-priority.rb
241
+ - test/test-color-scheme.rb
242
+ - test/test-failure.rb
243
+ - test/test-color.rb
244
+ - test/ui/test_testrunmediator.rb
245
+ - test/test-attribute-matcher.rb
246
+ - test/test-test-suite.rb
239
247
  - test/test-test-suite-creator.rb
248
+ - test/test-diff.rb
249
+ - test/test-emacs-runner.rb
250
+ - test/test-data.rb
251
+ - test/fixtures/header.csv
252
+ - test/fixtures/header.tsv
253
+ - test/fixtures/no-header.tsv
254
+ - test/fixtures/plus.csv
255
+ - test/fixtures/no-header.csv
256
+ - test/fixtures/header-label.tsv
257
+ - test/fixtures/header-label.csv
258
+ - test/test-assertions.rb
240
259
  - test/test-test-result.rb
260
+ - test/testunit-test-util.rb
261
+ - test/collector/test-load.rb
262
+ - test/collector/test_dir.rb
263
+ - test/collector/test_objectspace.rb
264
+ - test/collector/test-descendant.rb
241
265
  - test/test-error.rb
242
- - test/test-failure.rb
243
266
  - test/run-test.rb
244
267
  - test/test-pending.rb
245
- - test/test-color-scheme.rb
246
- - test/test-attribute-matcher.rb
247
- - test/testunit-test-util.rb
248
- - test/test-data.rb
249
- - test/ui/test_testrunmediator.rb
250
- - test/util/test-method-owner-finder.rb
268
+ - test/test-fixture.rb
251
269
  - test/util/test-output.rb
270
+ - test/util/test-method-owner-finder.rb
252
271
  - test/util/test_observable.rb
253
- - test/util/test_backtracefilter.rb
254
272
  - test/util/test_procwrapper.rb
273
+ - test/util/test_backtracefilter.rb
274
+ - test/test-notification.rb
255
275
  - test/test-omission.rb
256
276
  - test/test-test-case.rb
257
- - test/test-fixture.rb
258
- - test/fixtures/no-header.csv
259
- - test/fixtures/header-label.tsv
260
- - test/fixtures/plus.csv
261
- - test/fixtures/no-header.tsv
262
- - test/fixtures/header-label.csv
263
- - test/fixtures/header.csv
264
- - test/fixtures/header.tsv
265
- - test/collector/test-descendant.rb
266
- - test/collector/test_objectspace.rb
267
- - test/collector/test-load.rb
268
- - test/collector/test_dir.rb
269
- - test/test-priority.rb
270
- - test/test-test-suite.rb
271
- - test/test-diff.rb
272
- - test/test-emacs-runner.rb
273
- - test/test-attribute.rb
274
- - test/test-fault-location-detector.rb
275
- - test/test-notification.rb
276
277
  has_rdoc: