class AllureRspec::RspecMetadataParser
RSpec metadata parser
Constants
- RSPEC_IGNORED_METADATA
Attributes
@return [AllureRspec::RspecConfig]
@return [RSpec::Core::Example]
Public Class Methods
Source
# File lib/allure_rspec/metadata_parser.rb, line 35 def initialize(example, config) @example = example @config = config end
Metadata parser instance
@param [RSpec::Core::Example] example @param [AllureRspec::RspecConfig] config
Public Instance Methods
Source
# 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
Get allure labels @return [Array<Allure::Label>]
Source
# File lib/allure_rspec/metadata_parser.rb, line 56 def links matching_links(:tms) + matching_links(:issue) end
Get attachable links @return [Array<Allure::Link>]
Source
# 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
Example location
@return [String]
Source
# 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
Get status details @return [Allure::StatusDetails]
Private Instance Methods
Source
# File lib/allure_rspec/metadata_parser.rb, line 198 def allure?(key) key.to_s.match?(/allure(_\d+)?/i) end
Does key match custom allure label @param [Symbol] key @return [boolean]
Source
# 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
Get behavior labels @return [Array<Allure::Label>]
Source
# 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
Label value from custom metadata
@param [String, Symbol] key @param [Object] value @return [Allure::Label]
Source
# File lib/allure_rspec/metadata_parser.rb, line 115 def framework_label Allure::ResultUtils.framework_label("rspec") end
Get framework label @return [Allure::Label]
Source
# File lib/allure_rspec/metadata_parser.rb, line 212 def issue?(key) key.to_s.match?(/#{config.issue_tag}(_\d+)?/i) end
Does key match issue pattern @param [Symbol] key @return [boolean]
Source
# File lib/allure_rspec/metadata_parser.rb, line 160 def matching_links(type) link_pattern = config.public_send(:"link_#{type}_pattern") return [] unless link_pattern metadata .select { |key| __send__(:"#{type}?", key) } .map { |key, value| Allure::ResultUtils.public_send(:"#{type}_link", key.to_s, value, link_pattern) } end
tms and issue links @param [Symbol] type @return [Array<Allure::Link>]
Source
# File lib/allure_rspec/metadata_parser.rb, line 96 def metadata @metadata ||= example.metadata end
Example metadata
@return [Hash]
Source
# 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
Get package label @return [Allure::Label]
Source
# File lib/allure_rspec/metadata_parser.rb, line 121 def severity Allure::ResultUtils.severity_label(metadata[config.severity_tag] || "normal") end
Get severity @return [String]
Source
# 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
Special allure metadata tags
@param [Symbol] key @return [boolean]
Source
# File lib/allure_rspec/metadata_parser.rb, line 127 def suite_labels SuiteLabels.new(example.example_group).fetch end
Get test suite labels @return [Array<Allure::Label>]
Source
# 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
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>]
Source
# 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
Get test class label
@return [Allure::Label]
Source
# File lib/allure_rspec/metadata_parser.rb, line 205 def tms?(key) key.to_s.match?(/#{config.tms_tag}(_\d+)?/i) end
Does key match tms pattern @param [Symbol] key @return [boolean]