minitest-hooks 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +18 -0
- data/README.rdoc +95 -0
- data/Rakefile +46 -0
- data/lib/minitest/hooks.rb +107 -0
- data/lib/minitest/hooks/default.rb +3 -0
- data/spec/minitest_hooks_spec.rb +111 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a0a8293b0c8dbbad1e27c3d3e6cb9bf92fc59a3
|
4
|
+
data.tar.gz: 56adcfa31aaaea60a526c44f092216d315ffa082
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ade327c7055a6f152143ad1f8f6d20d7142c43cfc54f76f2a281c99cd00df52751f81abf301b74c5ce14c7382d13afa7a9d7038d5d7669bc200f68ebfe23ba64
|
7
|
+
data.tar.gz: b4020676c1ce37af3cd6f2903c1455c44cef0229365a08f83caa93832134a3b29aa21724ddfa682bf38bd09642f80495127a135e17601ad08b4eb76b7726035b
|
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2015 Jeremy Evans
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
= minitest-hooks
|
2
|
+
|
3
|
+
minitest-hooks adds around and before_all/after_all/around_all hooks for Minitest.
|
4
|
+
This allows you do things like run each suite of specs inside a database transaction,
|
5
|
+
running each spec inside its own savepoint inside that transaction, which can
|
6
|
+
significantly speed up testing for specs that share expensive database setup code.
|
7
|
+
|
8
|
+
= Installation
|
9
|
+
|
10
|
+
gem install enum_csv
|
11
|
+
|
12
|
+
= Source Code
|
13
|
+
|
14
|
+
Source code is available on GitHub at https://github.com/jeremyevans/minitest-hooks
|
15
|
+
|
16
|
+
= Usage
|
17
|
+
|
18
|
+
== Using the library
|
19
|
+
|
20
|
+
=== For all specs
|
21
|
+
|
22
|
+
require 'minitest/hooks/default'
|
23
|
+
|
24
|
+
=== For some specs
|
25
|
+
|
26
|
+
First, you need to require the library.
|
27
|
+
|
28
|
+
require 'minitest/hooks'
|
29
|
+
|
30
|
+
Or you can set the default for some specs to be <tt>Minitest::HooksSpec</tt>:
|
31
|
+
|
32
|
+
MiniTest::Spec.register_spec_type(/something/, Minitest::HooksSpec)
|
33
|
+
|
34
|
+
Alternatively, you can include <tt>Minitest::Hooks</tt> in a specific spec class:
|
35
|
+
|
36
|
+
describe 'something' do
|
37
|
+
include Minitest::Hooks
|
38
|
+
end
|
39
|
+
|
40
|
+
But if you do this, you need to make sure that any +around+ and +around_all+
|
41
|
+
methods defined in the class itself call +yield+ instead of +super+.
|
42
|
+
|
43
|
+
== before_all Hooks
|
44
|
+
|
45
|
+
To run code before any specs in the suite are executed, pass +:all+ to +before+:
|
46
|
+
|
47
|
+
describe 'something' do
|
48
|
+
before(:all) do
|
49
|
+
DB[:table].insert(:column=>1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
== after_all Hooks
|
54
|
+
|
55
|
+
To run code after all specs in the suite are executed, pass +:all+ to +after+:
|
56
|
+
|
57
|
+
describe 'something' do
|
58
|
+
after(:all) do
|
59
|
+
DB[:table].delete
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
== around Hooks
|
64
|
+
|
65
|
+
To run code around each spec in a suite, define the +around+ method and have it
|
66
|
+
call +super+:
|
67
|
+
|
68
|
+
describe 'something' do
|
69
|
+
def around
|
70
|
+
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
== around_all Hooks
|
77
|
+
|
78
|
+
To run code around all specs in a suite, define the +around_all+ method and have
|
79
|
+
it call +super+:
|
80
|
+
|
81
|
+
describe 'something' do
|
82
|
+
def around_all
|
83
|
+
DB.transaction(:rollback=>:always) do
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
= License
|
90
|
+
|
91
|
+
MIT
|
92
|
+
|
93
|
+
= Author
|
94
|
+
|
95
|
+
Jeremy Evans <code@jeremyevans.net>
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/clean"
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include ["enum_csv-*.gem", "rdoc", "coverage"]
|
6
|
+
|
7
|
+
desc "Build minitest-hooks gem"
|
8
|
+
task :package=>[:clean] do |p|
|
9
|
+
sh %{#{FileUtils::RUBY} -S gem build minitest-hooks.gemspec}
|
10
|
+
end
|
11
|
+
|
12
|
+
### Specs
|
13
|
+
|
14
|
+
desc "Run specs"
|
15
|
+
task :spec do
|
16
|
+
sh %{#{FileUtils::RUBY} -I lib spec/minitest_hooks_spec.rb}
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default=>:spec
|
20
|
+
|
21
|
+
### RDoc
|
22
|
+
|
23
|
+
RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'minitest-hooks: around and before_all/after_all/around_all hooks for Minitest']
|
24
|
+
|
25
|
+
begin
|
26
|
+
gem 'hanna-nouveau'
|
27
|
+
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
|
28
|
+
rescue Gem::LoadError
|
29
|
+
end
|
30
|
+
|
31
|
+
rdoc_task_class = begin
|
32
|
+
require "rdoc/task"
|
33
|
+
RDoc::Task
|
34
|
+
rescue LoadError
|
35
|
+
require "rake/rdoctask"
|
36
|
+
Rake::RDocTask
|
37
|
+
end
|
38
|
+
|
39
|
+
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
40
|
+
|
41
|
+
rdoc_task_class.new do |rdoc|
|
42
|
+
rdoc.rdoc_dir = "rdoc"
|
43
|
+
rdoc.options += RDOC_OPTS
|
44
|
+
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
# Add support for around and before_all/after_all/around_all hooks to
|
4
|
+
# minitest spec classes.
|
5
|
+
module Minitest::Hooks
|
6
|
+
# Add the class methods to the class. Also, include an additional
|
7
|
+
# module in the class that before(:all) and after(:all) methods
|
8
|
+
# work on a class that directly includes this module.
|
9
|
+
def self.included(mod)
|
10
|
+
super
|
11
|
+
mod.instance_exec do
|
12
|
+
include(@hooks_module ||= Module.new)
|
13
|
+
extend(Minitest::Hooks::ClassMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Empty method, necessary so that super calls in spec subclasses work.
|
18
|
+
def before_all
|
19
|
+
end
|
20
|
+
|
21
|
+
# Empty method, necessary so that super calls in spec subclasses work.
|
22
|
+
def after_all
|
23
|
+
end
|
24
|
+
|
25
|
+
# Method that just yields, so that super calls in spec subclasses work.
|
26
|
+
def around_all
|
27
|
+
yield
|
28
|
+
end
|
29
|
+
|
30
|
+
# Method that just yields, so that super calls in spec subclasses work.
|
31
|
+
def around
|
32
|
+
yield
|
33
|
+
end
|
34
|
+
|
35
|
+
# Run around hook inside, since time_it is run around every spec.
|
36
|
+
def time_it
|
37
|
+
super do
|
38
|
+
around do
|
39
|
+
yield
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Minitest::Hooks::ClassMethods
|
46
|
+
# Object used to get an empty new instance, as new by default will return
|
47
|
+
# a dup of the singleton instance.
|
48
|
+
NEW = Object.new.freeze
|
49
|
+
|
50
|
+
# Unless name is NEW, return a dup singleton instance.
|
51
|
+
def new(name)
|
52
|
+
if name.equal?(NEW)
|
53
|
+
return super
|
54
|
+
end
|
55
|
+
|
56
|
+
instance = @instance.dup
|
57
|
+
instance.name = name
|
58
|
+
instance.failures = []
|
59
|
+
instance
|
60
|
+
end
|
61
|
+
|
62
|
+
# When running the specs in the class, first create a singleton instance, the singleton is
|
63
|
+
# used to implement around_all/before_all/after_all hooks, and each spec will run as a
|
64
|
+
# dup of the singleton instance.
|
65
|
+
def run(reporter, options={})
|
66
|
+
r = nil
|
67
|
+
@instance = new(NEW)
|
68
|
+
|
69
|
+
@instance.around_all do
|
70
|
+
@instance.before_all
|
71
|
+
r = super
|
72
|
+
@instance.after_all
|
73
|
+
end
|
74
|
+
r
|
75
|
+
end
|
76
|
+
|
77
|
+
# If type is :all, set the before_all hook instead of the before hook.
|
78
|
+
def before(type=nil, &block)
|
79
|
+
if type == :all
|
80
|
+
(defined?(@hooks_module) ? @hooks_module : self).send(:define_method, :before_all) do
|
81
|
+
super()
|
82
|
+
instance_exec(&block)
|
83
|
+
end
|
84
|
+
nil
|
85
|
+
else
|
86
|
+
super
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# If type is :all, set the after_all hook instead of the after hook.
|
91
|
+
def after(type=nil, &block)
|
92
|
+
if type == :all
|
93
|
+
(defined?(@hooks_module) ? @hooks_module : self).send(:define_method, :after_all) do
|
94
|
+
instance_exec(&block)
|
95
|
+
super()
|
96
|
+
end
|
97
|
+
nil
|
98
|
+
else
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Spec subclass that includes the hook methods.
|
105
|
+
class Minitest::HooksSpec < Minitest::Spec
|
106
|
+
include Minitest::Hooks
|
107
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/hooks/default'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
DB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite:/')
|
8
|
+
|
9
|
+
describe 'Minitest::Hooks with transactions/savepoints' do
|
10
|
+
before(:all) do
|
11
|
+
@ds_ba = @ds_aa
|
12
|
+
@ds_ba.count.must_equal 1 + @i
|
13
|
+
end
|
14
|
+
before do
|
15
|
+
@ds_be = @ds_ae
|
16
|
+
@ds_be.count.must_equal 2 + @i * 2
|
17
|
+
end
|
18
|
+
after do
|
19
|
+
@ds_be.count.must_equal 2 + @i * 2
|
20
|
+
end
|
21
|
+
after(:all) do
|
22
|
+
@ds_ba.count.must_equal 1 + @i
|
23
|
+
end
|
24
|
+
def around
|
25
|
+
@ds_aa.count.must_equal 1 + @i
|
26
|
+
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
27
|
+
@ds_ae = @ds_aa
|
28
|
+
@ds_ae.insert(1)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
@ds_aa.count.must_equal 1 + @i
|
32
|
+
end
|
33
|
+
def around_all
|
34
|
+
@i ||= 0
|
35
|
+
DB.transaction(:rollback=>:always) do
|
36
|
+
DB.create_table(:a){Integer :a}
|
37
|
+
@ds_aa = DB[:a]
|
38
|
+
@ds_aa.count.must_equal 0
|
39
|
+
@ds_aa.insert(1)
|
40
|
+
super
|
41
|
+
end
|
42
|
+
DB.table_exists?(:a).must_equal false
|
43
|
+
end
|
44
|
+
|
45
|
+
3.times do |i|
|
46
|
+
it "should work try #{i}" do
|
47
|
+
@ds_aa.count.must_equal 2
|
48
|
+
@ds_ae.count.must_equal 2
|
49
|
+
@ds_ba.count.must_equal 2
|
50
|
+
@ds_be.count.must_equal 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "in nested describe" do
|
55
|
+
before(:all) do
|
56
|
+
@ds_ba3 = @ds_ba
|
57
|
+
@ds_ba2 = @ds_aa2
|
58
|
+
@ds_ba2.count.must_equal 2
|
59
|
+
end
|
60
|
+
before do
|
61
|
+
@ds_be3 = @ds_be
|
62
|
+
@ds_be2 = @ds_ae2
|
63
|
+
@ds_be2.count.must_equal 4
|
64
|
+
end
|
65
|
+
after do
|
66
|
+
@ds_be2.count.must_equal 4
|
67
|
+
end
|
68
|
+
after(:all) do
|
69
|
+
@ds_ba2.count.must_equal 2
|
70
|
+
end
|
71
|
+
def around
|
72
|
+
@ds_aa.count.must_equal 2
|
73
|
+
super do
|
74
|
+
@ds_aa.count.must_equal 3
|
75
|
+
@ds_ae3 = @ds_ae
|
76
|
+
@ds_ae2 = @ds_aa2
|
77
|
+
@ds_ae2.insert(1)
|
78
|
+
yield
|
79
|
+
@ds_aa.count.must_equal 4
|
80
|
+
end
|
81
|
+
@ds_aa.count.must_equal 2
|
82
|
+
end
|
83
|
+
def around_all
|
84
|
+
@i ||= 1
|
85
|
+
super do
|
86
|
+
@ds_aa.count.must_equal 1
|
87
|
+
@ds_aa2 = @ds_aa
|
88
|
+
@ds_aa2.insert(1)
|
89
|
+
yield
|
90
|
+
@ds_aa.count.must_equal 2
|
91
|
+
end
|
92
|
+
DB.table_exists?(:a).must_equal false
|
93
|
+
end
|
94
|
+
|
95
|
+
3.times do |i|
|
96
|
+
it "should work try #{i}" do
|
97
|
+
@ds_aa.count.must_equal 4
|
98
|
+
@ds_ae.count.must_equal 4
|
99
|
+
@ds_ba.count.must_equal 4
|
100
|
+
@ds_be.count.must_equal 4
|
101
|
+
@ds_aa2.count.must_equal 4
|
102
|
+
@ds_ae2.count.must_equal 4
|
103
|
+
@ds_ba2.count.must_equal 4
|
104
|
+
@ds_be2.count.must_equal 4
|
105
|
+
@ds_ae3.count.must_equal 4
|
106
|
+
@ds_ba3.count.must_equal 4
|
107
|
+
@ds_be3.count.must_equal 4
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-hooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
minitest-hooks adds around and before_all/after_all/around_all hooks for Minitest.
|
57
|
+
This allows you do things like run each suite of specs inside a database transaction,
|
58
|
+
running each spec inside its own savepoint inside that transaction, which can
|
59
|
+
significantly speed up testing for specs that share expensive database setup code.
|
60
|
+
email: code@jeremyevans.net
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- README.rdoc
|
65
|
+
- CHANGELOG
|
66
|
+
- MIT-LICENSE
|
67
|
+
files:
|
68
|
+
- CHANGELOG
|
69
|
+
- MIT-LICENSE
|
70
|
+
- README.rdoc
|
71
|
+
- Rakefile
|
72
|
+
- lib/minitest/hooks.rb
|
73
|
+
- lib/minitest/hooks/default.rb
|
74
|
+
- spec/minitest_hooks_spec.rb
|
75
|
+
homepage: http://github.com/jeremyevans/minitest_hooks
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- "--quiet"
|
82
|
+
- "--line-numbers"
|
83
|
+
- "--inline-source"
|
84
|
+
- "--title"
|
85
|
+
- 'minitest-hooks: around and before_all/after_all/around_all hooks for Minitest'
|
86
|
+
- "--main"
|
87
|
+
- README.rdoc
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.4.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Around and before_all/after_all/around_all hooks for Minitest
|
106
|
+
test_files: []
|