minitest-tagz 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/minitest/tagz.rb +44 -4
- data/lib/minitest/tagz/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae273911ca71a1549e9a3d7b8878559cf51035d2
|
4
|
+
data.tar.gz: 9b0e9c6a9e336d7aca78a884622dcfaf1be5dda2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 413b067f5f444b4a38ae58a1c69130beb7c8b2949547de989d04ae2e88f2184091155d74de282638d86a3dfb08d712c75ab9d11c85fef6cffff1e809a9f24c92
|
7
|
+
data.tar.gz: 219c6782f038990ad77bcabbfb630d1d266114b328f9d0e40951c27472c75cab4514322a50325276512c69846c9068e3d30251722bc77b6425a8641bb5b33014
|
data/README.md
CHANGED
@@ -89,6 +89,13 @@ class MySpec < Minitest::Spec
|
|
89
89
|
end
|
90
90
|
```
|
91
91
|
|
92
|
+
You can also use the `run_all_if_no_match` option to do something like always have a `:focus` tag on-demand:
|
93
|
+
|
94
|
+
```rb
|
95
|
+
Minitest::Tagz.choose_tags(*ENV['TAGS'].split(','), run_all_if_no_match: true) if ENV['TAGS']
|
96
|
+
```
|
97
|
+
|
98
|
+
|
92
99
|
## Debugging
|
93
100
|
|
94
101
|
You can save a reference to the tagger and watch the internal state machine:
|
data/lib/minitest/tagz.rb
CHANGED
@@ -3,13 +3,14 @@ require 'state_machine'
|
|
3
3
|
|
4
4
|
module Minitest
|
5
5
|
module Tagz
|
6
|
+
# The strategy for patching the Minitest run time
|
6
7
|
module MinitestRunnerStrategy
|
7
8
|
class << self
|
8
9
|
def serialize(owner, test_name)
|
9
10
|
"#{owner} >> #{test_name}"
|
10
11
|
end
|
11
12
|
|
12
|
-
module
|
13
|
+
module RunnableMethodsFilter
|
13
14
|
def runnable_methods
|
14
15
|
all_runnables = super
|
15
16
|
if Tagz.chosen_tags && Tagz.chosen_tags.any?
|
@@ -25,8 +26,31 @@ module Minitest
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
module RunPatch
|
30
|
+
def run(*args)
|
31
|
+
# Check for no match and don't filter runnable methods if there would be no match
|
32
|
+
if Tagz.run_all_if_no_match?
|
33
|
+
run_map = Runnable.runnables.reduce({}) {|memo, r| memo[r] = r.runnable_methods; memo}
|
34
|
+
should_skip_filter = run_map.all? do |ctxt, methods|
|
35
|
+
methods.all? do |m|
|
36
|
+
serialized = MinitestRunnerStrategy.serialize(ctxt, m)
|
37
|
+
tags = MinitestRunnerStrategy.tag_map[serialized]
|
38
|
+
tags.nil? || tags.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
if should_skip_filter
|
42
|
+
puts "Couldn't find any runnables with the given tag, running all runnables"
|
43
|
+
return super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
::Minitest::Test.singleton_class.prepend(RunnableMethodsFilter)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
28
52
|
def patch
|
29
|
-
::Minitest
|
53
|
+
::Minitest.singleton_class.prepend(RunPatch)
|
30
54
|
end
|
31
55
|
|
32
56
|
def tag_map
|
@@ -35,15 +59,22 @@ module Minitest
|
|
35
59
|
end
|
36
60
|
end
|
37
61
|
|
62
|
+
# Patch the Minitest runtime to hook into Tagz
|
38
63
|
MinitestRunnerStrategy.patch
|
64
|
+
|
65
|
+
# Alias
|
39
66
|
RunnerStrategy = MinitestRunnerStrategy
|
40
67
|
|
68
|
+
# Was more useful when I was trying to add
|
69
|
+
# shoulda-context support
|
41
70
|
module BaseMixin
|
42
71
|
def tag(*tags)
|
43
72
|
Tagz.declare_tag_assignment(self, tags)
|
44
73
|
end
|
45
74
|
end
|
46
75
|
|
76
|
+
# Was more useful when I was trying to add
|
77
|
+
# shoulda-context support
|
47
78
|
class TaggerFactory
|
48
79
|
def self.create_tagger(owner, pending_tags)
|
49
80
|
patchers = [MinitestPatcher]
|
@@ -51,6 +82,9 @@ module Minitest
|
|
51
82
|
end
|
52
83
|
end
|
53
84
|
|
85
|
+
# Represents the individual instance of a `tag` call
|
86
|
+
# It is essentially a state machine that works with the
|
87
|
+
# patcher to patch and unpatch Minitest properly
|
54
88
|
class Tagger
|
55
89
|
state_machine :state, initial: :awaiting_tag_declaration do
|
56
90
|
after_transition any => :awaiting_test_definition, do: :patch_test_definitions
|
@@ -95,6 +129,7 @@ module Minitest
|
|
95
129
|
end
|
96
130
|
end
|
97
131
|
|
132
|
+
# Patches Minitest to track tags
|
98
133
|
module MinitestPatcher
|
99
134
|
::Minitest::Test.extend(Tagz::BaseMixin)
|
100
135
|
|
@@ -153,14 +188,19 @@ module Minitest
|
|
153
188
|
end
|
154
189
|
end
|
155
190
|
|
191
|
+
# Main extensions to Minitest
|
156
192
|
class << self
|
157
|
-
attr_accessor :chosen_tags
|
193
|
+
attr_accessor :chosen_tags, :run_all_if_no_match
|
194
|
+
|
195
|
+
alias :run_all_if_no_match? :run_all_if_no_match
|
158
196
|
|
159
197
|
# Create a master TagSet that you wish to test. You only
|
160
198
|
# want to run tests with tags in this set
|
161
199
|
# @param [Enumerable<Symbol>] tags - a list of tags you want to test
|
162
|
-
|
200
|
+
# @param [Boolean] run_all_if_no_match - will run all tests if no tests are found with the tag
|
201
|
+
def choose_tags(*tags, run_all_if_no_match: false)
|
163
202
|
@chosen_tags = tags.map(&:to_sym)
|
203
|
+
@run_all_if_no_match = run_all_if_no_match
|
164
204
|
end
|
165
205
|
|
166
206
|
def declare_tag_assignment(owner, pending_tags)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-tagz
|
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
|
- Josh Bodah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|