minitest-hooks-1.5.0/0000755000004100000410000000000013324744244014531 5ustar www-datawww-dataminitest-hooks-1.5.0/spec/0000755000004100000410000000000013324744244015463 5ustar www-datawww-dataminitest-hooks-1.5.0/spec/minitest_hooks_spec.rb0000644000004100000410000000472013324744244022064 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks/default' DB = Sequel.connect(DATABASE_URL) describe 'Minitest::Hooks with transactions/savepoints' do before(:all) do @ds_ba = @ds_aa @ds_ba.count.must_equal 1 + @i end before do @ds_be = @ds_ae @ds_be.count.must_equal 2 + @i * 2 end after do @ds_be.count.must_equal 2 + @i * 2 end after(:all) do @ds_ba.count.must_equal 1 + @i end around do |&block| @ds_aa.count.must_equal 1 + @i DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do @ds_ae = @ds_aa @ds_ae.insert(1) super(&block) end @ds_aa.count.must_equal 1 + @i end around(:all) do |&block| @i ||= 0 DB.transaction(:rollback=>:always) do DB.create_table(:a){Integer :a} @ds_aa = DB[:a] @ds_aa.count.must_equal 0 @ds_aa.insert(1) super(&block) end DB.table_exists?(:a).must_equal false end 3.times do |i| it "should work try #{i}" do @ds_aa.count.must_equal 2 @ds_ae.count.must_equal 2 @ds_ba.count.must_equal 2 @ds_be.count.must_equal 2 end end describe "in nested describe" do before(:all) do @ds_ba3 = @ds_ba @ds_ba2 = @ds_aa2 @ds_ba2.count.must_equal 2 end before do @ds_be3 = @ds_be @ds_be2 = @ds_ae2 @ds_be2.count.must_equal 4 end after do @ds_be2.count.must_equal 4 end after(:all) do @ds_ba2.count.must_equal 2 end around do |&block| @ds_aa.count.must_equal 2 super() do @ds_aa.count.must_equal 3 @ds_ae3 = @ds_ae @ds_ae2 = @ds_aa2 @ds_ae2.insert(1) block.call @ds_aa.count.must_equal 4 end @ds_aa.count.must_equal 2 end around(:all) do |&block| @i ||= 1 super() do @ds_aa.count.must_equal 1 @ds_aa2 = @ds_aa @ds_aa2.insert(1) block.call @ds_aa.count.must_equal 2 end DB.table_exists?(:a).must_equal false end 3.times do |i| it "should work try #{i}" do @ds_aa.count.must_equal 4 @ds_ae.count.must_equal 4 @ds_ba.count.must_equal 4 @ds_be.count.must_equal 4 @ds_aa2.count.must_equal 4 @ds_ae2.count.must_equal 4 @ds_ba2.count.must_equal 4 @ds_be2.count.must_equal 4 @ds_ae3.count.must_equal 4 @ds_ba3.count.must_equal 4 @ds_be3.count.must_equal 4 end end end end minitest-hooks-1.5.0/spec/errors/0000755000004100000410000000000013324744244016777 5ustar www-datawww-dataminitest-hooks-1.5.0/spec/errors/example.rb0000644000004100000410000000346413324744244020766 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks/default' error = ENV['MINITEST_HOOKS_ERRORS'] module Minitest def self.plugin_result_inspector_reporter_init(options) self.reporter << ResultInspectorReporter.new(options[:io], options) end class ResultInspectorReporter < SummaryReporter def report results.each do |result| io.puts "result to_s: #{result.to_s.inspect}" # For MiniTest 5.11+, we expect Minitest::Result objects. if defined?(Minitest::Result) io.puts "result source_location: #{result.source_location.inspect}" else # For older versions of Minitest, extract source_location in a # similar fashion to how some third party reporters expected to be # able to: # https://github.com/circleci/minitest-ci/blob/8b72b0f32f154d91b53d63d1d0a8a8fb3b01d726/lib/minitest/ci_plugin.rb#L139 io.puts "result source_location: #{result.method(result.name).source_location.inspect}" end end end end end Minitest.extensions << "result_inspector_reporter" describe 'Minitest::Hooks error handling' do before(:all) do raise if error == 'before-all' end before do raise if error == 'before' end after do raise if error == 'after' end after(:all) do raise if error == 'after-all' end around do |&block| raise if error == 'around-before' super(&block) raise if error == 'around-after' end around(:all) do |&block| raise if error == 'around-all-before' super(&block) case error when 'before-all' name.must_equal 'before_all' when 'after-all' name.must_equal 'after_all' else name.must_equal 'around_all' end raise if error == 'around-all-after' end 3.times do |i| it "should work try #{i}" do end end end minitest-hooks-1.5.0/spec/helper.rb0000644000004100000410000000037713324744244017276 0ustar www-datawww-data$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../lib/")) require 'rubygems' require 'sequel' gem 'minitest' require 'minitest/autorun' DATABASE_URL = ENV['DATABASE_URL'] || (defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/') minitest-hooks-1.5.0/spec/all.rb0000644000004100000410000000041013324744244016553 0ustar www-datawww-datarequire 'rbconfig' ENV['RUBY'] ||= ENV["RUBY"] || File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]).sub(/.*\s.*/m, '"\&"') ENV['RUBYLIB'] = "lib:#{ENV['RUBYLIB']}" Dir['./spec/*_spec.rb'].each{|f| require f} minitest-hooks-1.5.0/spec/minitest_hooks_test.rb0000644000004100000410000000521513324744244022111 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks/test' class MyTest < Minitest::Test include Minitest::Hooks end class TestMinitestHooks < MyTest DB = Sequel.connect(DATABASE_URL) def before_all super @ds_ba = @ds_aa assert_equal @ds_ba.count, 1 + @i end def setup super @ds_be = @ds_ae assert_equal @ds_be.count, 2 + @i * 2 end def teardown assert_equal @ds_be.count, 2 + @i * 2 super end def after_all assert_equal @ds_ba.count, 1 + @i super end def around assert_equal @ds_aa.count, 1 + @i DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do @ds_ae = @ds_aa @ds_ae.insert(1) super end assert_equal @ds_aa.count, 1 + @i end def around_all @i ||= 0 DB.transaction(:rollback=>:always) do DB.create_table(:a){Integer :a} @ds_aa = DB[:a] assert_equal @ds_aa.count, 0 @ds_aa.insert(1) super end assert_equal DB.table_exists?(:a), false end 3.times do |i| define_method(:"test_should_work_#{i}") do assert_equal @ds_aa.count, 2 assert_equal @ds_ae.count, 2 assert_equal @ds_ba.count, 2 assert_equal @ds_be.count, 2 end end class TestMinitestHooks2 < self def before_all super @ds_ba3 = @ds_ba @ds_ba2 = @ds_aa2 assert_equal @ds_ba2.count, 2 end def setup super @ds_be3 = @ds_be @ds_be2 = @ds_ae2 assert_equal @ds_be2.count, 4 end def teardown assert_equal @ds_be2.count, 4 super end def after_all assert_equal @ds_ba2.count, 2 super end def around assert_equal @ds_aa.count, 2 super do assert_equal @ds_aa.count, 3 @ds_ae3 = @ds_ae @ds_ae2 = @ds_aa2 @ds_ae2.insert(1) yield assert_equal @ds_aa.count, 4 end assert_equal @ds_aa.count, 2 end def around_all @i ||= 1 super do assert_equal @ds_aa.count, 1 @ds_aa2 = @ds_aa @ds_aa2.insert(1) yield assert_equal @ds_aa.count, 2 end assert_equal DB.table_exists?(:a), false end 3.times do |i| define_method(:"test_should_work_#{i}") do assert_equal @ds_aa.count, 4 assert_equal @ds_ae.count, 4 assert_equal @ds_ba.count, 4 assert_equal @ds_be.count, 4 assert_equal @ds_aa2.count, 4 assert_equal @ds_ae2.count, 4 assert_equal @ds_ba2.count, 4 assert_equal @ds_be2.count, 4 assert_equal @ds_ae3.count, 4 assert_equal @ds_ba3.count, 4 assert_equal @ds_be3.count, 4 end end end end minitest-hooks-1.5.0/spec/minitest_hooks_direct_spec.rb0000644000004100000410000000506713324744244023423 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks' NDB = Sequel.connect(DATABASE_URL) MiniTest::Spec.register_spec_type(/no_default/, Minitest::Spec) describe 'Minitest::Hooks with transactions/savepoints no_default' do include Minitest::Hooks before(:all) do @ds_ba = @ds_aa @ds_ba.count.must_equal 1 + @i end before do @ds_be = @ds_ae @ds_be.count.must_equal 2 + @i * 2 end after do @ds_be.count.must_equal 2 + @i * 2 end after(:all) do @ds_ba.count.must_equal 1 + @i end around do |&block| @ds_aa.count.must_equal 1 + @i NDB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do @ds_ae = @ds_aa @ds_ae.insert(1) super(&block) end @ds_aa.count.must_equal 1 + @i end around(:all) do |&block| @i ||= 0 NDB.transaction(:rollback=>:always) do NDB.create_table(:a){Integer :a} @ds_aa = NDB[:a] @ds_aa.count.must_equal 0 @ds_aa.insert(1) super(&block) end NDB.table_exists?(:a).must_equal false end 3.times do |i| it "should work try #{i}" do @ds_aa.count.must_equal 2 @ds_ae.count.must_equal 2 @ds_ba.count.must_equal 2 @ds_be.count.must_equal 2 end end describe "in nested describe" do before(:all) do @ds_ba3 = @ds_ba @ds_ba2 = @ds_aa2 @ds_ba2.count.must_equal 2 end before do @ds_be3 = @ds_be @ds_be2 = @ds_ae2 @ds_be2.count.must_equal 4 end after do @ds_be2.count.must_equal 4 end after(:all) do @ds_ba2.count.must_equal 2 end around do |&block| @ds_aa.count.must_equal 2 super() do @ds_aa.count.must_equal 3 @ds_ae3 = @ds_ae @ds_ae2 = @ds_aa2 @ds_ae2.insert(1) block.call @ds_aa.count.must_equal 4 end @ds_aa.count.must_equal 2 end around(:all) do |&block| @i ||= 1 super() do @ds_aa.count.must_equal 1 @ds_aa2 = @ds_aa @ds_aa2.insert(1) block.call @ds_aa.count.must_equal 2 end NDB.table_exists?(:a).must_equal false end 3.times do |i| it "should work try #{i}" do @ds_aa.count.must_equal 4 @ds_ae.count.must_equal 4 @ds_ba.count.must_equal 4 @ds_be.count.must_equal 4 @ds_aa2.count.must_equal 4 @ds_ae2.count.must_equal 4 @ds_ba2.count.must_equal 4 @ds_be2.count.must_equal 4 @ds_ae3.count.must_equal 4 @ds_ba3.count.must_equal 4 @ds_be3.count.must_equal 4 end end end end minitest-hooks-1.5.0/spec/minitest_hooks_errors_spec.rb0000644000004100000410000000211313324744244023452 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks/default' require 'open3' RUBY = ENV['RUBY'] || 'ruby' describe 'Minitest::Hooks error handling' do def self.run_test(desc, runs, errors) it "should handle errors in #{desc}" do ENV['MINITEST_HOOKS_ERRORS'] = desc Open3.popen3(RUBY, "spec/errors/example.rb", "-v") do |_, o, e, w| output = o.read output.must_match /#{runs} runs, 0 assertions, 0 failures, #{errors} errors, 0 skips/ output.must_match /result to_s: ".*?Minitest::Hooks error handling#\w+.*?spec\/errors\/example\.rb:\d+/ output.must_match /result source_location: \["(unknown|.+?\.rb)", -?\d+\]/ output = e.read output.gsub!(/Picked up _JAVA_OPTIONS: [^\n]+\n/, '') output.must_equal '' w.value.exitstatus.wont_equal 0 if w end end end run_test "before-all", 1, 1 run_test "before", 3, 3 run_test "after", 3, 3 run_test "after-all", 4, 1 run_test "around-before", 1, 1 run_test "around-after", 1, 1 run_test "around-all-before", 1, 1 run_test "around-all-after", 4, 1 end minitest-hooks-1.5.0/spec/minitest_hooks_all_name_spec.rb0000644000004100000410000000141413324744244023711 0ustar www-datawww-datarequire './spec/helper' require 'minitest/hooks/default' describe 'Minitest::Hooks error handling' do before(:all) do name.must_equal 'before_all' end after(:all) do name.must_equal 'after_all' end around(:all) do |&block| name.must_equal 'around_all' super(&block) name.must_equal 'around_all' end 3.times do |i| it "should work try #{i}" do end end end class MinitestHooksNameTest < Minitest::Test include Minitest::Hooks def before_all assert_equal 'before_all', name end def after_all assert_equal 'after_all', name end def around_all assert_equal 'around_all', name super assert_equal 'around_all', name end 3.times do |i| define_method "test_should_work_try_#{i}" do end end end minitest-hooks-1.5.0/minitest-hooks.gemspec0000644000004100000410000000542313324744244021057 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: minitest-hooks 1.5.0 ruby lib Gem::Specification.new do |s| s.name = "minitest-hooks".freeze s.version = "1.5.0" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Jeremy Evans".freeze] s.date = "2018-05-21" s.description = "minitest-hooks adds around and before_all/after_all/around_all hooks for Minitest.\nThis allows you do things like run each suite of specs inside a database transaction,\nrunning each spec inside its own savepoint inside that transaction, which can\nsignificantly speed up testing for specs that share expensive database setup code.\n".freeze s.email = "code@jeremyevans.net".freeze s.extra_rdoc_files = ["CHANGELOG".freeze, "MIT-LICENSE".freeze, "README.rdoc".freeze] s.files = ["CHANGELOG".freeze, "MIT-LICENSE".freeze, "README.rdoc".freeze, "Rakefile".freeze, "lib/minitest/hooks.rb".freeze, "lib/minitest/hooks/default.rb".freeze, "lib/minitest/hooks/test.rb".freeze, "spec/all.rb".freeze, "spec/errors/example.rb".freeze, "spec/helper.rb".freeze, "spec/minitest_hooks_all_name_spec.rb".freeze, "spec/minitest_hooks_direct_spec.rb".freeze, "spec/minitest_hooks_errors_spec.rb".freeze, "spec/minitest_hooks_spec.rb".freeze, "spec/minitest_hooks_test.rb".freeze] s.homepage = "http://github.com/jeremyevans/minitest-hooks".freeze s.licenses = ["MIT".freeze] s.rdoc_options = ["--quiet".freeze, "--line-numbers".freeze, "--inline-source".freeze, "--title".freeze, "minitest-hooks: around and before_all/after_all/around_all hooks for Minitest".freeze, "--main".freeze, "README.rdoc".freeze] s.rubygems_version = "2.5.2.1".freeze s.summary = "Around and before_all/after_all/around_all hooks for Minitest".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, ["> 5.3"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["> 4"]) s.add_development_dependency(%q.freeze, [">= 0"]) else s.add_dependency(%q.freeze, ["> 5.3"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["> 4"]) s.add_dependency(%q.freeze, [">= 0"]) end else s.add_dependency(%q.freeze, ["> 5.3"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["> 4"]) s.add_dependency(%q.freeze, [">= 0"]) end end minitest-hooks-1.5.0/Rakefile0000644000004100000410000000166613324744244016207 0ustar www-datawww-datarequire "rake" require "rake/clean" CLEAN.include ["minitest-hooks-*.gem", "rdoc", "coverage"] desc "Build minitest-hooks gem" task :package=>[:clean] do |p| sh %{#{FileUtils::RUBY} -S gem build minitest-hooks.gemspec} end ### Specs desc "Run specs" task :spec do sh %{#{FileUtils::RUBY} spec/all.rb} end task :default=>:spec ### RDoc RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'minitest-hooks: around and before_all/after_all/around_all hooks for Minitest'] begin gem 'hanna-nouveau' RDOC_DEFAULT_OPTS.concat(['-f', 'hanna']) rescue Gem::LoadError end rdoc_task_class = begin require "rdoc/task" RDoc::Task rescue LoadError require "rake/rdoctask" Rake::RDocTask end RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc'] rdoc_task_class.new do |rdoc| rdoc.rdoc_dir = "rdoc" rdoc.options += RDOC_OPTS rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb" end minitest-hooks-1.5.0/lib/0000755000004100000410000000000013324744244015277 5ustar www-datawww-dataminitest-hooks-1.5.0/lib/minitest/0000755000004100000410000000000013324744244017133 5ustar www-datawww-dataminitest-hooks-1.5.0/lib/minitest/hooks.rb0000644000004100000410000000026013324744244020601 0ustar www-datawww-datarequire 'minitest/hooks/test' require 'minitest/spec' # Spec subclass that includes the hook methods. class Minitest::HooksSpec < Minitest::Spec include Minitest::Hooks end minitest-hooks-1.5.0/lib/minitest/hooks/0000755000004100000410000000000013324744244020256 5ustar www-datawww-dataminitest-hooks-1.5.0/lib/minitest/hooks/default.rb0000644000004100000410000000012513324744244022225 0ustar www-datawww-datarequire 'minitest/hooks' MiniTest::Spec.register_spec_type(//, Minitest::HooksSpec) minitest-hooks-1.5.0/lib/minitest/hooks/test.rb0000644000004100000410000000717313324744244021572 0ustar www-datawww-datarequire 'minitest' # Add support for around and before_all/after_all/around_all hooks to # minitest spec classes. module Minitest::Hooks # Add the class methods to the class. Also, include an additional # module in the class that before(:all) and after(:all) methods # work on a class that directly includes this module. def self.included(mod) super mod.instance_exec do extend(Minitest::Hooks::ClassMethods) end end # Empty method, necessary so that super calls in spec subclasses work. def before_all end # Empty method, necessary so that super calls in spec subclasses work. def after_all end # Method that just yields, so that super calls in spec subclasses work. def around_all yield end # Method that just yields, so that super calls in spec subclasses work. def around yield end # Run around hook inside, since time_it is run around every spec. def time_it super do around do yield end end end end module Minitest::Hooks::ClassMethods # Object used to get an empty new instance, as new by default will return # a dup of the singleton instance. NEW = Object.new.freeze # Unless name is NEW, return a dup singleton instance. def new(name) if name.equal?(NEW) return super('around_all') end instance = @instance.dup instance.name = name instance.failures = [] instance end # When running the specs in the class, first create a singleton instance, the singleton is # used to implement around_all/before_all/after_all hooks, and each spec will run as a # dup of the singleton instance. def with_info_handler(reporter, &block) @instance = new(NEW) @instance.time = 0 @instance.name = "around_all" begin @instance.around_all do begin @instance.capture_exceptions do @instance.name = "before_all" @instance.before_all end if @instance.failure failed = true _record_minitest_hooks_error(reporter, @instance) else super(reporter, &block) end ensure @instance.capture_exceptions do @instance.name = "after_all" unless failed @instance.after_all end if @instance.failure && !failed failed = true _record_minitest_hooks_error(reporter, @instance) end @instance.name = "around_all" unless failed end end rescue => e @instance.capture_exceptions do raise e end _record_minitest_hooks_error(reporter, @instance) end end # If type is :all, set the around_all hook, otherwise set the around hook. def around(type=nil, &block) meth = type == :all ? :around_all : :around define_method(meth, &block) end # If type is :all, set the before_all hook instead of the before hook. def before(type=nil, &block) if type == :all define_method(:before_all) do super() instance_exec(&block) end nil else super end end # If type is :all, set the after_all hook instead of the after hook. def after(type=nil, &block) if type == :all define_method(:after_all) do instance_exec(&block) super() end nil else super end end private def _record_minitest_hooks_error(reporter, instance) # In MiniTest 5.11+, use Minitest::Result for wrapping the object to send # to the reporter. if(defined?(Minitest::Result)) result = Minitest::Result.from(instance) else result = instance end reporter.record result end end minitest-hooks-1.5.0/README.rdoc0000644000004100000410000001312313324744244016337 0ustar www-datawww-data= minitest-hooks minitest-hooks adds around and before_all/after_all/around_all hooks for Minitest. This allows you do things like run each suite of specs inside a database transaction, running each spec inside its own savepoint inside that transaction, which can significantly speed up testing for specs that share expensive database setup code. = Installation gem install minitest-hooks = Source Code Source code is available on GitHub at https://github.com/jeremyevans/minitest-hooks = Usage == In Specs (Minitest::Spec) === For all specs require 'minitest/hooks/default' === For some specs First, you need to require the library. require 'minitest/hooks' You can set the default for some specs to be Minitest::HooksSpec: MiniTest::Spec.register_spec_type(/something/, Minitest::HooksSpec) Alternatively, you can include Minitest::Hooks in a specific spec class: describe 'something' do include Minitest::Hooks end === before_all Hooks To run code before any specs in the suite are executed, pass +:all+ to +before+: describe 'something' do before(:all) do DB[:table].insert(:column=>1) end end === after_all Hooks To run code after all specs in the suite are executed, pass +:all+ to +after+: describe 'something' do after(:all) do DB[:table].delete end end === around Hooks To run code around each spec in a suite, call +around+ with a block, and have the block call +super+: describe 'something' do around do |&block| DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do super(&block) end end end === around_all Hooks To run code around all specs in a suite, call around(:all) with a block, and have the block call +super+: describe 'something' do around(:all) do |&block| DB.transaction(:rollback=>:always) do super(&block) end end end === In Tests (Minitest::Test) Create a subclass of Minitest::Test and include Minitest::Hooks, and have your test classes subclass from that subclass: require 'minitest/hooks/test' class MyTest < Minitest::Test include Minitest::Hooks end class TestSuite1 < MyTest end You can just define the +before_all+, +after_all+, +around+, and +around_all+ methods, instead of using the spec DSL. Make sure to call super when overriding the methods. class TestSuite1 < MyTest def before_all super DB[:table].insert(:column=>1) end def after_all DB[:table].delete super end def around DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do super end end def around_all DB.transaction(:rollback=>:always) do super end end end = Behavior == Hooks Just Define Methods Just like the before/after hooks supported by minitest, all hooks supported by minitest-hooks just define methods on the spec class, there is no magic ("It's just ruby"). This has a couple of effects: 1. You cannot define multiple hooks of the same type in the same class. This is because you cannot have multiple methods with the same name in the same class. If you define a second hook of the same type in the same class, it will overwrite the previous hook, just like ruby's behavior if you define a method twice in the same class. 2. For around and around(:all) hooks, you should always call super. If you want a subclass around hook to run inside a superclass around hook, you need to call super in the subclass hook and run the code inside the block you pass to super, then call block.call somewhere inside the super block: describe "superclass" do around do |&block| some_outer_method do super(&block) end end describe "subclass" do around do |&block| super do some_inner_method do block.call end end end end end You do not need to call super for before(:all) or after(:all) hooks. Both before(:all) and after(:all) implicitly call super for you in the method they define, mirroring minitest's behavior for before and after hooks. 3. All hooks share state/instance variables. So any instance variables you set in before(:all), around(:all), or around are shared with the examples. Note that after(:all) will only see instance variables set in before(:all) or around(:all), it will not see instance variables set inside examples. == All Spec Classes are Independent The way minitest works, all spec classes are indepedent of other spec classes in terms of how and when they are executed, even spec classes that are subclasses of other spec classes. This means that for every spec class, the before(:all), after(:all), and around(:all) hooks for that class will be executed, even if they were defined in the spec's superclass and not in the spec class itself. So if you have a spec superclass that uses before(:all), and a spec subclass for that superclass, the before(:all) in the spec superclass will be run twice, once in the context of an instance of the superclass, before executing the superclass's specs, and once in the context of an instance of the subclass, before executing the subclass's specs. == Order of Operations For each spec class, the around(:all) hooks are run first. Both before(:all) and after(:all) run inside around(:all). For each spec inside the spec the spec class, around will be called, and before and after for each spec will be run inside around. = License MIT = Author Jeremy Evans minitest-hooks-1.5.0/MIT-LICENSE0000644000004100000410000000202613324744244016165 0ustar www-datawww-dataCopyright (c) 2015,2017 Jeremy Evans Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. minitest-hooks-1.5.0/CHANGELOG0000644000004100000410000000237113324744244015746 0ustar www-datawww-data=== 1.5.0 (2018-05-21) * Fix use with minitest 5.11+ by using Minitest::Result in such cases (GUI) (#15) === 1.4.2 (2017-09-12) * Don't modify test instance name if before_all/after_all cause an error (jeremyevans) (#14) * Set around_all test instance name to strings so that exceptions in {before,after,around}_all don't break reporters (jeremyevans) (#14) * Set time to 0 for around_all test instance so that exceptions in {before,after,around}_all don't break reporters (jeremyevans) (#13, #14) === 1.4.1 (2017-07-31) * Set test/spec name correctly when running before(:all)/after(:all)/around(:all) hooks (rcrogers, jeremyevans) (#12) === 1.4.0 (2015-11-17) * Handle errors in before(:all)/after(:all)/around(:all) hooks (jeremyevans) === 1.3.0 (2015-08-17) * Don't run before_all/after_all/around_all hooks for classes with no tests/specs when using minitest >= 5.8.0 (jeremyevans) (#7) === 1.2.0 (2015-07-02) * Add minitest/hooks/test file, which doesn't require minitest/spec (janko-m) (#9, #10) === 1.1.0 (2015-05-11) * Remove unnecessary module inclusion (jeremyevans) * Add block-based around and around(:all) support (jeremyevans) === 1.0.1 (2015-04-26) * Fix homepage in gemspec (jeremyevans) === 1.0.0 (2015-04-26) * Initial Public Release