Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. # Quick & Dirty textmate command to execute only the selected test on the current Rails test file
  2. # Note: It's so quick and so dirty that it doesn't support the new 'test "foo bar baz" do' syntax
  3. #
  4. # 1) Open Bundles > Bundle Editor > Edit commands
  5. # 2) Select Ruby > Run Focused Unit Test and press "copy" icon (++)
  6. # 3) Rename the new command and select it
  7. # 4) Paste this into Command(s) and customize the activation keys
  8.  
  9. cd ../..
  10.  
  11. # Assumes the current file is a unittest file
  12. # Runs with the currently-focused method as the test name
  13.  
  14. args=$(${TM_RUBY:=ruby} <<"EOF"
  15.  
  16. n = ENV['TM_LINE_NUMBER'].to_i
  17.  
  18. spec, context, name = nil, nil, nil
  19.  
  20. File.open(ENV['TM_FILEPATH']) do |f|
  21. # test/unit
  22. lines = f.read.split("\n")[0...n].reverse
  23. name = lines.find { |line| line =~ /^\s*def test[_a-z0-9]*[\?!]?/i}.to_s.sub(/^\s*def (.*?)\s*$/) { $1 }
  24. # test/spec.
  25. spec = $3 || $4 if lines.find { |line| line =~ /^\s*(specify|it)\s+('(.*)'|"(.*)")+\s*(\{|do)/ }
  26. context = $3 || $4 if lines.find { |line| line =~ /^\s*(context|describe)\s+('(.*)'|"(.*)")+\s*(\{|do)/ }
  27. end
  28.  
  29. puts [name, spec, context].inspect
  30.  
  31. if !name.empty?
  32. print "--name=#{name}"
  33. elsif !spec.empty? && !context.empty?
  34. print "--name=\"/test_spec \\{.*#{context}\\} \\d{3} \\[#{spec}\\]/\""
  35. end
  36. EOF)
  37.  
  38. if [[ -z "$args" ]]; then
  39. echo -e "This doesn't appear to be a TestCase class."
  40. exit_show_tool_tip
  41. fi
  42.  
  43. export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
  44. export RUBYLIB="test:$RUBYLIB"
  45. "${TM_RUBY:-ruby}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb" $args
Add Comment
Please, Sign In to add comment