<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>beforeRunningCommand</key>
	<string>nop</string>
	<key>bundleUUID</key>
	<string>467B298F-6227-11D9-BFB1-000D93589AF6</string>
	<key>captureFormatString</key>
	<string>$0</string>
	<key>capturePattern</key>
	<string>(/[^:]+):(\d+)</string>
	<key>command</key>
	<string># Assumes the current file is a unittest file
# Runs with the currently-focused method as the test name

base_files=($(${TM_RUBY:=ruby} &lt;&lt;"EOF"
module_name = nil

def find_module_name_in_file(file_name)
  File.open(file_name) do |file|
    n = ENV['TM_LINE_NUMBER'].to_i
    lines     = file.read.split("\n")[0...n]
    lines.each do |line| 
      match_data = line.match(/^module\b(.*)\b/)
	 return match_data[1].strip if match_data
    end
  end
  nil
end

def file_names_that_include_module(module_name)
  file_names = []
  Dir.new(".").each do |file|
    unless File.directory?(file)
      match_data = nil
      File.open(file) do |f|
        match_data = f.read.match(/.*include\s+#{module_name}\s.*/)
      end
      if match_data
        file_names &lt;&lt; file 
      end
    end
  end
  file_names
end 

def bottom_level_includers(file_name)
  bottom_levels = []

  module_name = find_module_name_in_file(file_name)
  if module_name.nil? 
    bottom_levels &lt;&lt; file_name 
  else
    file_names = file_names_that_include_module(module_name)
    file_names.each do |f_name|
      bottom_levels += bottom_level_includers(f_name)
    end
  end 
  bottom_levels 
end

module_name = find_module_name_in_file(ENV['TM_FILEPATH'])
file_names = file_names_that_include_module(module_name)
bottom_level_includers = []


file_names.each do |file_name|
 bottom_level_includers += bottom_level_includers(file_name)
end

#file_names = bottom_level_includers(ENV['TM_FILEPATH'])
print bottom_level_includers.join(" ")

EOF))

export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
for file_name in ${base_files[@]}
do
 "${TM_RUBY:-ruby}" -e '
require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
require "cgi"

$SCRIPTMATE_VERSION = "$Revision: 6354 $"

module RunFocusedTestInModule
  class Parser
    def parse
      n = ENV["TM_LINE_NUMBER"].to_i

      name = 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 }
      end

      if !name.empty?
        return "--name=#{name}"
      else
        return ""
      end
    end
  end
end

class UserScript
  def initialize(content, write_content_to_stdin=true)
    file_name = File.join(ENV["TM_DIRECTORY"], "'$file_name'")
    @write_content_to_stdin = write_content_to_stdin
    @content = content
    #match the entire she-bang.
    @hashbang = $1 if @content =~ /\A#!(.*)$/
    if ENV.has_key? "TM_FILEPATH" then
      @path = file_name 
      @display_name = File.basename(@path)
      # save file
      #open(@path, "w") { |io| io.write @content }
    else
      @path = "-"
      @display_name = "untitled"
    end
  end
end

ARGV[0]=RunFocusedTestInModule::Parser.new.parse

require "run_script"
'
done
</string>
	<key>fallbackInput</key>
	<string>document</string>
	<key>fileCaptureRegister</key>
	<string>1</string>
	<key>input</key>
	<string>none</string>
	<key>keyEquivalent</key>
	<string>@M</string>
	<key>lineCaptureRegister</key>
	<string>2</string>
	<key>name</key>
	<string>Run Focused Unit Test for module</string>
	<key>output</key>
	<string>showAsHTML</string>
	<key>scope</key>
	<string>source.ruby</string>
	<key>uuid</key>
	<string>175F897E-06DA-42A2-AF26-2DDAEC4C7442</string>
</dict>
</plist>
