minitag 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cfcb59a8e761ef05e4520539a37892c772362685feab9ca2c9d98badbc155ee
4
- data.tar.gz: e99d1e6784863d642564e69592d08d999218399951dbd346f484d63450358e19
3
+ metadata.gz: d440fb67a5cd62d5c4b65d12abd2168a7962171348ecdf55b401bc87815d407b
4
+ data.tar.gz: 0e0aa4b1f27d85fff9fd79242d28a8e48b23f0e5c76cb982b41aae570fa17b79
5
5
  SHA512:
6
- metadata.gz: 9e788f60ca4a42e8220ed07955b2c4f93a41791b4e9425b17f6785b3783e0cb88b002fc75d03baceb73984a65438df1ab041455243a11dfe480b1e6be8dce888
7
- data.tar.gz: a8720ea668e10aa1c4d1fb58fb2c4fad8661c39e9fe33f8e35a69a57696c482ebf3c236074716764eef004225900e3fc11eb3d37e71dc93f904d98e380114f6f
6
+ metadata.gz: ffc87f80426c64eacc5a9171f5bec559c04fc2e6ebb9c0530fd22b9d84cca03f4d27a6fc637c0ce030b6256793180d6c2276e4cb566a85ecad895078a119d99f
7
+ data.tar.gz: b636027dfe4dbb4bfcff9d9d5ae6c3614fc1fcf1635779e9911a485ceed81211bc21d5175bde1a8e2cdd2bf037f74e961ba630e9effb42b10cc083d1f6f44eaa
@@ -1,5 +1,9 @@
1
1
  name: continuous-integration
2
- on: push
2
+ on:
3
+ push:
4
+ pull_request:
5
+ branches:
6
+ - master
3
7
 
4
8
  jobs:
5
9
  ci:
@@ -1,13 +1,8 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
 
4
- Metrics/AbcSize:
5
- Enabled: false
6
-
7
- Metrics/CyclomaticComplexity:
8
- Enabled: false
9
-
10
4
  Layout/LineLength:
11
5
  Max: 120
12
6
 
13
-
7
+ Metrics/ClassLength:
8
+ Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minitag (0.4.1)
4
+ minitag (0.5.0)
5
5
  minitest (~> 5.0)
6
6
 
7
7
  GEM
@@ -18,12 +18,25 @@ module Minitag
18
18
  # @param [Array] tags the collection of tags.
19
19
  #
20
20
  # @return [void]
21
- def add_tags(namespace:, name:, tags:)
21
+ def add_test_tags(namespace:, name:, tags:)
22
22
  @tag_registry.add(namespace: namespace, name: name, tags: tags)
23
23
  end
24
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
+
25
36
  # Adds a filter tag.
26
- # Tags with a ~ prefix are treated as exclusive filters or inclusive filters otherwise.
37
+ #
38
+ # Tags with a ~ prefix are treated as exclusive filters or inclusive filters
39
+ # otherwise.
27
40
  #
28
41
  # param [String] name the name of the filter tag.
29
42
  #
@@ -61,7 +74,7 @@ module Minitag
61
74
  def match?(namespace:, name:)
62
75
  return true if no_filters?
63
76
 
64
- tags = @tag_registry.fetch(namespace: namespace, name: name)
77
+ tags = @tag_registry.get(namespace: namespace, name: name)
65
78
  match_inclusive_filters?(tags) && match_exclusive_filters?(tags)
66
79
  end
67
80
 
@@ -3,6 +3,26 @@
3
3
  module Minitag
4
4
  # Module used to extend Minitest::Test with the tag method.
5
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
+
6
26
  # Add tags to be associated with the next test definition and extends the
7
27
  # class from which the tag method is being used with Minitag::TagExtension.
8
28
  #
@@ -8,8 +8,8 @@ module Minitag
8
8
  module TagExtension
9
9
  define_method(:method_added) do |name|
10
10
  if name[/\Atest_/]
11
- Minitag.context.add_tags(
12
- namespace: self, name: name, tags: Minitag.pending_tags
11
+ Minitag.context.add_test_tags(
12
+ namespace: to_s, name: name, tags: Minitag.pending_tags
13
13
  )
14
14
 
15
15
  Minitag.pending_tags = []
@@ -21,7 +21,7 @@ module Minitag
21
21
  return methods if Minitag.context.no_filters?
22
22
 
23
23
  methods.select do |runnable_method|
24
- Minitag.context.match?(namespace: self, name: runnable_method)
24
+ Minitag.context.match?(namespace: to_s, name: runnable_method)
25
25
  end
26
26
  end
27
27
  end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minitag
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.
4
+ # Stores tags associated with a namespace or a single test case.
5
+ #
6
+ # A namespace is usually the class which tests belongs to.
6
7
  class TagRegistry
7
8
  def initialize
8
- @repository = Hash.new { |h, k| h[k] = Set.new }
9
+ @registry = {}
9
10
  end
10
11
 
11
12
  # Associates tags with a name taking into account its namespace.
@@ -18,7 +19,19 @@ module Minitag
18
19
  #
19
20
  # @return [void]
20
21
  def add(namespace:, name:, tags:)
21
- @repository[key(namespace, name)] = Set.new(tags)
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)
22
35
  end
23
36
 
24
37
  # Fetches tags associated with a test name and namespace.
@@ -27,8 +40,10 @@ module Minitag
27
40
  # @param [String] name the test name.
28
41
  #
29
42
  # @return [Set] the tags associated with the specified namespace and test name.
30
- def fetch(namespace:, name:)
31
- @repository[key(namespace, name)]
43
+ def get(namespace:, name:)
44
+ @registry.fetch(namespace, Set.new).union(
45
+ @registry.fetch(key(namespace, name), Set.new)
46
+ )
32
47
  end
33
48
 
34
49
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minitag
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
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.1
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-15 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler