TextMate's Run Focused Unit Test for simply_bdd October 3rd
We all know TextMate is one heck of a text editor. And Testing your Rails applications is a hot topic. As is Behaviour Driven Development, which has recently been facilitated by Rick Olson’s simply_bdd plugin. However, using simply_bdd’s way of method definition breaks with TextMate’s lovely “Run Focused Unit Test” Command from the Ruby Bundle, which allows you to run a single unit test out of a whole suite of tests by simply positioning your cursor into the test you’d like to run. Fear not, here’s a snippet which supports both.
# Assumes the current file is a unittest file
# Runs with the currently-focused method as the test name
method=$(${TM_RUBY:=ruby} <<"EOF"
n = ENV['TM_LINE_NUMBER'].to_i
File.open(ENV['TM_FILEPATH']) do |f|
f.read.split("\n")[0...n].reverse.each do |line|
if line =~ /^\s*(?:def ([_a-z]\w*[\?!]?)|specify ["\'](.+)["\'] do)/i
print ($1 || $2.downcase.gsub(/\s/, "_").insert(0, "test_"))
break
end
end
end
EOF)
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
"${TM_RUBY:-ruby}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb" \
--name=$method
You can replace your existing command snippet (which will store a custom version of the snippet in your home directory’s Library folder instead of overwriting the original TextMate bundle) by using the Bundle Editor to edit the command in question (⌃⌥⌘C). Remember, it’s the “Run Focused Unit Test” Command from the Ruby Bundle (which has a keyboard shortcut of ⌘⇧R by the way).

0 comments
Jump to comment form