~ubuntu-branches/ubuntu/lucid/puppet/lucid

« back to all changes in this revision

Viewing changes to autotest/rspec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

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