Skip to content

Commit

Permalink
feat: prioritize ambiguous steps
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaai committed Oct 3, 2024
1 parent 5eb4a21 commit aa0d41e
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/turnip/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ def step(step_or_description, *extra_args)
end

if matches.length > 1
msg = ['Ambiguous step definitions'].concat(matches.map(&:trace)).join("\r\n")
raise Turnip::Ambiguous, msg
if match_1 = matches.select { |m| not m.block.source_location.first.match(/shared/) }.first
send(match_1.method_name, *(match_1.params + extra_args))
elsif
match_2 =
matches
.select { |m| m.block.source_location.first.match(/shared/) }
.sort do |m1, m2|
folder_level_1 = m1.block.source_location.first.split('/').count
folder_level_2 = m2.block.source_location.first.split('/').count
folder_level_1 <=> folder_level_2
end
.reverse
.first
send(match_2.method_name, *(match_2.params + extra_args))
else
msg = ['Ambiguous step definitions'].concat(matches.map(&:trace)).join("\r\n")
raise Turnip::Ambiguous, msg
end
else
send(matches.first.method_name, *(matches.first.params + extra_args))
end

send(matches.first.method_name, *(matches.first.params + extra_args))
end
end
end

0 comments on commit aa0d41e

Please sign in to comment.