~ubuntu-branches/ubuntu/raring/facter/raring

« back to all changes in this revision

Viewing changes to autotest/rspec.rb

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2011-10-18 10:32:42 UTC
  • mfrom: (1.1.10 upstream) (3.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111018103242-vvgvfa9pf057xnmj
Tags: 1.6.1-1ubuntu1
* Merge from Debian unstable (LP: #877621). Remaining changes:
  - debian/rules: use what we had in natty; we dont want ruby-pkg-tools
    in main. (LP: #408402)
* debian/control: Continue using ruby + libopenssl-ruby as Build-Depends
  even tho Debian has moved to gem2deb (not in main). Move ruby-json to
  Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'autotest'
2
 
 
3
 
Autotest.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
 
    }
16
 
end
17
 
 
18
 
class RspecCommandError < StandardError; end
19
 
 
20
 
class 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
74
 
end