module Beaker::DSL::TestTagging

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.

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

- {Beaker::Options::Parser#normalize_tags!} makes sure the test tags
  are formatted correctly for use in this module
- {Beaker::Options::CommandLineParser#initialize} parses test tagging
  options
- {Beaker::Options::Validator#validate_tags} ensures test tag CLI params
  are valid for use by this module

Public Instance Methods

platform_specific_tag_confines() click to toggle source

Handles platform-specific tag confines logic

@return nil @!visibility private

# File lib/beaker/dsl/test_tagging.rb, line 65
def platform_specific_tag_confines
  @options[:platform_tag_confines_object] ||= PlatformTagConfiner.new(
    @options[:platform_tag_confines],
  )
  confines = @options[:platform_tag_confines_object].confine_details(
    metadata[:case][:tags],
  )
  confines.each do |confine_details|
    logger.notify(confine_details[:log_message])
    confine(
      confine_details[:type],
      :platform => confine_details[:platform_regex],
    )
  end
end
tag(*tags) click to toggle source

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

@param [Array<String>] tags Tags to be assigned to the current test

@return nil @api public

# File lib/beaker/dsl/test_tagging.rb, line 23
def tag(*tags)
  metadata[:case] ||= {}
  metadata[:case][:tags] = []
  tags.each do |tag|
    metadata[: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 metadata[: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 = metadata[: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 metadata[: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