class AllureRspec::RspecMetadataParser
RSpec metadata parser
Constants
- RSPEC_IGNORED_METADATA
Attributes
@return [AllureRspec::RspecConfig]
@return [RSpec::Core::Example]
Public Class Methods
Metadata parser instance
@param [RSpec::Core::Example] example @param [AllureRspec::RspecConfig] config <description>
# File lib/allure_rspec/metadata_parser.rb, line 35 def initialize(example, config) @example = example @config = config end
Public Instance Methods
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
Get attachable links @return [Array<Allure::Link>]
# File lib/allure_rspec/metadata_parser.rb, line 56 def links matching_links(:tms) + matching_links(:issue) end
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
Does key match custom allure label @param [Symbol] key @return [boolean]
# File lib/allure_rspec/metadata_parser.rb, line 168 def allure?(key) key.to_s.match?(/allure(_\d+)?/i) end
Get behavior labels @return [Array<Allure::Label>]
# File lib/allure_rspec/metadata_parser.rb, line 126 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 framework label @return [Allure::Label]
# File lib/allure_rspec/metadata_parser.rb, line 100 def framework_label Allure::ResultUtils.framework_label("rspec") end
Does key match issue pattern @param [Symbol] key @return [boolean]
# File lib/allure_rspec/metadata_parser.rb, line 182 def issue?(key) key.to_s.match?(/#{config.issue_tag}(_\d+)?/i) end
tms and issue links @param [Symbol] type @return [Array<Allure::Link>]
# File lib/allure_rspec/metadata_parser.rb, line 142 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
Example metadata
@return [Hash]
# File lib/allure_rspec/metadata_parser.rb, line 81 def metadata @metadata ||= example.metadata end
Get package label @return [Allure::Label]
# File lib/allure_rspec/metadata_parser.rb, line 87 def package_label Allure::ResultUtils.package_label(Pathname.new(strip_relative(example.file_path)).parent.to_s) end
Get severity @return [String]
# File lib/allure_rspec/metadata_parser.rb, line 106 def severity Allure::ResultUtils.severity_label(metadata[config.severity_tag] || "normal") end
Special allure metadata tags
@param [Symbol] key @return [boolean]
# File lib/allure_rspec/metadata_parser.rb, line 155 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
Get test suite labels @return [Array<Allure::Label>]
# File lib/allure_rspec/metadata_parser.rb, line 112 def suite_labels SuiteLabels.new(example.example_group).fetch end
Get custom labels @return [Array<Allure::Label>]
# File lib/allure_rspec/metadata_parser.rb, line 118 def tag_labels metadata .reject { |k| RSPEC_IGNORED_METADATA.include?(k) || special_metadata_tag?(k) } .map { |k, v| allure?(k) ? Allure::ResultUtils.tag_label(v) : Allure::ResultUtils.tag_label(k.to_s) } end
Get test class label
@return [Allure::Label]
# File lib/allure_rspec/metadata_parser.rb, line 94 def test_class_label Allure::ResultUtils.test_class_label(File.basename(example.file_path, ".rb")) end
Does key match tms pattern @param [Symbol] key @return [boolean]
# File lib/allure_rspec/metadata_parser.rb, line 175 def tms?(key) key.to_s.match?(/#{config.tms_tag}(_\d+)?/i) end