Created
December 16, 2008 13:22
-
-
Save raul/36451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick & Dirty textmate command to execute only the selected test on the current Rails test file | |
# Note: It's so quick and so dirty that it doesn't support the new 'test "foo bar baz" do' syntax | |
# | |
# 1) Open Bundles > Bundle Editor > Edit commands | |
# 2) Select Ruby > Run Focused Unit Test and press "copy" icon (++) | |
# 3) Rename the new command and select it | |
# 4) Paste this into Command(s) and customize the activation keys | |
cd ../.. | |
# Assumes the current file is a unittest file | |
# Runs with the currently-focused method as the test name | |
args=$(${TM_RUBY:=ruby} <<"EOF" | |
n = ENV['TM_LINE_NUMBER'].to_i | |
spec, context, name = nil, nil, nil | |
File.open(ENV['TM_FILEPATH']) do |f| | |
# test/unit | |
lines = f.read.split("\n")[0...n].reverse | |
name = lines.find { |line| line =~ /^\s*def test[_a-z0-9]*[\?!]?/i}.to_s.sub(/^\s*def (.*?)\s*$/) { $1 } | |
# test/spec. | |
spec = $3 || $4 if lines.find { |line| line =~ /^\s*(specify|it)\s+('(.*)'|"(.*)")+\s*(\{|do)/ } | |
context = $3 || $4 if lines.find { |line| line =~ /^\s*(context|describe)\s+('(.*)'|"(.*)")+\s*(\{|do)/ } | |
end | |
puts [name, spec, context].inspect | |
if !name.empty? | |
print "--name=#{name}" | |
elsif !spec.empty? && !context.empty? | |
print "--name=\"/test_spec \\{.*#{context}\\} \\d{3} \\[#{spec}\\]/\"" | |
end | |
EOF) | |
if [[ -z "$args" ]]; then | |
echo -e "This doesn't appear to be a TestCase class." | |
exit_show_tool_tip | |
fi | |
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}" | |
export RUBYLIB="test:$RUBYLIB" | |
"${TM_RUBY:-ruby}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb" $args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment