Ever wanted autocompletion for paths from paths.rb
in Cucumber? This card lets you write your steps like this:
When I go to path *press tab now* # path is replaced with a list of all known Cucumber paths
This is how you do it
(key shortcuts apply for TextMate2)
-
Open the bundle editor (ctrl + alt + + B)
-
Create a new Item ( + N), select "Command"
-
Paste this:
^
#!/usr/bin/env ruby -wKU
require File.join(ENV['TM_SUPPORT_PATH'], 'lib', 'ui.rb')cucumber_paths = File.join ENV['TM_PROJECT_DIRECTORY'], 'features', 'support', 'paths.rb'
if File.exist? cucumber_paths
lines = []
File.open(cucumber_paths, 'r').each do |line|
lines << line.slice(/\s+when /^?([^$]*)$?/[im]?$/, 1) # @param 1: return first matched group
end
paths = lines.compact.sortTextMate::UI.complete(paths, :extra_chars => " ")
else
%x{ "$DIALOG" tooltip --html 'File /features/support/paths.rb not found.' }
end
Now you only need some more configuration:
- Name the command (e.g. "Cucumber: paths")
- scope selector is
text.gherkin.feature
- choose a tab trigger (e.g. "path")
- input: nothing
- output: insert at caret
- caret placement: after output
You're done!