changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/autotest/rspec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require 'autotest'
2
3Autotest.add_hook :initialize do |at|
4 at.clear_mappings
5 # watch out: Ruby bug (1.8.6):
6 # %r(/) != /\//
7 at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
8 filename
9 }
10 at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
11 ["spec/#{m[1]}_spec.rb"]
12 }
13 at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
14 at.files_matching %r%^spec/.*_spec\.rb$%
15 }
16end
17
18class RspecCommandError < StandardError; end
19
20class Autotest::Rspec < Autotest
21
22 def initialize
23 super
24
25 self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
26 self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
27 end
28
29 def consolidate_failures(failed)
30 filters = Hash.new { |h,k| h[k] = [] }
31 failed.each do |spec, failed_trace|
32 if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
33 filters[f] << spec
34 break
35 end
36 end
37 return filters
38 end
39
40 def make_test_cmd(files_to_test)
41 return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
42 end
43
44 def add_options_if_present
45 File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
46 end
47
48 # Finds the proper spec command to use. Precendence is set in the
49 # lazily-evaluated method spec_commands. Alias + Override that in
50 # ~/.autotest to provide a different spec command then the default
51 # paths provided.
52 def spec_command(separator=File::ALT_SEPARATOR)
53 unless defined? @spec_command then
54 @spec_command = spec_commands.find { |cmd| File.exists? cmd }
55
56 raise RspecCommandError, "No spec command could be found!" unless @spec_command
57
58 @spec_command.gsub! File::SEPARATOR, separator if separator
59 end
60 @spec_command
61 end
62
63 # Autotest will look for spec commands in the following
64 # locations, in this order:
65 #
66 # * bin/spec
67 # * default spec bin/loader installed in Rubygems
68 def spec_commands
69 [
70 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
71 File.join(Config::CONFIG['bindir'], 'spec')
72 ]
73 end
74end