mega-sharp-tool 0.0.1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/mega-sharp-tool.gemspec +12 -0
  3. data/minitest-6.0.6/History.rdoc +1860 -0
  4. data/minitest-6.0.6/Manifest.txt +41 -0
  5. data/minitest-6.0.6/README.rdoc +763 -0
  6. data/minitest-6.0.6/Rakefile +89 -0
  7. data/minitest-6.0.6/bin/minitest +5 -0
  8. data/minitest-6.0.6/design_rationale.rb +54 -0
  9. data/minitest-6.0.6/lib/hoe/minitest.rb +30 -0
  10. data/minitest-6.0.6/lib/minitest/assertions.rb +821 -0
  11. data/minitest-6.0.6/lib/minitest/autorun.rb +5 -0
  12. data/minitest-6.0.6/lib/minitest/benchmark.rb +452 -0
  13. data/minitest-6.0.6/lib/minitest/bisect.rb +304 -0
  14. data/minitest-6.0.6/lib/minitest/complete.rb +56 -0
  15. data/minitest-6.0.6/lib/minitest/compress.rb +94 -0
  16. data/minitest-6.0.6/lib/minitest/error_on_warning.rb +11 -0
  17. data/minitest-6.0.6/lib/minitest/expectations.rb +321 -0
  18. data/minitest-6.0.6/lib/minitest/find_minimal_combination.rb +127 -0
  19. data/minitest-6.0.6/lib/minitest/hell.rb +11 -0
  20. data/minitest-6.0.6/lib/minitest/manual_plugins.rb +4 -0
  21. data/minitest-6.0.6/lib/minitest/parallel.rb +72 -0
  22. data/minitest-6.0.6/lib/minitest/path_expander.rb +432 -0
  23. data/minitest-6.0.6/lib/minitest/pride.rb +4 -0
  24. data/minitest-6.0.6/lib/minitest/pride_plugin.rb +135 -0
  25. data/minitest-6.0.6/lib/minitest/server.rb +49 -0
  26. data/minitest-6.0.6/lib/minitest/server_plugin.rb +88 -0
  27. data/minitest-6.0.6/lib/minitest/spec.rb +324 -0
  28. data/minitest-6.0.6/lib/minitest/sprint.rb +105 -0
  29. data/minitest-6.0.6/lib/minitest/sprint_plugin.rb +39 -0
  30. data/minitest-6.0.6/lib/minitest/test.rb +232 -0
  31. data/minitest-6.0.6/lib/minitest/test_task.rb +331 -0
  32. data/minitest-6.0.6/lib/minitest.rb +1232 -0
  33. data/minitest-6.0.6/test/minitest/metametameta.rb +150 -0
  34. data/minitest-6.0.6/test/minitest/test_bisect.rb +249 -0
  35. data/minitest-6.0.6/test/minitest/test_find_minimal_combination.rb +138 -0
  36. data/minitest-6.0.6/test/minitest/test_minitest_assertions.rb +1729 -0
  37. data/minitest-6.0.6/test/minitest/test_minitest_benchmark.rb +151 -0
  38. data/minitest-6.0.6/test/minitest/test_minitest_reporter.rb +437 -0
  39. data/minitest-6.0.6/test/minitest/test_minitest_spec.rb +1095 -0
  40. data/minitest-6.0.6/test/minitest/test_minitest_test.rb +1295 -0
  41. data/minitest-6.0.6/test/minitest/test_minitest_test_task.rb +57 -0
  42. data/minitest-6.0.6/test/minitest/test_path_expander.rb +229 -0
  43. data/minitest-6.0.6/test/minitest/test_server.rb +146 -0
  44. metadata +83 -0
