class AllureRspec::RspecMetadataParser

RSpec metadata parser

Constants

RSPEC_IGNORED_METADATA

Attributes

config[R]

@return [AllureRspec::RspecConfig]

example[R]

@return [RSpec::Core::Example]

Public Class Methods

new(example, config) click to toggle source

Metadata parser instance

@param [RSpec::Core::Example] example @param [AllureRspec::RspecConfig] config

# File lib/allure_rspec/metadata_parser.rb, line 35
def initialize(example, config)
  @example = example
  @config = config
end

Public Instance Methods

labels() click to toggle source

Get allure labels @return [Array<Allure::Label>]

# File lib/allure_rspec/metadata_parser.rb, line 42
def labels
  [
    framework_label,
    package_label,
    test_class_label,
    severity,
    *tag_labels,
    *behavior_labels,
    *suite_labels
  ].select(&:value)
end
location() click to toggle source

Example location

@return [String]

# File lib/allure_rspec/metadata_parser.rb, line 73
def location
  file = example
         .metadata
         .fetch(:shared_group_inclusion_backtrace)
         .last
         &.formatted_inclusion_location

  return example.location unless file

  file
end
status_details() click to toggle source

Get status details @return [Allure::StatusDetails]

# File lib/allure_rspec/metadata_parser.rb, line 62
def status_details
  Allure::StatusDetails.new(
    flaky: !metadata[:flaky].nil?,
    muted: !metadata[:muted].nil?,
    known: !metadata[:known].nil?
  )
end

Private Instance Methods

allure?(key) click to toggle source

Does key match custom allure label @param [Symbol] key @return [boolean]

# File lib/allure_rspec/metadata_parser.rb, line 198
def allure?(key)
  key.to_s.match?(/allure(_\d+)?/i)
end
behavior_labels() click to toggle source

Get behavior labels @return [Array<Allure::Label>]

# File lib/allure_rspec/metadata_parser.rb, line 144
def behavior_labels
  metadata = example.metadata
  epic = metadata[config.epic_tag] || Pathname.new(strip_relative(example.file_path)).parent.to_s
  feature = metadata[config.feature_tag] || example.example_group.description
  story = metadata[config.story_tag]

  [
    Allure::ResultUtils.epic_label(epic),
    Allure::ResultUtils.feature_label(feature),
    Allure::ResultUtils.story_label(story)
  ]
end
custom_label(key, value) click to toggle source

Label value from custom metadata

@param [String, Symbol] key @param [Object] value @return [Allure::Label]

# File lib/allure_rspec/metadata_parser.rb, line 174
def custom_label(key, value)
  return if value == false
  return Allure::ResultUtils.tag_label(value.to_s) if value.is_a?(String) || value.is_a?(Symbol)

  Allure::ResultUtils.tag_label(key.to_s)
end
framework_label() click to toggle source

Get framework label @return [Allure::Label]

# File lib/allure_rspec/metadata_parser.rb, line 115
def framework_label
  Allure::ResultUtils.framework_label("rspec")
end
issue?(key) click to toggle source

Does key match issue pattern @param [Symbol] key @return [boolean]

# File lib/allure_rspec/metadata_parser.rb, line 212
def issue?(key)
  key.to_s.match?(/#{config.issue_tag}(_\d+)?/i)
end
metadata() click to toggle source

Example metadata

@return [Hash]

# File lib/allure_rspec/metadata_parser.rb, line 96
def metadata
  @metadata ||= example.metadata
end
package_label() click to toggle source

Get package label @return [Allure::Label]

# File lib/allure_rspec/metadata_parser.rb, line 102
def package_label
  Allure::ResultUtils.package_label(Pathname.new(strip_relative(example.file_path)).parent.to_s)
end
severity() click to toggle source

Get severity @return [String]

# File lib/allure_rspec/metadata_parser.rb, line 121
def severity
  Allure::ResultUtils.severity_label(metadata[config.severity_tag] || "normal")
end
special_metadata_tag?(key) click to toggle source

Special allure metadata tags

@param [Symbol] key @return [boolean]

# File lib/allure_rspec/metadata_parser.rb, line 185
def special_metadata_tag?(key)
  tms?(key) || issue?(key) || [
    config.severity_tag,
    config.epic_tag,
    config.feature_tag,
    config.story_tag,
    *config.ignored_tags
  ].include?(key)
end
suite_labels() click to toggle source

Get test suite labels @return [Array<Allure::Label>]

# File lib/allure_rspec/metadata_parser.rb, line 127
def suite_labels
  SuiteLabels.new(example.example_group).fetch
end
tag_labels() click to toggle source

Get custom labels

skip tags that are set to false explicitly
use value as label when it's a string or a symbol

@return [Array<Allure::Label>]

# File lib/allure_rspec/metadata_parser.rb, line 136
def tag_labels
  metadata
    .reject { |k| RSPEC_IGNORED_METADATA.include?(k) || special_metadata_tag?(k) }
    .filter_map { |k, v| custom_label(k, v) }
end
test_class_label() click to toggle source

Get test class label

@return [Allure::Label]

# File lib/allure_rspec/metadata_parser.rb, line 109
def test_class_label
  Allure::ResultUtils.test_class_label(File.basename(example.file_path, ".rb"))
end
tms?(key) click to toggle source

Does key match tms pattern @param [Symbol] key @return [boolean]

# File lib/allure_rspec/metadata_parser.rb, line 205
def tms?(key)
  key.to_s.match?(/#{config.tms_tag}(_\d+)?/i)
end