minitest-hooks 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc5ab13e6ee044a2863034efc3ac937a421a4db7
4
- data.tar.gz: 51b6c4ea85b9eb707f89b781e686ccd9cee60fda
3
+ metadata.gz: f627ec4c18d23a6411e5ca743c1c26ddfc0b7d7c
4
+ data.tar.gz: bab6646941a54c118f04121ece54b4f21453ed13
5
5
  SHA512:
6
- metadata.gz: f7574f8634e17b8d0cfb0c44afd963d075263edfce9f0773be50e3b9f7614c6f13787f4b78203b3fde86c045bcb5bb2f968ccb35b8ab734d4169f6c2e40771b3
7
- data.tar.gz: 059e6099981202bcc989e42c5f9cee7f02d3fc3af4670a044dbd7f552229e2b3a43943e08aa0e3f4ac8cb4cae05b1799e15dfa729dadb81a8f5c03713487df42
6
+ metadata.gz: 1b6c79f2546ad32cbeb5b8245a335e762528bfe5b1b2b47b7fddad10908543dbe23f839ab82927f38a7d2c68bc9da330a14b36b025d5a1c142b400c4789bcee0
7
+ data.tar.gz: d1d67e7620a1faff10d1c1ad104bf0feec27176f3e2cf81ac5f74dd7d2fafdbd667606dde1d06a0ab39d3275d80aa44fdad6107d8507b36d89ba535caf736414
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.2.0 (2015-07-02)
2
+
3
+ * Add minitest/hooks/test file, which doesn't requrie minitest/spec (janko-m) (#9, #10)
4
+
1
5
  === 1.1.0 (2015-05-11)
2
6
 
3
7
  * Remove unnecessary module inclusion (jeremyevans)
data/README.rdoc CHANGED
@@ -88,7 +88,7 @@ and have the block call +super+:
88
88
  Create a subclass of <tt>Minitest::Test</tt> and include <tt>Minitest::Hooks</tt>,
89
89
  and have your test classes subclass from that subclass:
90
90
 
91
- require 'minitest/hooks'
91
+ require 'minitest/hooks/test'
92
92
  class MyTest < Minitest::Test
93
93
  include Minitest::Hooks
94
94
  end
@@ -123,6 +123,70 @@ instead of using the spec DSL. Make sure to call super when overriding the meth
123
123
  end
124
124
  end
125
125
 
126
+ = Behavior
127
+
128
+ == Hooks Just Define Methods
129
+
130
+ Just like the before/after hooks supported by minitest, all hooks supported by minitest-hooks
131
+ just define methods on the spec class, there is no magic ("It's just ruby"). This has a
132
+ couple of effects:
133
+
134
+ 1. You cannot define multiple hooks of the same type in the same class. This is because
135
+ you cannot have multiple methods with the same name in the same class. If you define
136
+ a second hook of the same type in the same class, it will overwrite the previous hook,
137
+ just like ruby's behavior if you define a method twice in the same class.
138
+
139
+ 2. For around and around(:all) hooks, you should always call super. If you want a subclass
140
+ around hook to run inside a superclass around hook, you need to call super in the
141
+ subclass hook and run the code inside the block you pass to super, then call block.call
142
+ somewhere inside the super block:
143
+
144
+ describe "superclass" do
145
+ around do |&block|
146
+ some_outer_method do
147
+ super(&block)
148
+ end
149
+ end
150
+
151
+ describe "subclass" do
152
+ around do |&block|
153
+ super do
154
+ some_inner_method do
155
+ block.call
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ You do not need to call super for before(:all) or after(:all) hooks. Both before(:all) and
163
+ after(:all) implicitly call super for you in the method they define, mirroring minitest's
164
+ behavior for before and after hooks.
165
+
166
+ 3. All hooks share state/instance variables. So any instance variables you set in before(:all),
167
+ around(:all), or around are shared with the examples. Note that after(:all) will only see
168
+ instance variables set in before(:all) or around(:all), it will not see instance variables
169
+ set inside examples.
170
+
171
+ == All Spec Classes are Independent
172
+
173
+ The way minitest works, all spec classes are indepedent of other spec classes in terms
174
+ of how and when they are executed, even spec classes that are subclasses of other spec
175
+ classes. This means that for every spec class, the before(:all), after(:all), and
176
+ around(:all) hooks for that class will be executed, even if they were defined in the
177
+ spec's superclass and not in the spec class itself.
178
+
179
+ So if you have a spec superclass that uses before(:all), and a spec subclass for that
180
+ superclass, the before(:all) in the spec superclass will be run twice, once in the context
181
+ of an instance of the superclass, before executing the superclass's specs, and once in the
182
+ context of an instance of the subclass, before executing the subclass's specs.
183
+
184
+ == Order of Operations
185
+
186
+ For each spec class, the around(:all) hooks are run first. Both before(:all) and after(:all)
187
+ run inside around(:all). For each spec inside the spec the spec class, around will be called,
188
+ and before and after for each spec will be run inside around.
189
+
126
190
  = License
