Module: Beaker::DSL::TestTagging

Included in:
Beaker::DSL
Defined in:
lib/beaker/dsl/test_tagging.rb

Overview

Note:

There are a few places where TestTagging-related code is located:

  • Options::Parser#normalize_tags! makes sure the test tags are formatted correctly for use in this module

  • Options::CommandLineParser#initialize parses test tagging options

  • Options::Validator#validate_tags ensures test tag CLI params are valid for use by this module

Test Tagging is about applying meta-data to tests (using the #tag method), so that you can control which tests are executed in a particular beaker run at a more fine-grained level.

Defined Under Namespace

Classes: PlatformTagConfiner

Instance Method Summary collapse

Instance Method Details

#tag(*tags) ⇒ Object

Sets tags on the current TestCase, and skips testing if necessary after checking this case’s tags against the ones that are being included or excluded.

Parameters:

  • tags (Array<String>)

    Tags to be assigned to the current test

Returns:

  • nil



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/beaker/dsl/test_tagging.rb', line 23

def tag(*tags)
  [:case] ||= {}
  [:case][:tags] = []
  tags.each do |tag|
    [:case][:tags] << tag.downcase
  end

  @options[:test_tag_and]     ||= []
  @options[:test_tag_or]      ||= []
  @options[:test_tag_exclude] ||= []

  tags_needed_to_include_this_test = []
  @options[:test_tag_and].each do |tag_to_include|
    tags_needed_to_include_this_test << tag_to_include \
      unless [:case][:tags].include?(tag_to_include)
  end
  skip_test "#{self.path} does not include necessary tag(s): #{tags_needed_to_include_this_test}" \
    if tags_needed_to_include_this_test.length > 0

  found_test_tag = false
  @options[:test_tag_or].each do |tag_to_include|
    found_test_tag = [:case][:tags].include?(tag_to_include)
    break if found_test_tag
  end
  skip_test "#{self.path} does not include any of these tag(s): #{@options[:test_tag_or]}" \
    if @options[:test_tag_or].length > 0 && !found_test_tag

  tags_to_remove_to_include_this_test = []
  @options[:test_tag_exclude].each do |tag_to_exclude|
    tags_to_remove_to_include_this_test << tag_to_exclude \
      if [:case][:tags].include?(tag_to_exclude)
  end
  skip_test "#{self.path} includes excluded tag(s): #{tags_to_remove_to_include_this_test}" \
    if tags_to_remove_to_include_this_test.length > 0

  platform_specific_tag_confines
end