public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Michael S. Klishin (author)
Sun May 11 12:40:45 -0700 2008
commit  df27240a0654cafe29807277063c78fb0e97e64b
tree    ae51c701c18eecb8be4a8c6e0b00f7f94580b728
parent  f3592507c5455a613f2c25bcfb7db514afbd6a2a
merb-core / lib / merb-core / test / run_specs.rb
100644 48 lines (44 sloc) 1.514 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'rubygems'
require 'open3'
require 'benchmark'
 
# Runs specs in all files matching the file pattern.
#
# ==== Parameters
# globs<String, Array[String]>:: 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.
def run_specs(globs, spec_cmd='spec', run_opts = "-c -f s")
  require "optparse"
  require "spec"
  globs = globs.is_a?(Array) ? globs : [globs]
  examples, failures, errors, pending = 0, 0, 0, 0
 
  time = Benchmark.measure do
    globs.each do |glob|
      Dir[glob].each do |spec|
        response = Open3.popen3("#{spec_cmd} #{File.expand_path(spec)} #{run_opts}") do |i,o,e|
          while out = o.gets
            STDOUT.puts out
            STDOUT.flush
            if out =~ /\d+ example/
              e, f, p = out.match(/(\d+) examples?, (\d+) failures?(?:, (\d+) pending?)?/)[1..-1]
              examples += e.to_i; failures += f.to_i; pending += p.to_i
            end
          end
          errors += 1 if e.is_a?(IO)
          STDOUT.puts e.read if e.is_a?(IO)
        end
      end
    end
  end
 
  puts
  puts "*** TOTALS ***"
  if failures == 0
    print "\e[32m"
  else
    print "\e[31m"
  end
  puts "#{examples} examples, #{failures} failures, #{errors} errors, #{pending} pending, #{sprintf("suite run in %3.3f seconds", time.real)}"
  # TODO: we need to report pending examples all together
  print "\e[0m"
end