127
191
 
128
192
  MIT
@@ -1,111 +1,6 @@
1
+ require 'minitest/hooks/test'
1
2
  require 'minitest/spec'
2
3
 
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
- extend(Minitest::Hooks::ClassMethods)
13
- end
14
- end
15
-
16
- # Empty method, necessary so that super calls in spec subclasses work.
17
- def before_all
18
- end
19
-
20
- # Empty method, necessary so that super calls in spec subclasses work.
21
- def after_all
22
- end
23
-
24
- # Method that just yields, so that super calls in spec subclasses work.
25
- def around_all
26
- yield
27
- end
28
-
29
- # Method that just yields, so that super calls in spec subclasses work.
30
- def around
31
- yield
32
- end
33
-
34
- # Run around hook inside, since time_it is run around every spec.
35
- def time_it
36
- super do
37
- around do
38
- yield
39
- end
40
- end
41
- end
42
- end
43
-
44
- module Minitest::Hooks::ClassMethods
45
- # Object used to get an empty new instance, as new by default will return
46
- # a dup of the singleton instance.
47
- NEW = Object.new.freeze
48
-
49
- # Unless name is NEW, return a dup singleton instance.
50
- def new(name)
51
- if name.equal?(NEW)
52
- return super
53
- end
54
-
55
- instance = @instance.dup
56
- instance.name = name
57
- instance.failures = []
58
- instance
59
- end
60
-
61
- # When running the specs in the class, first create a singleton instance, the singleton is
62
- # used to implement around_all/before_all/after_all hooks, and each spec will run as a
63
- # dup of the singleton instance.
64
- def run(reporter, options={})
65
- r = nil
66
- @instance = new(NEW)
67
-
68
- @instance.around_all do
69
- @instance.before_all
70
- r = super
71
- @instance.after_all
72
- end
73
- r
74
- end
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
-
82
- # If type is :all, set the before_all hook instead of the before hook.
83
- def before(type=nil, &block)
84
- if type == :all
85
- define_method(:before_all) do
86
- super()
87
- instance_exec(&block)
88
- end
89
- nil
90
- else
91
- super
92
- end
93
- end
94
-
95
- # If type is :all, set the after_all hook instead of the after hook.
96
- def after(type=nil, &block)
97
- if type == :all
98
- define_method(:after_all) do
99
- instance_exec(&block)
100
- super()
101
- end
102
- nil
103
- else
104
- super
105
- end
106
- end
107
- end
108
-
109
4
  # Spec subclass that includes the hook methods.
110
5
  class Minitest::HooksSpec < Minitest::Spec
111
6
  include Minitest::Hooks
