minitest-hooks 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/README.rdoc +52 -15
- data/Rakefile +1 -2
- data/lib/minitest/hooks.rb +8 -3
- data/spec/minitest_hooks_direct_spec.rb +117 -0
- data/spec/minitest_hooks_spec.rb +11 -10
- data/spec/minitest_hooks_test.rb +125 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc5ab13e6ee044a2863034efc3ac937a421a4db7
|
4
|
+
data.tar.gz: 51b6c4ea85b9eb707f89b781e686ccd9cee60fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7574f8634e17b8d0cfb0c44afd963d075263edfce9f0773be50e3b9f7614c6f13787f4b78203b3fde86c045bcb5bb2f968ccb35b8ab734d4169f6c2e40771b3
|
7
|
+
data.tar.gz: 059e6099981202bcc989e42c5f9cee7f02d3fc3af4670a044dbd7f552229e2b3a43943e08aa0e3f4ac8cb4cae05b1799e15dfa729dadb81a8f5c03713487df42
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 1.1.0 (2015-05-11)
|
2
|
+
|
3
|
+
* Remove unnecessary module inclusion (jeremyevans)
|
4
|
+
|
5
|
+
* Add block-based around and around(:all) support (jeremyevans)
|
6
|
+
|
7
|
+
=== 1.0.1 (2015-04-26)
|
8
|
+
|
9
|
+
* Fix homepage in gemspec (jeremyevans)
|
10
|
+
|
1
11
|
=== 1.0.0 (2015-04-26)
|
2
12
|
|
3
13
|
* Initial Public Release
|
data/README.rdoc
CHANGED
@@ -13,9 +13,9 @@ significantly speed up testing for specs that share expensive database setup cod
|
|
13
13
|
|
14
14
|
Source code is available on GitHub at https://github.com/jeremyevans/minitest-hooks
|
15
15
|
|
16
|
-
= Usage
|
16
|
+
= Usage
|
17
17
|
|
18
|
-
==
|
18
|
+
== In Specs (Minitest::Spec)
|
19
19
|
|
20
20
|
=== For all specs
|
21
21
|
|
@@ -27,7 +27,7 @@ First, you need to require the library.
|
|
27
27
|
|
28
28
|
require 'minitest/hooks'
|
29
29
|
|
30
|
-
|
30
|
+
You can set the default for some specs to be <tt>Minitest::HooksSpec</tt>:
|
31
31
|
|
32
32
|
MiniTest::Spec.register_spec_type(/something/, Minitest::HooksSpec)
|
33
33
|
|
@@ -37,10 +37,7 @@ Alternatively, you can include <tt>Minitest::Hooks</tt> in a specific spec class
|
|
37
37
|
include Minitest::Hooks
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
methods defined in the class itself call +yield+ instead of +super+.
|
42
|
-
|
43
|
-
== before_all Hooks
|
40
|
+
=== before_all Hooks
|
44
41
|
|
45
42
|
To run code before any specs in the suite are executed, pass +:all+ to +before+:
|
46
43
|
|
@@ -50,7 +47,7 @@ To run code before any specs in the suite are executed, pass +:all+ to +before+:
|
|
50
47
|
end
|
51
48
|
end
|
52
49
|
|
53
|
-
|
50
|
+
=== after_all Hooks
|
54
51
|
|
55
52
|
To run code after all specs in the suite are executed, pass +:all+ to +after+:
|
56
53
|
|
@@ -60,25 +57,65 @@ To run code after all specs in the suite are executed, pass +:all+ to +after+:
|
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
|
60
|
+
=== around Hooks
|
64
61
|
|
65
|
-
To run code around each spec in a suite,
|
62
|
+
To run code around each spec in a suite, call +around+ with a block, and have the block
|
66
63
|
call +super+:
|
67
64
|
|
68
65
|
describe 'something' do
|
69
|
-
|
66
|
+
around do |&block|
|
70
67
|
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
71
|
-
super
|
68
|
+
super(&block)
|
72
69
|
end
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
|
-
|
73
|
+
=== around_all Hooks
|
77
74
|
|
78
|
-
To run code around all specs in a suite,
|
79
|
-
|
75
|
+
To run code around all specs in a suite, call <tt>around(:all)</tt> with a block,
|
76
|
+
and have the block call +super+:
|
80
77
|
|
81
78
|
describe 'something' do
|
79
|
+
around(:all) do |&block|
|
80
|
+
DB.transaction(:rollback=>:always) do
|
81
|
+
super(&block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
=== In Tests (Minitest::Test)
|
87
|
+
|
88
|
+
Create a subclass of <tt>Minitest::Test</tt> and include <tt>Minitest::Hooks</tt>,
|
89
|
+
and have your test classes subclass from that subclass:
|
90
|
+
|
91
|
+
require 'minitest/hooks'
|
92
|
+
class MyTest < Minitest::Test
|
93
|
+
include Minitest::Hooks
|
94
|
+
end
|
95
|
+
|
96
|
+
class TestSuite1 < MyTest
|
97
|
+
end
|
98
|
+
|
99
|
+
You can just define the +before_all+, +after_all+, +around+, and +around_all+ methods,
|
100
|
+
instead of using the spec DSL. Make sure to call super when overriding the methods.
|
101
|
+
|
102
|
+
class TestSuite1 < MyTest
|
103
|
+
def before_all
|
104
|
+
super
|
105
|
+
DB[:table].insert(:column=>1)
|
106
|
+
end
|
107
|
+
|
108
|
+
def after_all
|
109
|
+
DB[:table].delete
|
110
|
+
super
|
111
|
+
end
|
112
|
+
|
113
|
+
def around
|
114
|
+
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
115
|
+
super
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
82
119
|
def around_all
|
83
120
|
DB.transaction(:rollback=>:always) do
|
84
121
|
super
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "rake"
|
2
2
|
require "rake/clean"
|
3
|
-
require 'rake/testtask'
|
4
3
|
|
5
4
|
CLEAN.include ["minitest-hooks-*.gem", "rdoc", "coverage"]
|
6
5
|
|
@@ -13,7 +12,7 @@ end
|
|
13
12
|
|
14
13
|
desc "Run specs"
|
15
14
|
task :spec do
|
16
|
-
sh %{#{FileUtils::RUBY} -I lib spec
|
15
|
+
sh %{#{FileUtils::RUBY} -I lib -e 'ARGV.each{|f| require f}' ./spec/*.rb}
|
17
16
|
end
|
18
17
|
|
19
18
|
task :default=>:spec
|
data/lib/minitest/hooks.rb
CHANGED
@@ -9,7 +9,6 @@ module Minitest::Hooks
|
|
9
9
|
def self.included(mod)
|
10
10
|
super
|
11
11
|
mod.instance_exec do
|
12
|
-
include(@hooks_module ||= Module.new)
|
13
12
|
extend(Minitest::Hooks::ClassMethods)
|
14
13
|
end
|
15
14
|
end
|
@@ -74,10 +73,16 @@ module Minitest::Hooks::ClassMethods
|
|
74
73
|
r
|
75
74
|
end
|
76
75
|
|
76
|
+
# If type is :all, set the around_all hook, otherwise set the around hook.
|
77
|
+
def around(type=nil, &block)
|
78
|
+
meth = type == :all ? :around_all : :around
|
79
|
+
define_method(meth, &block)
|
80
|
+
end
|
81
|
+
|
77
82
|
# If type is :all, set the before_all hook instead of the before hook.
|
78
83
|
def before(type=nil, &block)
|
79
84
|
if type == :all
|
80
|
-
|
85
|
+
define_method(:before_all) do
|
81
86
|
super()
|
82
87
|
instance_exec(&block)
|
83
88
|
end
|
@@ -90,7 +95,7 @@ module Minitest::Hooks::ClassMethods
|
|
90
95
|
# If type is :all, set the after_all hook instead of the after hook.
|
91
96
|
def after(type=nil, &block)
|
92
97
|
if type == :all
|
93
|
-
|
98
|
+
define_method(:after_all) do
|
94
99
|
instance_exec(&block)
|
95
100
|
super()
|
96
101
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
gem 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/hooks'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
NDB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite:/')
|
9
|
+
|
10
|
+
MiniTest::Spec.register_spec_type(/no_default/, Minitest::Spec)
|
11
|
+
|
12
|
+
describe 'Minitest::Hooks with transactions/savepoints no_default' do
|
13
|
+
include Minitest::Hooks
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
@ds_ba = @ds_aa
|
17
|
+
@ds_ba.count.must_equal 1 + @i
|
18
|
+
end
|
19
|
+
before do
|
20
|
+
@ds_be = @ds_ae
|
21
|
+
@ds_be.count.must_equal 2 + @i * 2
|
22
|
+
end
|
23
|
+
after do
|
24
|
+
@ds_be.count.must_equal 2 + @i * 2
|
25
|
+
end
|
26
|
+
after(:all) do
|
27
|
+
@ds_ba.count.must_equal 1 + @i
|
28
|
+
end
|
29
|
+
around do |&block|
|
30
|
+
@ds_aa.count.must_equal 1 + @i
|
31
|
+
NDB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
32
|
+
@ds_ae = @ds_aa
|
33
|
+
@ds_ae.insert(1)
|
34
|
+
super(&block)
|
35
|
+
end
|
36
|
+
@ds_aa.count.must_equal 1 + @i
|
37
|
+
end
|
38
|
+
around(:all) do |&block|
|
39
|
+
@i ||= 0
|
40
|
+
NDB.transaction(:rollback=>:always) do
|
41
|
+
NDB.create_table(:a){Integer :a}
|
42
|
+
@ds_aa = NDB[:a]
|
43
|
+
@ds_aa.count.must_equal 0
|
44
|
+
@ds_aa.insert(1)
|
45
|
+
super(&block)
|
46
|
+
end
|
47
|
+
NDB.table_exists?(:a).must_equal false
|
48
|
+
end
|
49
|
+
|
50
|
+
3.times do |i|
|
51
|
+
it "should work try #{i}" do
|
52
|
+
@ds_aa.count.must_equal 2
|
53
|
+
@ds_ae.count.must_equal 2
|
54
|
+
@ds_ba.count.must_equal 2
|
55
|
+
@ds_be.count.must_equal 2
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "in nested describe" do
|
60
|
+
before(:all) do
|
61
|
+
@ds_ba3 = @ds_ba
|
62
|
+
@ds_ba2 = @ds_aa2
|
63
|
+
@ds_ba2.count.must_equal 2
|
64
|
+
end
|
65
|
+
before do
|
66
|
+
@ds_be3 = @ds_be
|
67
|
+
@ds_be2 = @ds_ae2
|
68
|
+
@ds_be2.count.must_equal 4
|
69
|
+
end
|
70
|
+
after do
|
71
|
+
@ds_be2.count.must_equal 4
|
72
|
+
end
|
73
|
+
after(:all) do
|
74
|
+
@ds_ba2.count.must_equal 2
|
75
|
+
end
|
76
|
+
around do |&block|
|
77
|
+
@ds_aa.count.must_equal 2
|
78
|
+
super() do
|
79
|
+
@ds_aa.count.must_equal 3
|
80
|
+
@ds_ae3 = @ds_ae
|
81
|
+
@ds_ae2 = @ds_aa2
|
82
|
+
@ds_ae2.insert(1)
|
83
|
+
block.call
|
84
|
+
@ds_aa.count.must_equal 4
|
85
|
+
end
|
86
|
+
@ds_aa.count.must_equal 2
|
87
|
+
end
|
88
|
+
around(:all) do |&block|
|
89
|
+
@i ||= 1
|
90
|
+
super() do
|
91
|
+
@ds_aa.count.must_equal 1
|
92
|
+
@ds_aa2 = @ds_aa
|
93
|
+
@ds_aa2.insert(1)
|
94
|
+
block.call
|
95
|
+
@ds_aa.count.must_equal 2
|
96
|
+
end
|
97
|
+
NDB.table_exists?(:a).must_equal false
|
98
|
+
end
|
99
|
+
|
100
|
+
3.times do |i|
|
101
|
+
it "should work try #{i}" do
|
102
|
+
@ds_aa.count.must_equal 4
|
103
|
+
@ds_ae.count.must_equal 4
|
104
|
+
@ds_ba.count.must_equal 4
|
105
|
+
@ds_be.count.must_equal 4
|
106
|
+
@ds_aa2.count.must_equal 4
|
107
|
+
@ds_ae2.count.must_equal 4
|
108
|
+
@ds_ba2.count.must_equal 4
|
109
|
+
@ds_be2.count.must_equal 4
|
110
|
+
@ds_ae3.count.must_equal 4
|
111
|
+
@ds_ba3.count.must_equal 4
|
112
|
+
@ds_be3.count.must_equal 4
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
data/spec/minitest_hooks_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'sequel'
|
3
|
+
gem 'minitest'
|
3
4
|
require 'minitest/autorun'
|
4
5
|
require 'minitest/hooks/default'
|
5
6
|
require 'logger'
|
@@ -21,23 +22,23 @@ describe 'Minitest::Hooks with transactions/savepoints' do
|
|
21
22
|
after(:all) do
|
22
23
|
@ds_ba.count.must_equal 1 + @i
|
23
24
|
end
|
24
|
-
|
25
|
+
around do |&block|
|
25
26
|
@ds_aa.count.must_equal 1 + @i
|
26
27
|
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
27
28
|
@ds_ae = @ds_aa
|
28
29
|
@ds_ae.insert(1)
|
29
|
-
super
|
30
|
+
super(&block)
|
30
31
|
end
|
31
32
|
@ds_aa.count.must_equal 1 + @i
|
32
33
|
end
|
33
|
-
|
34
|
+
around(:all) do |&block|
|
34
35
|
@i ||= 0
|
35
36
|
DB.transaction(:rollback=>:always) do
|
36
37
|
DB.create_table(:a){Integer :a}
|
37
38
|
@ds_aa = DB[:a]
|
38
39
|
@ds_aa.count.must_equal 0
|
39
40
|
@ds_aa.insert(1)
|
40
|
-
super
|
41
|
+
super(&block)
|
41
42
|
end
|
42
43
|
DB.table_exists?(:a).must_equal false
|
43
44
|
end
|
@@ -68,25 +69,25 @@ describe 'Minitest::Hooks with transactions/savepoints' do
|
|
68
69
|
after(:all) do
|
69
70
|
@ds_ba2.count.must_equal 2
|
70
71
|
end
|
71
|
-
|
72
|
+
around do |&block|
|
72
73
|
@ds_aa.count.must_equal 2
|
73
|
-
super do
|
74
|
+
super() do
|
74
75
|
@ds_aa.count.must_equal 3
|
75
76
|
@ds_ae3 = @ds_ae
|
76
77
|
@ds_ae2 = @ds_aa2
|
77
78
|
@ds_ae2.insert(1)
|
78
|
-
|
79
|
+
block.call
|
79
80
|
@ds_aa.count.must_equal 4
|
80
81
|
end
|
81
82
|
@ds_aa.count.must_equal 2
|
82
83
|
end
|
83
|
-
|
84
|
+
around(:all) do |&block|
|
84
85
|
@i ||= 1
|
85
|
-
super do
|
86
|
+
super() do
|
86
87
|
@ds_aa.count.must_equal 1
|
87
88
|
@ds_aa2 = @ds_aa
|
88
89
|
@ds_aa2.insert(1)
|
89
|
-
|
90
|
+
block.call
|
90
91
|
@ds_aa.count.must_equal 2
|
91
92
|
end
|
92
93
|
DB.table_exists?(:a).must_equal false
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel'
|
3
|
+
gem 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/hooks'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
|
9
|
+
class MyTest < Minitest::Test
|
10
|
+
include Minitest::Hooks
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestMinitestHooks < MyTest
|
14
|
+
DB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite:/')
|
15
|
+
|
16
|
+
def before_all
|
17
|
+
super
|
18
|
+
@ds_ba = @ds_aa
|
19
|
+
assert_equal @ds_ba.count, 1 + @i
|
20
|
+
end
|
21
|
+
def setup
|
22
|
+
super
|
23
|
+
@ds_be = @ds_ae
|
24
|
+
assert_equal @ds_be.count, 2 + @i * 2
|
25
|
+
end
|
26
|
+
def teardown
|
27
|
+
assert_equal @ds_be.count, 2 + @i * 2
|
28
|
+
super
|
29
|
+
end
|
30
|
+
def after_all
|
31
|
+
assert_equal @ds_ba.count, 1 + @i
|
32
|
+
super
|
33
|
+
end
|
34
|
+
def around
|
35
|
+
assert_equal @ds_aa.count, 1 + @i
|
36
|
+
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true) do
|
37
|
+
@ds_ae = @ds_aa
|
38
|
+
@ds_ae.insert(1)
|
39
|
+
super
|
40
|
+
end
|
41
|
+
assert_equal @ds_aa.count, 1 + @i
|
42
|
+
end
|
43
|
+
def around_all
|
44
|
+
@i ||= 0
|
45
|
+
DB.transaction(:rollback=>:always) do
|
46
|
+
DB.create_table(:a){Integer :a}
|
47
|
+
@ds_aa = DB[:a]
|
48
|
+
assert_equal @ds_aa.count, 0
|
49
|
+
@ds_aa.insert(1)
|
50
|
+
super
|
51
|
+
end
|
52
|
+
assert_equal DB.table_exists?(:a), false
|
53
|
+
end
|
54
|
+
|
55
|
+
3.times do |i|
|
56
|
+
define_method(:"test_should_work_#{i}") do
|
57
|
+
assert_equal @ds_aa.count, 2
|
58
|
+
assert_equal @ds_ae.count, 2
|
59
|
+
assert_equal @ds_ba.count, 2
|
60
|
+
assert_equal @ds_be.count, 2
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class TestMinitestHooks2 < self
|
65
|
+
def before_all
|
66
|
+
super
|
67
|
+
@ds_ba3 = @ds_ba
|
68
|
+
@ds_ba2 = @ds_aa2
|
69
|
+
assert_equal @ds_ba2.count, 2
|
70
|
+
end
|
71
|
+
def setup
|
72
|
+
super
|
73
|
+
@ds_be3 = @ds_be
|
74
|
+
@ds_be2 = @ds_ae2
|
75
|
+
assert_equal @ds_be2.count, 4
|
76
|
+
end
|
77
|
+
def teardown
|
78
|
+
assert_equal @ds_be2.count, 4
|
79
|
+
super
|
80
|
+
end
|
81
|
+
def after_all
|
82
|
+
assert_equal @ds_ba2.count, 2
|
83
|
+
super
|
84
|
+
end
|
85
|
+
def around
|
86
|
+
assert_equal @ds_aa.count, 2
|
87
|
+
super do
|
88
|
+
assert_equal @ds_aa.count, 3
|
89
|
+
@ds_ae3 = @ds_ae
|
90
|
+
@ds_ae2 = @ds_aa2
|
91
|
+
@ds_ae2.insert(1)
|
92
|
+
yield
|
93
|
+
assert_equal @ds_aa.count, 4
|
94
|
+
end
|
95
|
+
assert_equal @ds_aa.count, 2
|
96
|
+
end
|
97
|
+
def around_all
|
98
|
+
@i ||= 1
|
99
|
+
super do
|
100
|
+
assert_equal @ds_aa.count, 1
|
101
|
+
@ds_aa2 = @ds_aa
|
102
|
+
@ds_aa2.insert(1)
|
103
|
+
yield
|
104
|
+
assert_equal @ds_aa.count, 2
|
105
|
+
end
|
106
|
+
assert_equal DB.table_exists?(:a), false
|
107
|
+
end
|
108
|
+
|
109
|
+
3.times do |i|
|
110
|
+
define_method(:"test_should_work_#{i}") do
|
111
|
+
assert_equal @ds_aa.count, 4
|
112
|
+
assert_equal @ds_ae.count, 4
|
113
|
+
assert_equal @ds_ba.count, 4
|
114
|
+
assert_equal @ds_be.count, 4
|
115
|
+
assert_equal @ds_aa2.count, 4
|
116
|
+
assert_equal @ds_ae2.count, 4
|
117
|
+
assert_equal @ds_ba2.count, 4
|
118
|
+
assert_equal @ds_be2.count, 4
|
119
|
+
assert_equal @ds_ae3.count, 4
|
120
|
+
assert_equal @ds_ba3.count, 4
|
121
|
+
assert_equal @ds_be3.count, 4
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -71,7 +71,9 @@ files:
|
|
71
71
|
- Rakefile
|
72
72
|
- lib/minitest/hooks.rb
|
73
73
|
- lib/minitest/hooks/default.rb
|
74
|
+
- spec/minitest_hooks_direct_spec.rb
|
74
75
|
- spec/minitest_hooks_spec.rb
|
76
|
+
- spec/minitest_hooks_test.rb
|
75
77
|
homepage: http://github.com/jeremyevans/minitest-hooks
|
76
78
|
licenses:
|
77
79
|
- MIT
|