minitag 0.3.1 → 0.5.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/.github/workflows/ci.yml +36 -0
- data/.rubocop.yml +2 -7
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -1
- data/README.md +2 -4
- data/lib/minitag.rb +13 -0
- data/lib/minitag/context.rb +17 -5
- data/lib/minitag/extension_registry.rb +26 -0
- data/lib/minitag/minitest_tag.rb +43 -0
- data/lib/minitag/tag_extension.rb +4 -20
- data/lib/minitag/tag_registry.rb +21 -8
- data/lib/minitag/version.rb +1 -1
- metadata +5 -3
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d440fb67a5cd62d5c4b65d12abd2168a7962171348ecdf55b401bc87815d407b
|
|
4
|
+
data.tar.gz: 0e0aa4b1f27d85fff9fd79242d28a8e48b23f0e5c76cb982b41aae570fa17b79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffc87f80426c64eacc5a9171f5bec559c04fc2e6ebb9c0530fd22b9d84cca03f4d27a6fc637c0ce030b6256793180d6c2276e4cb566a85ecad895078a119d99f
|
|
7
|
+
data.tar.gz: b636027dfe4dbb4bfcff9d9d5ae6c3614fc1fcf1635779e9911a485ceed81211bc21d5175bde1a8e2cdd2bf037f74e961ba630e9effb42b10cc083d1f6f44eaa
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: continuous-integration
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
ci:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v2
|
|
13
|
+
- name: Set up Ruby 2.7
|
|
14
|
+
uses: actions/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: "2.7"
|
|
17
|
+
- name: Cache gems
|
|
18
|
+
uses: actions/cache@v2
|
|
19
|
+
with:
|
|
20
|
+
path: vendor/bundle
|
|
21
|
+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
|
22
|
+
restore-keys: |
|
|
23
|
+
${{ runner.os }}-gem-
|
|
24
|
+
- name: Install gems
|
|
25
|
+
run: |
|
|
26
|
+
sed -i '/ruby ".*"/,+1 d' Gemfile
|
|
27
|
+
bundle_version=`awk '/BUNDLED WITH/{getline; gsub(/ /, "", $0); print}' Gemfile.lock`
|
|
28
|
+
gem install bundler --no-document -v ${bundle_version}
|
|
29
|
+
bundle config retry "3"
|
|
30
|
+
bundle config jobs "$(nproc)"
|
|
31
|
+
bundle config path vendor/bundle
|
|
32
|
+
bundle install
|
|
33
|
+
- name: Run RuboCop
|
|
34
|
+
run: bundle exec rubocop --parallel
|
|
35
|
+
- name: Run tests
|
|
36
|
+
run: bundle exec rake test
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
[](https://badge.fury.io/rb/minitag)
|
|
1
|
+
[](https://badge.fury.io/rb/minitag) [](https://github.com/bernardoamc/minitag/actions?query=workflow%3Acontinuous-integration)
|
|
2
2
|
|
|
3
3
|
# Minitag
|
|
4
4
|
|
|
5
|
-
[](https://travis-ci.org/bernardoamc/minitag)
|
|
6
|
-
|
|
7
5
|
A simple gem that allow developers to tag their minitest tests and run tests
|
|
8
6
|
based on these tags.
|
|
9
7
|
|
|
@@ -38,7 +36,7 @@ It is important to point out that tags associated with a test have no concept of
|
|
|
38
36
|
```rb
|
|
39
37
|
class MyTest < Minitest::Test
|
|
40
38
|
tag 'my_tag', 'another_tag'
|
|
41
|
-
|
|
39
|
+
def test_hello_minitest
|
|
42
40
|
# ...
|
|
43
41
|
end
|
|
44
42
|
end
|
data/lib/minitag.rb
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'set'
|
|
3
4
|
require 'minitest'
|
|
4
5
|
require 'minitag/version'
|
|
5
6
|
require 'minitag/context'
|
|
7
|
+
require 'minitag/extension_registry'
|
|
8
|
+
require 'minitag/minitest_tag'
|
|
6
9
|
require 'minitag/tag_extension'
|
|
7
10
|
|
|
8
11
|
# Namespace for classes or modules providing tagging functionality
|
|
9
12
|
# to Minitest::Test
|
|
10
13
|
module Minitag
|
|
11
14
|
class << self
|
|
15
|
+
# Registry of classes that requires extension by Minitag::TagExtension.
|
|
16
|
+
def extension_registry
|
|
17
|
+
@extension_registry ||= ExtensionRegistry.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Register a class for extension.
|
|
21
|
+
def register_for_extension(klass)
|
|
22
|
+
extension_registry.register(klass)
|
|
23
|
+
end
|
|
24
|
+
|
|
12
25
|
# Execution context of the test suite.
|
|
13
26
|
def context
|
|
14
27
|
@context ||= Context.new
|
data/lib/minitag/context.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'set'
|
|
4
3
|
require_relative './tag_registry'
|
|
5
4
|
|
|
6
5
|
module Minitag
|
|
@@ -19,12 +18,25 @@ module Minitag
|
|
|
19
18
|
# @param [Array] tags the collection of tags.
|
|
20
19
|
#
|
|
21
20
|
# @return [void]
|
|
22
|
-
def
|
|
21
|
+
def add_test_tags(namespace:, name:, tags:)
|
|
23
22
|
@tag_registry.add(namespace: namespace, name: name, tags: tags)
|
|
24
23
|
end
|
|
25
24
|
|
|
25
|
+
# Add tags to an entire namespace. Every test within the namespace will
|
|
26
|
+
# share these tags.
|
|
27
|
+
#
|
|
28
|
+
# @param [String] namespace the namespace that contain tests.
|
|
29
|
+
# @param [Array] tags the collection of tags.
|
|
30
|
+
#
|
|
31
|
+
# @return [void]
|
|
32
|
+
def add_namespace_tags(namespace:, tags:)
|
|
33
|
+
@tag_registry.add_for_namespace(namespace: namespace, tags: tags)
|
|
34
|
+
end
|
|
35
|
+
|
|
26
36
|
# Adds a filter tag.
|
|
27
|
-
#
|
|
37
|
+
#
|
|
38
|
+
# Tags with a ~ prefix are treated as exclusive filters or inclusive filters
|
|
39
|
+
# otherwise.
|
|
28
40
|
#
|
|
29
41
|
# param [String] name the name of the filter tag.
|
|
30
42
|
#
|
|
@@ -34,7 +46,7 @@ module Minitag
|
|
|
34
46
|
# @return [void]
|
|
35
47
|
def add_filter(tag)
|
|
36
48
|
if tag.start_with?('~')
|
|
37
|
-
@exclusive_filters << tag[1
|
|
49
|
+
@exclusive_filters << tag[1..]
|
|
38
50
|
else
|
|
39
51
|
@inclusive_filters << tag
|
|
40
52
|
end
|
|
@@ -62,7 +74,7 @@ module Minitag
|
|
|
62
74
|
def match?(namespace:, name:)
|
|
63
75
|
return true if no_filters?
|
|
64
76
|
|
|
65
|
-
tags = @tag_registry.
|
|
77
|
+
tags = @tag_registry.get(namespace: namespace, name: name)
|
|
66
78
|
match_inclusive_filters?(tags) && match_exclusive_filters?(tags)
|
|
67
79
|
end
|
|
68
80
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Minitag
|
|
4
|
+
# Stores and extends classes that relies on tags with the Minitag::TagExtension
|
|
5
|
+
# module.
|
|
6
|
+
class ExtensionRegistry
|
|
7
|
+
def initialize
|
|
8
|
+
@registry = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Extends a class with Minitag::TagExtension and stores it as extended.
|
|
12
|
+
#
|
|
13
|
+
# Invariants:
|
|
14
|
+
# - Classes that were already extended will be ignored during this operation.
|
|
15
|
+
#
|
|
16
|
+
# @param [Class] klass a class that will be extended.
|
|
17
|
+
#
|
|
18
|
+
# @return [void]
|
|
19
|
+
def register(klass)
|
|
20
|
+
return if @registry.key?(klass)
|
|
21
|
+
|
|
22
|
+
@registry[klass] = true
|
|
23
|
+
klass.singleton_class.prepend(Minitag::TagExtension)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Minitag
|
|
4
|
+
# Module used to extend Minitest::Test with the tag method.
|
|
5
|
+
module MinitestTag
|
|
6
|
+
# Add tags to be associated with an entire class that inherits from
|
|
7
|
+
# Minitest::Test. Every test that belongs to this class will also inherit
|
|
8
|
+
# these tags.
|
|
9
|
+
#
|
|
10
|
+
# It is important to notice that tags associated with a class have no
|
|
11
|
+
# concept of being inclusive or exclusive. This distinction is only
|
|
12
|
+
# valid for tag filters.
|
|
13
|
+
#
|
|
14
|
+
# @param [Array] tags the list of tags to be associated with a test class.
|
|
15
|
+
#
|
|
16
|
+
# @return [void]
|
|
17
|
+
def tag_namespace(*tags)
|
|
18
|
+
Minitag.context.add_namespace_tags(
|
|
19
|
+
namespace: to_s,
|
|
20
|
+
tags: tags.map { |tag| tag.to_s.strip.downcase }
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
Minitag.register_for_extension(self)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Add tags to be associated with the next test definition and extends the
|
|
27
|
+
# class from which the tag method is being used with Minitag::TagExtension.
|
|
28
|
+
#
|
|
29
|
+
# It is important to notice that tags associated with a test have no concept
|
|
30
|
+
# of being inclusive or exclusive. This distinction is only valid for tag
|
|
31
|
+
# filters.
|
|
32
|
+
#
|
|
33
|
+
# @param [Array] tags the list of tags to be associated with a test case.
|
|
34
|
+
#
|
|
35
|
+
# @return [void]
|
|
36
|
+
def tag(*tags)
|
|
37
|
+
Minitag.pending_tags = tags.map { |tag| tag.to_s.strip.downcase }
|
|
38
|
+
Minitag.register_for_extension(self)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Minitest::Test.singleton_class.prepend(Minitag::MinitestTag)
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Minitag
|
|
4
|
-
# Module used to extend
|
|
4
|
+
# Module used to extend classes that rely on tags.
|
|
5
5
|
# It has the following responsibilities:
|
|
6
|
-
# - Introduce the tag functionality
|
|
7
6
|
# - Associate tags with tests
|
|
8
7
|
# - Filter tests based on the specified tags
|
|
9
8
|
module TagExtension
|
|
10
|
-
# Add tags to be associated with the next test definition.
|
|
11
|
-
#
|
|
12
|
-
# It is important to notice that tags associated with a test have no concept
|
|
13
|
-
# of being inclusive or exclusive. This distinction is only valid for tag
|
|
14
|
-
# filters.
|
|
15
|
-
#
|
|
16
|
-
# @param [Array] tags the list of tags to be associated with a test case.
|
|
17
|
-
#
|
|
18
|
-
# @return [void]
|
|
19
|
-
def tag(*tags)
|
|
20
|
-
Minitag.pending_tags = tags.map { |tag| tag.to_s.strip.downcase }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
9
|
define_method(:method_added) do |name|
|
|
24
10
|
if name[/\Atest_/]
|
|
25
|
-
Minitag.context.
|
|
26
|
-
namespace:
|
|
11
|
+
Minitag.context.add_test_tags(
|
|
12
|
+
namespace: to_s, name: name, tags: Minitag.pending_tags
|
|
27
13
|
)
|
|
28
14
|
|
|
29
15
|
Minitag.pending_tags = []
|
|
@@ -35,10 +21,8 @@ module Minitag
|
|
|
35
21
|
return methods if Minitag.context.no_filters?
|
|
36
22
|
|
|
37
23
|
methods.select do |runnable_method|
|
|
38
|
-
Minitag.context.match?(namespace:
|
|
24
|
+
Minitag.context.match?(namespace: to_s, name: runnable_method)
|
|
39
25
|
end
|
|
40
26
|
end
|
|
41
27
|
end
|
|
42
28
|
end
|
|
43
|
-
|
|
44
|
-
Minitest::Test.singleton_class.prepend(Minitag::TagExtension)
|
data/lib/minitag/tag_registry.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'set'
|
|
4
|
-
|
|
5
3
|
module Minitag
|
|
6
|
-
# Stores tags associated with a
|
|
7
|
-
#
|
|
4
|
+
# Stores tags associated with a namespace or a single test case.
|
|
5
|
+
#
|
|
6
|
+
# A namespace is usually the class which tests belongs to.
|
|
8
7
|
class TagRegistry
|
|
9
8
|
def initialize
|
|
10
|
-
@
|
|
9
|
+
@registry = {}
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
# Associates tags with a name taking into account its namespace.
|
|
@@ -20,7 +19,19 @@ module Minitag
|
|
|
20
19
|
#
|
|
21
20
|
# @return [void]
|
|
22
21
|
def add(namespace:, name:, tags:)
|
|
23
|
-
@
|
|
22
|
+
@registry[key(namespace, name)] = Set.new(tags)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Associates tags with a namespace.
|
|
26
|
+
#
|
|
27
|
+
# Duplicated tags will be removed during this operation.
|
|
28
|
+
#
|
|
29
|
+
# @param [String] namespace the context which a test name belongs.
|
|
30
|
+
# @param [Array] tags the collection of tags associated with a test.
|
|
31
|
+
#
|
|
32
|
+
# @return [void]
|
|
33
|
+
def add_for_namespace(namespace:, tags:)
|
|
34
|
+
@registry[namespace] = Set.new(tags)
|
|
24
35
|
end
|
|
25
36
|
|
|
26
37
|
# Fetches tags associated with a test name and namespace.
|
|
@@ -29,8 +40,10 @@ module Minitag
|
|
|
29
40
|
# @param [String] name the test name.
|
|
30
41
|
#
|
|
31
42
|
# @return [Set] the tags associated with the specified namespace and test name.
|
|
32
|
-
def
|
|
33
|
-
@
|
|
43
|
+
def get(namespace:, name:)
|
|
44
|
+
@registry.fetch(namespace, Set.new).union(
|
|
45
|
+
@registry.fetch(key(namespace, name), Set.new)
|
|
46
|
+
)
|
|
34
47
|
end
|
|
35
48
|
|
|
36
49
|
private
|
data/lib/minitag/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minitag
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bernardo de Araujo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-07-
|
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -73,9 +73,9 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
+
- ".github/workflows/ci.yml"
|
|
76
77
|
- ".gitignore"
|
|
77
78
|
- ".rubocop.yml"
|
|
78
|
-
- ".travis.yml"
|
|
79
79
|
- CODE_OF_CONDUCT.md
|
|
80
80
|
- Gemfile
|
|
81
81
|
- Gemfile.lock
|
|
@@ -86,6 +86,8 @@ files:
|
|
|
86
86
|
- bin/setup
|
|
87
87
|
- lib/minitag.rb
|
|
88
88
|
- lib/minitag/context.rb
|
|
89
|
+
- lib/minitag/extension_registry.rb
|
|
90
|
+
- lib/minitag/minitest_tag.rb
|
|
89
91
|
- lib/minitag/tag_extension.rb
|
|
90
92
|
- lib/minitag/tag_registry.rb
|
|
91
93
|
- lib/minitag/version.rb
|