Class: Minitag::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/minitag/context.rb

Overview

Represents the execution context of the test suite.

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



8
9
10
11
12
# File 'lib/minitag/context.rb', line 8

def initialize
  @inclusive_filters = Set.new
  @exclusive_filters = Set.new
  @tag_registry = Minitag::TagRegistry.new
end

Instance Method Details

#add_filter(tag) ⇒ void

This method returns an undefined value.

Adds a filter tag.

Tags with a ~ prefix are treated as exclusive filters or inclusive filters otherwise.

param [String] name the name of the filter tag.

Invariants:

- A filter will always be a String without the ~ prefix.


47
48
49
50
51
52
53
# File 'lib/minitag/context.rb', line 47

def add_filter(tag)
  if tag.start_with?('~')
    @exclusive_filters << tag[1..tag.length - 1]
  else
    @inclusive_filters << tag
  end
end

#add_namespace_tags(namespace:, tags:) ⇒ void

This method returns an undefined value.

Add tags to an entire namespace. Every test within the namespace will share these tags.

Parameters:

  • namespace (String)

    the namespace that contain tests.

  • tags (Array)

    the collection of tags.



32
33
34
# File 'lib/minitag/context.rb', line 32

def add_namespace_tags(namespace:, tags:)
  @tag_registry.add_for_namespace(namespace: namespace, tags: tags)
end

#add_test_tags(namespace:, name:, tags:) ⇒ void

This method returns an undefined value.

Associates tags with a name taking into account its namespace.

Parameters:

  • namespace (String)

    the namespace which a name belongs.

  • name (String)

    the test name.

  • tags (Array)

    the collection of tags.



21
22
23
# File 'lib/minitag/context.rb', line 21

def add_test_tags(namespace:, name:, tags:)
  @tag_registry.add(namespace: namespace, name: name, tags: tags)
end

#match?(namespace:, name:) ⇒ Boolean

Detects whether the name associated with a namespace contains tags that matches the filtering criteria. For more information check the methods:

- match_inclusive_filters?
- match_exclusive_filters?

Invariants:

- Returns true when no filters are present.

Parameters:

  • namespace (String)

    the namespace which a test name belongs.

  • name (String)

    the test name.

Returns:

  • (Boolean)

    whether there was a match or not.



74
75
76
77
78
79
# File 'lib/minitag/context.rb', line 74

def match?(namespace:, name:)
  return true if no_filters?

  tags = @tag_registry.get(namespace: namespace, name: name)
  match_inclusive_filters?(tags) && match_exclusive_filters?(tags)
end

#no_filters?Boolean

Indicates when a context has no filters.

Returns:

  • (Boolean)

    whether a context has no filters.



58
59
60
# File 'lib/minitag/context.rb', line 58

def no_filters?
  @inclusive_filters.empty? && @exclusive_filters.empty?
end