@@ -25,6 +25,12 @@ def feature_name
2525 @feature_name ||= feature . name
2626 end
2727
28+ # Title path without the final scenario display name.
29+ # @return [Array<String>]
30+ def title_path
31+ [ feature_path , feature_name , rule_name ] . compact
32+ end
33+
2834 # Scenario name
2935 # @return [String]
3036 def name
@@ -52,19 +58,60 @@ def tags
5258 # Feature file name
5359 # @return [String]
5460 def feature_file_name
55- @feature_file_name ||= test_case . location . file . split ( "/" ) . last . gsub ( ".feature" , "" )
61+ @feature_file_name ||= File . basename ( location_file , ".feature " )
5662 end
5763
5864 # Feature folder
5965 # @return [String]
6066 def feature_folder
61- @feature_folder ||= test_case . location . file . split ( "/" ) [ -2 ]
67+ @feature_folder ||= begin
68+ directory = File . dirname ( location_file )
69+ directory == "." ? nil : File . basename ( directory )
70+ end
6271 end
6372
6473 private
6574
6675 attr_reader :test_case , :scenario_source , :feature
6776
77+ # @return [String]
78+ def feature_path
79+ @feature_path ||= location_file . delete_prefix ( "./" )
80+ end
81+
82+ # @return [String]
83+ def location_file
84+ @location_file ||= test_case . location . file
85+ end
86+
87+ # @return [String, nil]
88+ def rule_name
89+ @rule_name ||= rule &.name
90+ end
91+
92+ # @return [Object, nil]
93+ def rule
94+ return unless scenario_id
95+
96+ @rule ||= Array ( feature . children )
97+ . filter_map { |child | child . rule if child . respond_to? ( :rule ) }
98+ . find { |child_rule | rule_scenario_ids ( child_rule ) . include? ( scenario_id ) }
99+ end
100+
101+ # @return [Array<String>]
102+ def rule_scenario_ids ( rule )
103+ Array ( rule . children ) . filter_map do |child |
104+ next unless child . respond_to? ( :scenario )
105+
106+ child . scenario &.id
107+ end
108+ end
109+
110+ # @return [String, nil]
111+ def scenario_id
112+ @scenario_id ||= scenario . respond_to? ( :id ) ? scenario . id : nil
113+ end
114+
68115 # Is scenario outline
69116 # @return [Boolean]
70117 def scenario_outline?
0 commit comments