@@ -0,0 +1,324 @@
1
+ require_relative "test"
2
+
3
+ class Module # :nodoc:
4
+ def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
5
+ block = dont_flip == :block
6
+ dont_flip = false if block
7
+
8
+ # https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
9
+ # Drop this when we can drop ruby 2.6 (aka after rails 6.1 EOL, ~2024-06)
10
+ kw_extra = "ruby2_keywords %p" % [new_name] if respond_to? :ruby2_keywords, true
11
+
12
+ self.class_eval <<-EOM, __FILE__, __LINE__ + 1
13
+ def #{new_name} *args
14
+ raise "Calling ##{new_name} outside of test." unless ctx
15
+ case
16
+ when #{!!dont_flip} then
17
+ ctx.#{meth}(target, *args)
18
+ when #{block} && Proc === target then
19
+ ctx.#{meth}(*args, &target)
20
+ else
21
+ ctx.#{meth}(args.first, target, *args[1..-1])
22
+ end
23
+ end
24
+ #{kw_extra}
25
+ EOM
26
+ end
27
+ end
28
+
29
+ # :stopdoc:
30
+ module Minitest # fucking hell rdoc...
31
+ Expectation = Struct.new :target, :ctx
32
+ end
33
+ # :startdoc:
34
+
35
+ ##
36
+ # Kernel extensions for minitest
37
+
38
+ module Kernel
39
+ ##
40
+ # Describe a series of expectations for a given target +desc+.
41
+ #
42
+ # Defines a test class subclassing from either Minitest::Spec or
43
+ # from the surrounding describe's class. The surrounding class may
44
+ # subclass Minitest::Spec manually in order to easily share code:
45
+ #
46
+ # class MySpec < Minitest::Spec
47
+ # # ... shared code ...
48
+ # end
49
+ #
50
+ # class TestStuff < MySpec
51
+ # it "does stuff" do
52
+ # # shared code available here
53
+ # end
54
+ # describe "inner stuff" do
55
+ # it "still does stuff" do
56
+ # # ...and here
57
+ # end
58
+ # end
59
+ # end
60
+ #
61
+ # For more information on getting started with writing specs, see:
62
+ #
63
+ # http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html
64
+ #
65
+ # For some suggestions on how to improve your specs, try:
66
+ #
67
+ # https://betterspecs.org
68
+ #
69
+ # but do note that several items there are debatable or specific to
70
+ # rspec.
71
+ #
72
+ # For more information about expectations, see Minitest::Expectations.
73
+
74
+ def describe desc, *additional_desc, &block # :doc:
75
+ stack = Minitest::Spec.describe_stack
76
+ is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL)
77
+ name = [stack.last, desc, *additional_desc]
78
+ name.prepend self if stack.empty? && is_spec_class
79
+ sclas =
80
+ stack.last \
81
+ || (is_spec_class && self) \
82
+ || Minitest::Spec.spec_type(desc, *additional_desc)
83
+
84
+ cls = sclas.create name.compact.join("::"), desc
85
+
86
+ stack.push cls
87
+ cls.class_eval(&block)
88
+ stack.pop
89
+ cls
90
+ end
91
+ private :describe
92
+ end
93
+
94
+ ##
95
+ # Minitest::Spec -- The faster, better, less-magical spec framework!
96
+ #
97
+ # For a list of expectations, see Minitest::Expectations.
98
+
99
+ class Minitest::Spec < Minitest::Test
100
+
101
+ ##
102
+ # Oh look! A Minitest::Spec::DSL module! Eat your heart out DHH.
103
+
104
+ module DSL
105
+ ##
106
+ # Contains pairs of matchers and Spec classes to be used to
107
+ # calculate the superclass of a top-level describe. This allows for
108
+ # automatically customizable spec types.
109
+ #
110
+ # See: register_spec_type and spec_type
111
+
112
+ TYPES = [[//, Minitest::Spec]]
113
+
114
+ ##
115
+ # Register a new type of spec that matches the spec's description.
116
+ # This method can take either a Regexp and a spec class or a spec
117
+ # class and a block that takes the description and returns true if
118
+ # it matches.
119
+ #
120
+ # Eg:
121
+ #
122
+ # register_spec_type(/Controller$/, Minitest::Spec::Rails)
123
+ #
124
+ # or:
125
+ #
126
+ # register_spec_type(Minitest::Spec::RailsModel) do |desc|
127
+ # desc.superclass == ActiveRecord::Base
128
+ # end
129
+
130
+ def register_spec_type *args, &block
131
+ if block then
132
+ matcher, klass = block, args.first
133
+ else
134
+ matcher, klass = *args
135
+ end
136
+ TYPES.unshift [matcher, klass]
137
+ end
138
+
139
+ ##
140
+ # Figure out the spec class to use based on a spec's description. Eg:
141
+ #
142
+ # spec_type("BlahController") # => Minitest::Spec::Rails
143
+
144
+ def spec_type desc, *additional
145
+ TYPES.find { |matcher, _klass|
146
+ if matcher.respond_to? :call then
147
+ matcher.call desc, *additional
148
+ else
149
+ matcher === desc.to_s
150
+ end
151
+ }.last
152
+ end
153
+
154
+ def describe_stack # :nodoc:
155
+ Thread.current[:describe_stack] ||= []
156
+ end
157
+
158
+ def children # :nodoc:
159
+ @children ||= []
160
+ end
161
+
162
+ def nuke_test_methods! # :nodoc:
163
+ self.public_instance_methods.grep(/^test_/).each do |name|
164
+ self.send :undef_method, name
165
+ end
166
+ end
167
+
168
+ ##
169
+ # Define a 'before' action. Inherits the way normal methods should.
170
+ #
171
+ # NOTE: +type+ is ignored and is only there to make porting easier.
172
+ #
173
+ # Equivalent to Minitest::Test#setup.
174
+
175
+ def before _type = nil, &block
176
+ define_method :setup do
177
+ super()
178
+ self.instance_eval(&block)
179
+ end
180
+ end
181
+
182
+ ##
183
+ # Define an 'after' action. Inherits the way normal methods should.
184
+ #
185
+ # NOTE: +type+ is ignored and is only there to make porting easier.
186
+ #
187
+ # Equivalent to Minitest::Test#teardown.
188
+
189
+ def after _type = nil, &block
190
+ define_method :teardown do
191
+ self.instance_eval(&block)
192
+ super()
193
+ end
194
+ end
195
+
196
+ ##
197
+ # Define an expectation with name +desc+. Name gets morphed to a
198
+ # proper test method name. For some freakish reason, people who
199
+ # write specs don't like class inheritance, so this goes way out of
200
+ # its way to make sure that expectations aren't inherited.
201
+ #
202
+ # This is also aliased to #specify and doesn't require a +desc+ arg.
203
+ #
204
+ # Hint: If you _do_ want inheritance, use minitest/test. You can mix
205
+ # and match between assertions and expectations as much as you want.
206
+
207
+ def it desc = "anonymous", &block
208
+ block ||= proc { skip "(no tests defined)" }
209
+
210
+ @specs ||= 0
211
+ @specs += 1
212
+
213
+ name = "test_%04d_%s" % [ @specs, desc ]
214
+
215
+ undef_klasses = self.children.reject { |c| c.public_method_defined? name }
216
+
217
+ define_method name, &block
218
+
219
+ undef_klasses.each do |undef_klass|
220
+ undef_klass.send :undef_method, name
221
+ end
222
+
223
+ name
224
+ end
225
+
226
+ ##
227
+ # Essentially, define an accessor for +name+ with +block+.
228
+ #
229
+ # Why use let instead of def? I honestly don't know.
230
+
231
+ def let name, &block
232
+ name = name.to_s
233
+ pre, post = "let '#{name}' cannot ", ". Please use another name."
234
+ methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]
235
+ raise ArgumentError, "#{pre}begin with 'test'#{post}" if
236
+ name.start_with? "test"
237
+ raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if
238
+ methods.include? name
239
+
240
+ define_method name do
241
+ @_memoized ||= {}
242
+ @_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
243
+ end
244
+ end
245
+
246
+ ##
247
+ # Another lazy man's accessor generator. Made even more lazy by
248
+ # setting the name for you to +subject+.
249
+
250
+ def subject &block
251
+ let :subject, &block
252
+ end
253
+
254
+ def create name, desc # :nodoc:
255
+ cls = Class.new self do
256
+ @name = name
257
+ @desc = desc
258
+
259
+ nuke_test_methods!
260
+ end
261
+
262
+ children << cls
263
+
264
+ cls
265
+ end
266
+
267
+ def name # :nodoc:
268
+ defined?(@name) ? @name : super
269
+ end
270
+
271
+ alias to_s name
272
+ alias inspect name
273
+
274
+ attr_reader :desc # :nodoc:
275
+ alias specify it
276
+
277
+ ##
278
+ # Rdoc... why are you so dumb?
279
+
280
+ module InstanceMethods
281
+ ##
282
+ # Takes a value or a block and returns a value monad that has
283
+ # all of Expectations methods available to it.
284
+ #
285
+ # _(1 + 1).must_equal 2
286
+ #
287
+ # And for blocks:
288
+ #
289
+ # _ { 1 + "1" }.must_raise TypeError
290
+ #
291
+ # This method of expectation-based testing is preferable to
292
+ # straight-expectation methods (on Object) because it stores its
293
+ # test context, bypassing our hacky use of thread-local variables.
294
+ #
295
+ # It is also aliased to #value and #expect for your aesthetic
296
+ # pleasure:
297
+ #
298
+ # _(1 + 1).must_equal 2
299
+ # value(1 + 1).must_equal 2
300
+ # expect(1 + 1).must_equal 2
301
+
302
+ def _ value = nil, &block
303
+ Minitest::Expectation.new block || value, self
304
+ end
305
+
306
+ alias value _
307
+ alias expect _
308
+ end
309
+
310
+ def self.extended obj # :nodoc:
311
+ obj.send :include, InstanceMethods
312
+ end
313
+ end
314
+
315
+ extend DSL
316
+
317
+ TYPES = DSL::TYPES # :nodoc:
318
+ end
319
+
320
+ require_relative "expectations"
321
+
322
+ class Minitest::Expectation
323
+ include Minitest::Expectations
324
+ end
@@ -0,0 +1,105 @@
1
+ $LOAD_PATH.unshift "test", "lib"
2
+
3
+ require "simplecov" if ENV["MT_COV"] || ARGV.delete("--simplecov")
4
+ require_relative "autorun"
5
+ require_relative "path_expander"
6
+
7
+ module Minitest
8
+
9
+ ##
10
+ # Runs (Get it? It's fast!) your tests and makes it easier to rerun
11
+ # individual failures.
12
+
13
+ class Sprint
14
+ # extracted version = "1.5.0"
15
+
16
+ ##
17
+ # Process and run minitest cmdline.
18
+
19
+ def self.run args = ARGV
20
+ if args.delete("--bisect") or args.delete("-b") then
21
+ require_relative "bisect"
22
+
23
+ return Minitest::Bisect.run ARGV
24
+ end
25
+
26
+ Minitest::PathExpander.new(args).process { |f|
27
+ require "./#{f}" if File.file? f
28
+ }
29
+ end
30
+
31
+ ##
32
+ # An extra minitest reporter to output how to rerun failures in
33
+ # various styles.
34
+
35
+ class SprintReporter < AbstractReporter
36
+ ##
37
+ # The style to report, either lines or regexp. Defaults to lines.
38
+ attr_accessor :style
39
+ attr_accessor :results # :nodoc:
40
+
41
+ def initialize style = :regexp # :nodoc:
42
+ self.results = []
43
+ self.style = style
44
+ end
45
+
46
+ def record result # :nodoc:
47
+ results << result unless result.passed? or result.skipped?
48
+ end
49
+
50
+ def report # :nodoc:
51
+ return if results.empty?
52
+
53
+ puts
54
+ puts "Happy Happy Sprint List:"
55
+ puts
56
+ print_list
57
+ puts
58
+ end
59
+
60
+ def print_list # :nodoc:
61
+ case style
62
+ when :regexp
63
+ results.each do |result|
64
+ puts " minitest -n #{result.class_name}##{result.name}"
65
+ end
66
+ when :lines
67
+ files = Hash.new { |h,k| h[k] = [] }
68
+ results.each do |result|
69
+ path, line = result.source_location
70
+ path = path.delete_prefix "#{Dir.pwd}/"
71
+ files[path] << line
72
+ end
73
+
74
+ files.sort.each do |path, lines|
75
+ puts " minitest %s:%s" % [path, lines.sort.join(",")]
76
+ end
77
+ else
78
+ raise "unsupported style: %p" % [style]
79
+ end
80
+ end
81
+ end
82
+
83
+ ##
84
+ # An extra minitest reporter to output how to rerun failures using
85
+ # rake.
86
+
87
+ class RakeReporter < SprintReporter
88
+ ##
89
+ # The name of the rake task to rerun. Defaults to nil.
90
+
91
+ attr_accessor :name
92
+
93
+ def initialize name = nil # :nodoc:
94
+ super()
95
+ self.name = name
96
+ end
97
+
98
+ def print_list # :nodoc:
99
+ results.each do |result|
100
+ puts [" rake", name, "N=#{result.class_name}##{result.name}"].compact.join(" ")
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "../minitest"
2
+
3
+ # :stopdoc:
4
+ class OptionParser # unofficial embedded gem "makeoptparseworkwell"
5
+ def hidden(...) = define(...).tap { |sw| def sw.summarize(*) = nil }
6
+ def deprecate(from, to) = hidden(from) { abort "#{from} is deprecated. Use #{to}." }
7
+ def topdict(name) = name.length > 1 ? top.long : top.short
8
+ def alias(from, to) = (dict = topdict(from) and dict[to] = dict[from])
9
+ end unless OptionParser.method_defined? :hidden
10
+ # :startdoc:
11
+
12
+ module Minitest # :nodoc:
13
+ def self.plugin_sprint_options opts, options # :nodoc:
14
+ opts.on "--rake [TASK]", "Report how to re-run failures with rake." do |task|
15
+ options[:sprint] = :rake
16
+ options[:rake_task] = task
17
+ end
18
+
19
+ opts.deprecate "--binstub", "--rerun"
20
+
21
+ sprint_styles = %w[rake lines names binstub]
22
+
23
+ opts.on "-r", "--rerun [STYLE]", sprint_styles, "Report how to re-run failures using STYLE (names, lines)." do |style|
24
+ options[:sprint] = (style || :lines).to_sym
25
+ end
26
+ end
27
+
28
+ def self.plugin_sprint_init options
29
+ require_relative "sprint"
30
+ case options[:sprint]
31
+ when :rake then
32
+ self.reporter << Minitest::Sprint::RakeReporter.new(options[:rake_task])
33
+ when :binstub, :names then
34
+ self.reporter << Minitest::Sprint::SprintReporter.new
35
+ when :lines then
36
+ self.reporter << Minitest::Sprint::SprintReporter.new(:lines)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,232 @@
1
+ require_relative "../minitest" unless defined? Minitest::Runnable
2
+
3
+ module Minitest
4
+ ##
5
+ # Subclass Test to create your own tests. Typically you'll want a
6
+ # Test subclass per implementation class.
7
+ #
8
+ # See Minitest::Assertions
9
+
10
+ class Test < Runnable
11
+ require_relative "assertions"
12
+ include Minitest::Reportable
13
+ include Minitest::Assertions
14
+
15
+ PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, SystemExit] # :nodoc:
16
+
17
+ SETUP_METHODS = %w[ before_setup setup after_setup ] # :nodoc:
18
+
19
+ TEARDOWN_METHODS = %w[ before_teardown teardown after_teardown ] # :nodoc:
20
+
21
+ # :stopdoc:
22
+ class << self; attr_accessor :io_lock; end
23
+ self.io_lock = Mutex.new
24
+ # :startdoc:
25
+
26
+ ##
27
+ # Call this at the top of your tests when you absolutely
28
+ # positively need to have ordered tests. In doing so, you're
29
+ # admitting that you suck and your tests are weak.
30
+
31
+ def self.i_suck_and_my_tests_are_order_dependent!
32
+ class << self
33
+ undef_method :run_order if method_defined? :run_order
34
+ define_method :run_order do :alpha end
35
+ end
36
+ end
37
+
38
+ ##
39
+ # Make diffs for this Test use #pretty_inspect so that diff
40
+ # in assert_equal can have more details. NOTE: this is much slower
41
+ # than the regular inspect but much more usable for complex
42
+ # objects.
43
+
44
+ def self.make_my_diffs_pretty!
45
+ require "pp"
46
+
47
+ define_method :mu_pp, &:pretty_inspect
48
+ end
49
+
50
+ ##
51
+ # Call this at the top of your tests (inside the +Minitest::Test+
52
+ # subclass or +describe+ block) when you want to run your tests in
53
+ # parallel. In doing so, you're admitting that you rule and your
54
+ # tests are awesome.
55
+
56
+ def self.parallelize_me!
57
+ return unless Minitest.parallel_executor
58
+ include Minitest::Parallel::Test
59
+ extend Minitest::Parallel::Test::ClassMethods
60
+ end
61
+
62
+ ##
63
+ # Returns all instance methods starting with "test_". Based on
64
+ # #run_order, the methods are either sorted, randomized
65
+ # (default), or run in parallel.
66
+
67
+ def self.runnable_methods
68
+ methods = methods_matching(/^test_/)
69
+
70
+ case self.run_order
71
+ when :random, :parallel then
72
+ srand Minitest.seed
73
+ methods.sort.shuffle
74
+ when :alpha, :sorted then
75
+ methods.sort
76
+ else
77
+ raise "Unknown_order: %p" % [self.run_order]
78
+ end
79
+ end
80
+
81
+ ##
82
+ # Runs a single test with setup/teardown hooks.
83
+
84
+ def run
85
+ time_it do
86
+ capture_exceptions do
87
+ SETUP_METHODS.each do |hook|
88
+ self.send hook
89
+ end
90
+
91
+ self.send self.name
92
+ end
93
+
94
+ TEARDOWN_METHODS.each do |hook|
95
+ capture_exceptions do
96
+ self.send hook
97
+ end
98
+ end
99
+ end
100
+
101
+ Result.from self # per contract
102
+ end
103
+
104
+ ##
105
+ # Provides before/after hooks for setup and teardown. These are
106
+ # meant for library writers, NOT for regular test authors. See
107
+ # #before_setup for an example.
108
+
109
+ module LifecycleHooks
110
+
111
+ ##
112
+ # Runs before every test, before setup. This hook is meant for
113
+ # libraries to extend minitest. It is not meant to be used by
114
+ # test developers.
115
+ #
116
+ # As a simplistic example:
117
+ #
118
+ # module MyMinitestPlugin
119
+ # def before_setup
120
+ # super
121
+ # # ... stuff to do before setup is run
122
+ # end
123
+ #
124
+ # def after_setup
125
+ # # ... stuff to do after setup is run
126
+ # super
127
+ # end
128
+ #
129
+ # def before_teardown
130
+ # super
131
+ # # ... stuff to do before teardown is run
132
+ # end
133
+ #
134
+ # def after_teardown
135
+ # # ... stuff to do after teardown is run
136
+ # super
137
+ # end
138
+ # end
139
+ #
140
+ # class Minitest::Test
141
+ # include MyMinitestPlugin
142
+ # end
143
+
144
+ def before_setup; end
145
+
146
+ ##
147
+ # Runs before every test. Use this to set up before each test
148
+ # run.
149
+
150
+ def setup; end
151
+
152
+ ##
153
+ # Runs before every test, after setup. This hook is meant for
154
+ # libraries to extend minitest. It is not meant to be used by
155
+ # test developers.
156
+ #
157
+ # See #before_setup for an example.
158
+
159
+ def after_setup; end
160
+
161
+ ##
162
+ # Runs after every test, before teardown. This hook is meant for
163
+ # libraries to extend minitest. It is not meant to be used by
164
+ # test developers.
165
+ #
166
+ # See #before_setup for an example.
167
+
168
+ def before_teardown; end
169
+
170
+ ##
171
+ # Runs after every test. Use this to clean up after each test
172
+ # run.
173
+
174
+ def teardown; end
175
+
176
+ ##
177
+ # Runs after every test, after teardown. This hook is meant for
178
+ # libraries to extend minitest. It is not meant to be used by
179
+ # test developers.
180
+ #
181
+ # See #before_setup for an example.
182
+
183
+ def after_teardown; end
184
+ end # LifecycleHooks
185
+
186
+ def capture_exceptions # :nodoc:
187
+ yield
188
+ rescue *PASSTHROUGH_EXCEPTIONS
189
+ raise
190
+ rescue Assertion => e
191
+ self.failures << e
192
+ rescue Exception => e
193
+ self.failures << UnexpectedError.new(sanitize_exception e)
194
+ end
195
+
196
+ def sanitize_exception e # :nodoc:
197
+ Marshal.dump e
198
+ e # good: use as-is
199
+ rescue
200
+ neuter_exception e
201
+ end
202
+
203
+ def neuter_exception e # :nodoc:
204
+ bt = e.backtrace
205
+ msg = e.message.dup
206
+
207
+ new_exception e.class, msg, bt # e.class can be a problem...
208
+ rescue
209
+ msg.prepend "Neutered Exception #{e.class}: "
210
+
211
+ new_exception RuntimeError, msg, bt, true # but if this raises, we die
212
+ end
213
+
214
+ def new_exception klass, msg, bt, kill = false # :nodoc:
215
+ ne = klass.new msg
216
+ ne.set_backtrace bt
217
+
218
+ if kill then
219
+ ne.instance_variables.each do |v|
220
+ ne.remove_instance_variable v
221
+ end
222
+ end
223
+
224
+ Marshal.dump ne # can raise TypeError
225
+ ne
226
+ end
227
+
228
+ include LifecycleHooks
229
+ include Guard
230
+ extend Guard
231
+ end # Test
232
+ end