minitag 0.3.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab98e9f2debb23b27f21435a3b2ac0102a835391accb97fd7e1bae69457f4e07
4
- data.tar.gz: 538c9bc1789dd2080b3a8f8430c116d05693eb5c2dfee3f1204fe60c67e5e80a
3
+ metadata.gz: edc15f86cd75fafe193dda4ce0c3ec53195a3c831b3b364c1268468cec1fa58b
4
+ data.tar.gz: a7cba97a2c8f4cde4263f7d4e880510a6f14a6606649eb3920bfe0a569ef9805
5
5
  SHA512:
6
- metadata.gz: '081ad2c7553abb897271b01e30d0561255ca5ee30128aac47f4dbee4ac29fd7a0de0e1954268c9325f9476823f6ffc16321b429fc9d98b0edc3fc20e10433ca6'
7
- data.tar.gz: 372cd5e85be6c5f7c35faf779e2ab197ac8a4d218dd11b13c43c2b5be2449aa7c14d4898208cc93c5410a24b2ec4e6290171c1d67dca332d8f9325706cb2eace
6
+ metadata.gz: 4e2aa1f83f281212d0417747906b9ec9cc0e7e97f9aa7d0d38eac636d1d8d0f98c555cace09b410ee2655c060e4008fa5eaafae7225f4a674f26e1bb9a19810c
7
+ data.tar.gz: 31b67943091e116adf9ec47a751075b8d1e5fac32480a04bbbd406bcaa732252d31fb274cfd5645f6a2cf8ded9318817dce1537eaf707572aa090e9b3a438421
@@ -1,22 +1,26 @@
1
1
  name: continuous-integration
2
- on: push
2
+ on: [push, pull_request]
3
3
 
4
4
  jobs:
5
5
  ci:
6
6
  runs-on: ubuntu-latest
7
+ strategy:
8
+ matrix:
9
+ ruby: [ '2.6', '2.7' ]
10
+ name: Ruby ${{ matrix.ruby }}
7
11
  steps:
8
12
  - uses: actions/checkout@v2
9
- - name: Set up Ruby 2.7
13
+ - name: Set up Ruby ${{ matrix.ruby }}
10
14
  uses: actions/setup-ruby@v1
11
15
  with:
12
- ruby-version: "2.7"
16
+ ruby-version: ${{ matrix.ruby }}
13
17
  - name: Cache gems
14
18
  uses: actions/cache@v2
15
19
  with:
16
20
  path: vendor/bundle
17
- key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
21
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
18
22
  restore-keys: |
19
- ${{ runner.os }}-gem-
23
+ ${{ runner.os }}-${{ matrix.ruby }}-gem-
20
24
  - name: Install gems
21
25
  run: |
22
26
  sed -i '/ruby ".*"/,+1 d' Gemfile
data/.rubocop.yml CHANGED
@@ -1,13 +1,12 @@
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
 
7
+ Metrics/ClassLength:
8
+ Enabled: false
13
9
 
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'test/**/*_test.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minitag (0.3.3)
4
+ minitag (0.6.1)
5
5
  minitest (~> 5.0)
6
6
 
7
7
  GEM
@@ -15,7 +15,7 @@ GEM
15
15
  rainbow (3.0.0)
16
16
  rake (13.0.1)
17
17
  regexp_parser (1.7.1)
18
- rexml (3.2.4)
18
+ rexml (3.2.5)
19
19
  rubocop (0.87.1)
20
20
  parallel (~> 1.10)
