Module: Minitag::MinitestTag

Defined in:
lib/minitag/minitest_tag.rb

Overview

Module used to extend Minitest::Test with the tag method.

Instance Method Summary collapse

Instance Method Details

#run_one_method(klass, method_name, reporter) ⇒ Object

rubocop:disable Metrics/AbcSize



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/minitag/minitest_tag.rb', line 39

def run_one_method(klass, method_name, reporter) # rubocop:disable Metrics/AbcSize
  return super if !Minitag.skip_filtered? || Minitag.context.no_filters? ||
                  Minitag.context.match?(namespace: to_s, name: method_name)

  # Skip this test
  test = klass.new(method_name)
  test.time = 0
  skip = Minitest::Skip.new('This test did not match filters')
  source = test.method(method_name).source_location
  skip.set_backtrace(["#{source[0]}:#{source[1]}"])
  test.failures << skip
  reporter.prerecord(self, method_name)
  reporter.record(Minitest::Result.from(test))
end

#runnable_methodsArray

Decides which methods to run based on an Array of test names provided by the superclass and the tags defined within test classes.

Invariants:

- Returns the full list of test names when the test suite runs without
any tag filtering.

Returns:

  • (Array)

    the list of test names that should run.



62
63
64
65
66
67
68
69
# File 'lib/minitag/minitest_tag.rb', line 62

def runnable_methods
  methods = super.dup
  return methods if Minitag.skip_filtered? || Minitag.context.no_filters?

  methods.select do |runnable_method|
    Minitag.context.match?(namespace: to_s, name: runnable_method)
  end
end

#tag(*tags) ⇒ void

This method returns an undefined value.

Add tags to be associated with the next test definition and extends the class from which the tag method is being used with Minitag::TagExtension.

It is important to notice that tags associated with a test have no concept of being inclusive or exclusive. This distinction is only valid for tag filters.

Parameters:

  • tags (Array)

    the list of tags to be associated with a test case.



34
35
36
37
# File 'lib/minitag/minitest_tag.rb', line 34

def tag(*tags)
  Minitag.pending_tags = tags.map { |tag| tag.to_s.strip.downcase }
  Minitag.register_for_extension(self)
end

#tag_namespace(*tags) ⇒ void

This method returns an undefined value.

Add tags to be associated with an entire class that inherits from Minitest::Test. Every test that belongs to this class will also inherit these tags.

It is important to notice that tags associated with a class have no concept of being inclusive or exclusive. This distinction is only valid for tag filters.

Parameters:

  • tags (Array)

    the list of tags to be associated with a test class.



17
18
19
20
21
22
# File 'lib/minitag/minitest_tag.rb', line 17

def tag_namespace(*tags)
  Minitag.context.add_namespace_tags(
    namespace: to_s,
    tags: tags.map { |tag| tag.to_s.strip.downcase }
  )
end