@@ -0,0 +1,107 @@
1
+ require 'minitest'
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
+ extend(Minitest::Hooks::ClassMethods)
13
+ end
14
+ end
15
+
16
+ # Empty method, necessary so that super calls in spec subclasses work.
17
+ def before_all
18
+ end
19
+
20
+ # Empty method, necessary so that super calls in spec subclasses work.
21
+ def after_all
22
+ end
23
+
24
+ # Method that just yields, so that super calls in spec subclasses work.
25
+ def around_all
26
+ yield
27
+ end
28
+
29
+ # Method that just yields, so that super calls in spec subclasses work.
30
+ def around
31
+ yield
32
+ end
33
+
34
+ # Run around hook inside, since time_it is run around every spec.
35
+ def time_it
36
+ super do
37
+ around do
38
+ yield
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ module Minitest::Hooks::ClassMethods
45
+ # Object used to get an empty new instance, as new by default will return
46
+ # a dup of the singleton instance.
47
+ NEW = Object.new.freeze
48
+
49
+ # Unless name is NEW, return a dup singleton instance.
50
+ def new(name)
51
+ if name.equal?(NEW)
52
+ return super
53
+ end
54
+
55
+ instance = @instance.dup
56
+ instance.name = name
57
+ instance.failures = []
58
+ instance
59
+ end
60
+
61
+ # When running the specs in the class, first create a singleton instance, the singleton is
62
+ # used to implement around_all/before_all/after_all hooks, and each spec will run as a
63
+ # dup of the singleton instance.
64
+ def run(reporter, options={})
65
+ r = nil
66
+ @instance = new(NEW)
67
+
68
+ @instance.around_all do
69
+ @instance.before_all
70
+ r = super(reporter, options)
71
+ @instance.after_all
72
+ end
73
+ r
74
+ end
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
+
82
+ # If type is :all, set the before_all hook instead of the before hook.
83
+ def before(type=nil, &block)
84
+ if type == :all
85
+ define_method(:before_all) do
86
+ super()
87
+ instance_exec(&block)
88
+ end
89
+ nil
90
+ else
91
+ super
92
+ end
93
+ end
94
+
95
+ # If type is :all, set the after_all hook instead of the after hook.
96
+ def after(type=nil, &block)
97
+ if type == :all
98
+ define_method(:after_all) do
99
+ instance_exec(&block)
100
+ super()
101
+ end
102
+ nil
103
+ else
104
+ super
105
+ end
106
+ end
107
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'sequel'
3
+ gem 'minitest'
4
+ require 'minitest/autorun'
@@ -1,9 +1,5 @@
1
- require 'rubygems'
2
- require 'sequel'
3
- gem 'minitest'
4
- require 'minitest/autorun'
1
+ require './spec/helper'
5
2
  require 'minitest/hooks'
6
- require 'logger'
7
3
 
8
4
  NDB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite:/')
9
5
 
@@ -1,9 +1,5 @@
1
- require 'rubygems'
2
- require 'sequel'
3
- gem 'minitest'
4
- require 'minitest/autorun'
1
+ require './spec/helper'
5
2
  require 'minitest/hooks/default'
6
- require 'logger'
7
3
 
8
4
  DB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite:/')
9
5
 
@@ -1,10 +1,5 @@
1
- require 'rubygems'
2
- require 'sequel'
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'minitest/hooks'
6
- require 'logger'
7
-
1
+ require './spec/helper'
2
+ require 'minitest/hooks/test'
8
3
 
9
4
  class MyTest < Minitest::Test
10
5
  include Minitest::Hooks
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.1.0
4
+ version: 1.2.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-05-11 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: |
56
70
  minitest-hooks adds around and before_all/after_all/around_all hooks for Minitest.
57
71
  This allows you do things like run each suite of specs inside a database transaction,
@@ -71,6 +85,8 @@ files:
71
85
  - Rakefile
72
86
  - lib/minitest/hooks.rb
73
87
  - lib/minitest/hooks/default.rb
88
+ - lib/minitest/hooks/test.rb
89
+ - spec/helper.rb
74
90
  - spec/minitest_hooks_direct_spec.rb
75
91
  - spec/minitest_hooks_spec.rb
76
92
  - spec/minitest_hooks_test.rb