diff options
Diffstat (limited to 'vendor/plugins/rspec/lib/autotest/rspec.rb')
-rw-r--r-- | vendor/plugins/rspec/lib/autotest/rspec.rb | 62 |
1 files changed, 23 insertions, 39 deletions
diff --git a/vendor/plugins/rspec/lib/autotest/rspec.rb b/vendor/plugins/rspec/lib/autotest/rspec.rb index cf7421ee1..164f298f5 100644 --- a/vendor/plugins/rspec/lib/autotest/rspec.rb +++ b/vendor/plugins/rspec/lib/autotest/rspec.rb @@ -18,35 +18,18 @@ end class RspecCommandError < StandardError; end class Autotest::Rspec < Autotest - - def tests_for_file(filename) - super.select { |f| @files.has_key? f } - end - - alias :specs_for_file :tests_for_file - - def failed_results(results) - results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m) - end - def handle_results(results) - @files_to_test = consolidate_failures failed_results(results) - unless @files_to_test.empty? then - hook :red - else - hook :green - end unless $TESTING - @tainted = true unless @files_to_test.empty? + def initialize + super + self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m + self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m end - + def consolidate_failures(failed) - filters = Hash.new { |h,k| h[k] = [] } - failed.each do |spec, failed_trace| - @files.keys.select{|f| f =~ /spec\//}.each do |f| - if failed_trace =~ Regexp.new(f) - filters[f] << spec - break - end + filters = new_hash_of_arrays + failed.each do |spec, trace| + if trace =~ /\n(\.\/)?(.*\.rb):[\d]+:\Z?/ + filters[$2] << spec end end return filters @@ -56,23 +39,25 @@ class Autotest::Rspec < Autotest return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" end - def add_options_if_present + def add_options_if_present # :nodoc: File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : "" end - # Finds the proper spec command to use. Precendence - # is set in the lazily-evaluated method spec_commands. Alias + Override - # that in ~/.autotest to provide a different spec command - # then the default paths provided. - def spec_command - @spec_command ||= spec_commands.each do |command| - if File.exists?(command) - return @alt_separator ? (command.gsub @separator, @alt_separator) : command - end + # Finds the proper spec command to use. Precendence is set in the + # lazily-evaluated method spec_commands. Alias + Override that in + # ~/.autotest to provide a different spec command then the default + # paths provided. + def spec_command(separator=File::ALT_SEPARATOR) + unless defined? @spec_command then + @spec_command = spec_commands.find { |cmd| File.exists? cmd } + + raise RspecCommandError, "No spec command could be found!" unless @spec_command + + @spec_command.gsub! File::SEPARATOR, separator if separator end - raise RspecCommandError, "No spec command could be found!" + @spec_command end - + # Autotest will look for spec commands in the following # locations, in this order: # @@ -84,5 +69,4 @@ class Autotest::Rspec < Autotest File.join(Config::CONFIG['bindir'], 'spec') ] end - end |