pax_global_header 0000666 0000000 0000000 00000000064 14460501506 0014513 g ustar 00root root 0000000 0000000 52 comment=539c3e201c4ae9d93571d6487ca90faa572f1c39
minitest-hooks-1.5.1/ 0000775 0000000 0000000 00000000000 14460501506 0014474 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/.ci.gemfile 0000664 0000000 0000000 00000001122 14460501506 0016473 0 ustar 00root root 0000000 0000000 source 'http://rubygems.org'
minitest_version = case RUBY_VERSION
when /\A1.8/
'< 5.12'
when /\A1.9/
'< 5.4'
when /\A2.0/
'< 5.6'
when /\A2.1/
'< 5.8'
when /\A2.2/
'< 5.9'
when /\A2.3/
'< 5.10'
when /\A2.4/
'< 5.11'
else
'> 0'
end
gem 'minitest', minitest_version
gem 'minitest-global_expectations', '>=1.0.1'
if RUBY_VERSION < '1.9'
gem 'sequel', '< 5'
else
gem 'sequel'
end
if RUBY_VERSION < '2'
gem 'rake', '<10.0.0'
else
gem 'rake'
end
if defined?(JRUBY_VERSION)
gem 'jdbc-sqlite3'
elsif RUBY_VERSION < '1.9.3'
gem 'sqlite3', '<1.4'
else
gem 'sqlite3'
end
minitest-hooks-1.5.1/.github/ 0000775 0000000 0000000 00000000000 14460501506 0016034 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14460501506 0020071 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/.github/workflows/ci.yml 0000664 0000000 0000000 00000001107 14460501506 0021206 0 ustar 00root root 0000000 0000000 name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
permissions:
contents: read
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [ "1.9.3", "2.0.0", 2.1, 2.3, 2.4, 2.5, 2.6, 2.7, "3.0", 3.1, 3.2, jruby-9.2, jruby-9.3, jruby-9.4 ]
name: ${{ matrix.ruby }}
env:
BUNDLE_GEMFILE: .ci.gemfile
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
minitest-hooks-1.5.1/.gitignore 0000664 0000000 0000000 00000000075 14460501506 0016466 0 ustar 00root root 0000000 0000000 /rdoc
/minitest-hooks-*.gem
/Gemfile.lock
/.bundle
/coverage
minitest-hooks-1.5.1/CHANGELOG 0000664 0000000 0000000 00000002661 14460501506 0015713 0 ustar 00root root 0000000 0000000 === 1.5.1 (2023-07-27)
* Do not include specs or Rakefile in the gem (jeremyevans)
* Fix use with minitest 5.19+ by using Minitest instead of MiniTest as the constant (jeremyevans)
=== 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
minitest-hooks-1.5.1/Gemfile 0000664 0000000 0000000 00000000047 14460501506 0015770 0 ustar 00root root 0000000 0000000 source "https://rubygems.org"
gemspec
minitest-hooks-1.5.1/MIT-LICENSE 0000664 0000000 0000000 00000002026 14460501506 0016130 0 ustar 00root root 0000000 0000000 Copyright (c) 2015-2023 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.1/README.rdoc 0000664 0000000 0000000 00000013123 14460501506 0016302 0 ustar 00root root 0000000 0000000 = 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.1/Rakefile 0000664 0000000 0000000 00000002112 14460501506 0016135 0 ustar 00root root 0000000 0000000 require "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} #{"-w" if RUBY_VERSION >= '3'} spec/all.rb}
end
desc "Run specs with coverage"
task :spec_cov do
ENV['COVERAGE'] = '1'
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.1/lib/ 0000775 0000000 0000000 00000000000 14460501506 0015242 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/lib/minitest/ 0000775 0000000 0000000 00000000000 14460501506 0017076 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/lib/minitest/hooks.rb 0000664 0000000 0000000 00000000260 14460501506 0020544 0 ustar 00root root 0000000 0000000 require '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.1/lib/minitest/hooks/ 0000775 0000000 0000000 00000000000 14460501506 0020221 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/lib/minitest/hooks/default.rb 0000664 0000000 0000000 00000000125 14460501506 0022170 0 ustar 00root root 0000000 0000000 require 'minitest/hooks'
Minitest::Spec.register_spec_type(//, Minitest::HooksSpec)
minitest-hooks-1.5.1/lib/minitest/hooks/test.rb 0000664 0000000 0000000 00000007227 14460501506 0021535 0 ustar 00root root 0000000 0000000 require '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)
# :nocov:
else
result = instance
# :nocov:
end
reporter.record result
end
end
minitest-hooks-1.5.1/minitest-hooks.gemspec 0000664 0000000 0000000 00000002342 14460501506 0021017 0 ustar 00root root 0000000 0000000 Gem::Specification.new do |s|
s.name = 'minitest-hooks'
s.version = '1.5.1'
s.platform = Gem::Platform::RUBY
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"]
s.rdoc_options += ["--quiet", "--line-numbers", "--inline-source", '--title', 'minitest-hooks: around and before_all/after_all/around_all hooks for Minitest', '--main', 'README.rdoc']
s.license = "MIT"
s.summary = "Around and before_all/after_all/around_all hooks for Minitest"
s.author = "Jeremy Evans"
s.email = "code@jeremyevans.net"
s.homepage = "http://github.com/jeremyevans/minitest-hooks"
s.files = %w(MIT-LICENSE CHANGELOG README.rdoc) + Dir["lib/**/*.rb"]
s.description = <5.3"
s.add_development_dependency "sequel", '>4'
s.add_development_dependency "sqlite3"
s.add_development_dependency "rake"
s.add_development_dependency "minitest-global_expectations"
end
minitest-hooks-1.5.1/spec/ 0000775 0000000 0000000 00000000000 14460501506 0015426 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/spec/all.rb 0000664 0000000 0000000 00000000417 14460501506 0016525 0 ustar 00root root 0000000 0000000 require '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,test}.rb'].each{|f| require f}
minitest-hooks-1.5.1/spec/errors/ 0000775 0000000 0000000 00000000000 14460501506 0016742 5 ustar 00root root 0000000 0000000 minitest-hooks-1.5.1/spec/errors/example.rb 0000664 0000000 0000000 00000003464 14460501506 0020731 0 ustar 00root root 0000000 0000000 require './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.1/spec/helper.rb 0000664 0000000 0000000 00000000640 14460501506 0017232 0 ustar 00root root 0000000 0000000 $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../lib/"))
require 'rubygems'
require 'sequel'
if ENV.delete('COVERAGE')
require_relative 'simplecov_helper'
end
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
gem 'minitest'
require 'minitest/global_expectations/autorun'
DATABASE_URL = ENV['DATABASE_URL'] || (defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/')
minitest-hooks-1.5.1/spec/minitest_hooks_all_name_spec.rb 0000664 0000000 0000000 00000001414 14460501506 0023654 0 ustar 00root root 0000000 0000000 require './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.1/spec/minitest_hooks_direct_spec.rb 0000664 0000000 0000000 00000005067 14460501506 0023366 0 ustar 00root root 0000000 0000000 require './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.1/spec/minitest_hooks_errors_spec.rb 0000664 0000000 0000000 00000002116 14460501506 0023420 0 ustar 00root root 0000000 0000000 require './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.1/spec/minitest_hooks_spec.rb 0000664 0000000 0000000 00000004720 14460501506 0022027 0 ustar 00root root 0000000 0000000 require './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.1/spec/minitest_hooks_test.rb 0000664 0000000 0000000 00000005215 14460501506 0022054 0 ustar 00root root 0000000 0000000 require './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.1/spec/simplecov_helper.rb 0000664 0000000 0000000 00000001277 14460501506 0021322 0 ustar 00root root 0000000 0000000 require 'simplecov'
SimpleCov.instance_exec do
enable_coverage :branch
add_filter "/spec/"
add_group('Missing'){|src| src.covered_percent < 100}
add_group('Covered'){|src| src.covered_percent == 100}
enable_for_subprocesses true
at_fork do |pid|
command_name "#{SimpleCov.command_name} (subprocess: #{pid})"
self.print_error_status = false
formatter SimpleCov::Formatter::SimpleFormatter
minimum_coverage 0
start
end
if ENV['COVERAGE'] == 'subprocess'
ENV.delete('COVERAGE')
command_name 'spawn'
at_fork.call(Process.pid)
else
ENV['COVERAGE'] = 'subprocess'
ENV['RUBYOPT'] = "#{ENV['RUBYOPT']} -r ./spec/simplecov_helper"
start
end
end