Top Level Namespace

Defined Under Namespace

Modules: Erubis, Kernel, Merb, Spec Classes: Class, Exception, Hash, MemCache, Memcached, Object, String, Time

Instance Method Summary collapse

Instance Method Details

#run_spec(spec, base_dir, run_opts = "-fs") ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/merb-core/test/run_spec.rb', line 22

def run_spec(spec, base_dir, run_opts = "-fs")

  $VERBOSE = nil
  err, out = StringIO.new, StringIO.new
  def out.tty?() true end
  options = Spec::Runner::OptionParser.parse(%W(#{spec} --color).concat(%W(#{run_opts})), err, out)
  options.filename_pattern = File.expand_path(spec)
  failure = ! Spec::Runner::CommandLine.run(options)
  File.open(base_dir / "results" / "#{File.basename(spec)}_out", "w") do |file|
    file.puts out.string
  end
  File.open(base_dir / "results" / "#{File.basename(spec)}_err", "w") do |file|
    file.puts err.string
  end
  exit!(failure ? -1 : 0)
end

#run_specs(globs, spec_cmd = 'spec', run_opts = "-c", except = []) ⇒ Object

Runs specs in all files matching the file pattern.

Parameters

globs<String, Array>

File patterns to look for.

spec_cmd<~to_s>

The spec command. Defaults to “spec”.

run_opts<String>

Options to pass to spec commands, for instance, if you want to use profiling formatter.

except>

File paths to skip.


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/merb-core/test/run_specs.rb', line 86

def run_specs(globs, spec_cmd='spec', run_opts = "-c", except = [])
  require "optparse"
  require "spec"
  globs = globs.is_a?(Array) ? globs : [globs]
  
  forking = (ENV["FORK"] ? ENV["FORK"] == "1" : Merb.forking_environment?)
  base_dir = File.expand_path(File.dirname(__FILE__) / ".." / ".." / "..")
  
  counter = Merb::Counter.new
  forks   = 0
  failure = false

  FileUtils.rm_rf(base_dir / "results")
  FileUtils.mkdir_p(base_dir / "results")

  time = Benchmark.measure do
    files = {}
    globs.each do |glob|
      Dir[glob].each do |spec|
        if forking
          Kernel.fork do
            run_spec(spec, base_dir, run_opts)
          end
          Process.wait
        else
          `NOW=1 #{Gem.ruby} #{File.dirname(__FILE__) / "run_spec.rb"} \"#{spec}\"`
        end
        begin
          out = File.read(base_dir / "results" / "#{File.basename(spec)}_out")
          err = File.read(base_dir / "results" / "#{File.basename(spec)}_err")
          counter.add(spec, out, err)        
        rescue Errno::ENOENT => e
          STDOUT.puts e.message
        end
      end
    end
  end
  
  Process.waitall
  
  counter.time = time
  counter.report
  FileUtils.rm_rf(base_dir / "results")  
  exit!(counter.failed? ? -1 : 0)
end