21
21
  parser (>= 2.7.1.1)
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- [![Gem Version](https://badge.fury.io/rb/minitag.svg)](https://badge.fury.io/rb/minitag)
1
+ [![Gem Version](https://badge.fury.io/rb/minitag.svg)](https://badge.fury.io/rb/minitag) [![](https://github.com/bernardoamc/minitag/workflows/continuous-integration/badge.svg)](https://github.com/bernardoamc/minitag/actions?query=workflow%3Acontinuous-integration)
2
2
 
3
3
  # Minitag
4
4
 
5
- A simple gem that allow developers to tag their minitest tests and run tests
6
- based on these tags.
5
+ A simple gem that allow developers using minitest to specify tags for their classes and tests, and run their test suite based on these tags.
6
+
7
+ This gem should be framework agnostic, let me know if you encounter any problems
8
+ running this within the framework of your choice.
7
9
 
8
10
  ## Installation
9
11
 
@@ -21,20 +23,18 @@ $ gem install minitag
21
23
 
22
24
  ## Usage
23
25
 
24
- ### Setup
25
-
26
- Require `minitag` in our `test_helper.rb`:
27
-
28
- `require 'minitag'`
29
-
30
26
  ### Adding tags
31
27
 
32
- We can tag specific tests with one or more tags.
28
+ We can tag specific classes or tests with one or more tags.
33
29
 
34
- It is important to point out that tags associated with a test have no concept of being inclusive or exclusive. This distinction is only valid for [tag filters](#running-tests-with-tag-filters).
30
+ It is important to point out that tags associated with a class or test have no concept of being inclusive or exclusive. This distinction is only valid for [tag filters](#running-tests-with-tag-filters).
35
31
 
36
32
  ```rb
37
33
  class MyTest < Minitest::Test
34
+ # Every test within this class will inherit this tag
35
+ tag_namespace 'my_namespace_tag'
36
+
37
+ # Only the test below will have this tag
38
38
  tag 'my_tag', 'another_tag'
39
39
  def test_hello_minitest
40
40
  # ...
@@ -70,6 +70,24 @@ $ bundle exec rake test --tag '~unit'
70
70
  $ bundle exec rake test --tag 'unit' --tag '~parallel'
71
71
  ```
72
72
 
73
+ ## FAQ
74
+
75
+ ### Is this gem compatible with Rails?
76
+
77
+ Yes. Found any problems? Please open an issue or reach out to me.
78
+
79
+ ### Is this gem compatible with the spec part of minitest?
80
+
81
+ For the most part yes, but tagging `describe` blocks are not supported.
82
+
83
+ ### When should I use this gem?
84
+
85
+ - When there's a need to split a test suite into different CI steps.
86
+ - During development, it's helpful to have extra flexibility when running a big
87
+ test suite.
88
+ - When there are tests that you want to run only occasionality. For example,
89
+ tests that perform network calls or have expensive side effects.
90
+
73
91
  ## Development
74
92
 
75
93
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
@@ -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 add_tags(namespace:, name:, tags:)
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
- # 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.
28
40
  #
29
41
  # param [String] name the name of the filter tag.
30
42
  #
@@ -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.fetch(namespace: namespace, name: name)
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,58 @@
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
+ end
23
+
24
+ # Add tags to be associated with the next test definition and extends the
25
+ # class from which the tag method is being used with Minitag::TagExtension.
26
+ #
27
+ # It is important to notice that tags associated with a test have no concept
28
+ # of being inclusive or exclusive. This distinction is only valid for tag
29
+ # filters.
30
+ #
31
+ # @param [Array] tags the list of tags to be associated with a test case.
32
+ #
33
+ # @return [void]
34
+ def tag(*tags)
35
+ Minitag.pending_tags = tags.map { |tag| tag.to_s.strip.downcase }
36
+ Minitag.register_for_extension(self)
37
+ end
38
+
39
+ # Decides which methods to run based on an Array of test names provided by
40
+ # the superclass and the tags defined within test classes.
41
+ #
42
+ # Invariants:
43
+ # - Returns the full list of test names when the test suite runs without
44
+ # any tag filtering.
45
+ #
46
+ # @return [Array] the list of test names that should run.
47
+ def runnable_methods
48
+ methods = super.dup
49
+ return methods if Minitag.context.no_filters?
50
+
51
+ methods.select do |runnable_method|
52
+ Minitag.context.match?(namespace: to_s, name: runnable_method)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ Minitest::Test.singleton_class.prepend(Minitag::MinitestTag)
@@ -1,44 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minitag
4
- # Module used to extend Minitest::Test.
5
- # It has the following responsibilities:
6
- # - Introduce the tag functionality
7
- # - Associate tags with tests
8
- # - Filter tests based on the specified tags
4
+ # Responsible for listening to added methods and associating tags
5
+ # with those.
9
6
  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
7
  define_method(:method_added) do |name|
24
8
  if name[/\Atest_/]
25
- Minitag.context.add_tags(
26
- namespace: self, name: name, tags: Minitag.pending_tags
9
+ Minitag.context.add_test_tags(
10
+ namespace: to_s, name: name, tags: Minitag.pending_tags
27
11
  )
28
12
 
29
13
  Minitag.pending_tags = []
30
14
  end
31
15
  end
32
-
33
- def runnable_methods
34
- methods = super.dup
35
- return methods if Minitag.context.no_filters?
36
-
37
- methods.select do |runnable_method|
38
- Minitag.context.match?(namespace: self, name: runnable_method)
39
- end
40
- end
41
16
  end
42
17
  end
43
-
44
- Minitest::Test.singleton_class.prepend(Minitag::TagExtension)
@@ -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 test name, which belongs to a namespace.
7
- # 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.
8
7
  class TagRegistry
9
8
  def initialize
10
- @repository = Hash.new { |h, k| h[k] = Set.new }
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
- @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)
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 fetch(namespace:, name:)
33
- @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
+ )
34
47
  end
35
48
 
36
49
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minitag
4
- VERSION = '0.3.3'
4
+ VERSION = '0.6.1'
5
5
  end
@@ -14,7 +14,7 @@ module Minitest
14
14
 
15
15
  def self.plugin_minitag_init(options)
16
16
  Array(options[:tags]).each do |tag|
17
- Minitag.context.add_filter(tag)
17
+ Minitag.add_filter(tag)
18
18
  end
19
19
  end
20
20
  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.3.3
4
+ version: 0.6.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-12 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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