Read more

Create autocompletion dropdown for Cucumber paths in Textmate

Dominik Schöler
September 17, 2012Software engineer at makandra GmbH

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

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

(key shortcuts apply for TextMate2)

  1. Open the bundle editor (ctrl + alt +  + B)

  2. Create a new Item ( + N), select "Command"

  3. 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.sort

    TextMate::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!

Posted by Dominik Schöler to makandra dev (2012-09-17 08:25)