minitag 0.3.0 → 0.4.1
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 +32 -0
- 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 +9 -8
- data/lib/minitag/extension_registry.rb +26 -0
- data/lib/minitag/minitest_tag.rb +23 -0
- data/lib/minitag/tag_extension.rb +1 -17
- data/lib/minitag/tag_registry.rb +8 -7
- 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: 5cfcb59a8e761ef05e4520539a37892c772362685feab9ca2c9d98badbc155ee
|
|
4
|
+
data.tar.gz: e99d1e6784863d642564e69592d08d999218399951dbd346f484d63450358e19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e788f60ca4a42e8220ed07955b2c4f93a41791b4e9425b17f6785b3783e0cb88b002fc75d03baceb73984a65438df1ab041455243a11dfe480b1e6be8dce888
|
|
7
|
+
data.tar.gz: a8720ea668e10aa1c4d1fb58fb2c4fad8661c39e9fe33f8e35a69a57696c482ebf3c236074716764eef004225900e3fc11eb3d37e71dc93f904d98e380114f6f
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: continuous-integration
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
ci:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
steps:
|
|
8
|
+
- uses: actions/checkout@v2
|
|
9
|
+
- name: Set up Ruby 2.7
|
|
10
|
+
uses: actions/setup-ruby@v1
|
|
11
|
+
with:
|
|
12
|
+
ruby-version: "2.7"
|
|
13
|
+
- name: Cache gems
|
|
14
|
+
uses: actions/cache@v2
|
|
15
|
+
with:
|
|
16
|
+
path: vendor/bundle
|
|
17
|
+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
|
18
|
+
restore-keys: |
|
|
19
|
+
${{ runner.os }}-gem-
|
|
20
|
+
- name: Install gems
|
|
21
|
+
run: |
|
|
22
|
+
sed -i '/ruby ".*"/,+1 d' Gemfile
|
|
23
|
+
bundle_version=`awk '/BUNDLED WITH/{getline; gsub(/ /, "", $0); print}' Gemfile.lock`
|
|
24
|
+
gem install bundler --no-document -v ${bundle_version}
|
|
25
|
+
bundle config retry "3"
|
|
26
|
+
bundle config jobs "$(nproc)"
|
|
27
|
+
bundle config path vendor/bundle
|
|
28
|
+
bundle install
|
|
29
|
+
- name: Run RuboCop
|
|
30
|
+
run: bundle exec rubocop --parallel
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: bundle exec rake test
|
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
|
|
@@ -24,7 +23,7 @@ module Minitag
|
|
|
24
23
|
end
|
|
25
24
|
|
|
26
25
|
# Adds a filter tag.
|
|
27
|
-
# Tags with a ~ prefix are exclusive filters
|
|
26
|
+
# Tags with a ~ prefix are treated as exclusive filters or inclusive filters otherwise.
|
|
28
27
|
#
|
|
29
28
|
# param [String] name the name of the filter tag.
|
|
30
29
|
#
|
|
@@ -34,7 +33,7 @@ module Minitag
|
|
|
34
33
|
# @return [void]
|
|
35
34
|
def add_filter(tag)
|
|
36
35
|
if tag.start_with?('~')
|
|
37
|
-
@exclusive_filters << tag[1
|
|
36
|
+
@exclusive_filters << tag[1..]
|
|
38
37
|
else
|
|
39
38
|
@inclusive_filters << tag
|
|
40
39
|
end
|
|
@@ -42,13 +41,15 @@ module Minitag
|
|
|
42
41
|
|
|
43
42
|
# Indicates when a context has no filters.
|
|
44
43
|
#
|
|
45
|
-
# @return [
|
|
44
|
+
# @return [Boolean] whether a context has no filters.
|
|
46
45
|
def no_filters?
|
|
47
46
|
@inclusive_filters.empty? && @exclusive_filters.empty?
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
# Detects whether the name associated with a namespace contains tags
|
|
51
|
-
# that matches the filtering criteria.
|
|
50
|
+
# that matches the filtering criteria. For more information check the methods:
|
|
51
|
+
# - match_inclusive_filters?
|
|
52
|
+
# - match_exclusive_filters?
|
|
52
53
|
#
|
|
53
54
|
# @param [String] namespace the namespace which a test name belongs.
|
|
54
55
|
# @param [String] name the test name.
|
|
@@ -56,7 +57,7 @@ module Minitag
|
|
|
56
57
|
# Invariants:
|
|
57
58
|
# - Returns true when no filters are present.
|
|
58
59
|
#
|
|
59
|
-
# return [
|
|
60
|
+
# @return [Boolean] whether there was a match or not.
|
|
60
61
|
def match?(namespace:, name:)
|
|
61
62
|
return true if no_filters?
|
|
62
63
|
|
|
@@ -75,7 +76,7 @@ module Minitag
|
|
|
75
76
|
# - Returns false when inclusive filters are specified but there
|
|
76
77
|
# are no tags.
|
|
77
78
|
#
|
|
78
|
-
# return [
|
|
79
|
+
# @return [Boolean] whether there was a match or not.
|
|
79
80
|
def match_inclusive_filters?(tags)
|
|
80
81
|
return true if @inclusive_filters.empty?
|
|
81
82
|
return false if @inclusive_filters.any? && tags.empty?
|
|
@@ -92,7 +93,7 @@ module Minitag
|
|
|
92
93
|
# - Returns true when exclusive filters are specified and there
|
|
93
94
|
# are no tags.
|
|
94
95
|
#
|
|
95
|
-
# return [
|
|
96
|
+
# return [Boolean] whether there was a match or not.
|
|
96
97
|
def match_exclusive_filters?(tags)
|
|
97
98
|
return true if @exclusive_filters.empty?
|
|
98
99
|
return true if @exclusive_filters.any? && tags.empty?
|
|
@@ -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,23 @@
|
|
|
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 the next test definition and extends the
|
|
7
|
+
# class from which the tag method is being used with Minitag::TagExtension.
|
|
8
|
+
#
|
|
9
|
+
# It is important to notice that tags associated with a test have no concept
|
|
10
|
+
# of being inclusive or exclusive. This distinction is only valid for tag
|
|
11
|
+
# filters.
|
|
12
|
+
#
|
|
13
|
+
# @param [Array] tags the list of tags to be associated with a test case.
|
|
14
|
+
#
|
|
15
|
+
# @return [void]
|
|
16
|
+
def tag(*tags)
|
|
17
|
+
Minitag.pending_tags = tags.map { |tag| tag.to_s.strip.downcase }
|
|
18
|
+
Minitag.register_for_extension(self)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Minitest::Test.singleton_class.prepend(Minitag::MinitestTag)
|
|
@@ -1,25 +1,11 @@
|
|
|
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 inclusive or exclusive tags. 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
11
|
Minitag.context.add_tags(
|
|
@@ -40,5 +26,3 @@ module Minitag
|
|
|
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,9 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'set'
|
|
4
|
-
|
|
5
3
|
module Minitag
|
|
6
|
-
# Stores tags associated with a
|
|
4
|
+
# Stores tags associated with a test name, which belongs to a namespace.
|
|
5
|
+
# The namespace is usually the class which the test belongs to.
|
|
7
6
|
class TagRegistry
|
|
8
7
|
def initialize
|
|
9
8
|
@repository = Hash.new { |h, k| h[k] = Set.new }
|
|
@@ -11,9 +10,11 @@ module Minitag
|
|
|
11
10
|
|
|
12
11
|
# Associates tags with a name taking into account its namespace.
|
|
13
12
|
#
|
|
14
|
-
#
|
|
13
|
+
# Duplicated tags will be removed during this operation.
|
|
14
|
+
#
|
|
15
|
+
# @param [String] namespace the context which a test name belongs.
|
|
15
16
|
# @param [String] name the test name.
|
|
16
|
-
# @param [Array] tags the collection of tags.
|
|
17
|
+
# @param [Array] tags the collection of tags associated with a test.
|
|
17
18
|
#
|
|
18
19
|
# @return [void]
|
|
19
20
|
def add(namespace:, name:, tags:)
|
|
@@ -22,10 +23,10 @@ module Minitag
|
|
|
22
23
|
|
|
23
24
|
# Fetches tags associated with a test name and namespace.
|
|
24
25
|
#
|
|
25
|
-
# @param [String] namespace the
|
|
26
|
+
# @param [String] namespace the context which a test name belongs.
|
|
26
27
|
# @param [String] name the test name.
|
|
27
28
|
#
|
|
28
|
-
# @return [Set] the tags associated with the specified namespace and name.
|
|
29
|
+
# @return [Set] the tags associated with the specified namespace and test name.
|
|
29
30
|
def fetch(namespace:, name:)
|
|
30
31
|
@repository[key(namespace, name)]
|
|
31
32
|
end
|
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.4.1
|
|
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-15 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
|