Top Level Namespace

Defined Under Namespace

Modules: ColorfulMessages, Erubis, Gem, GemManagement, Kernel, Merb, Spec Classes: Exception, Hash, MemCache, Memcached, Object, String

Instance Method Summary collapse

Instance Method Details

#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<Array>

File paths to skip.



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
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/merb-core/test/run_specs.rb', line 101

def run_specs(globs, spec_cmd='spec', run_opts = "-c", except = [])
  require "optparse"
  require "spec"
  globs = globs.is_a?(Array) ? globs : [globs]
  
  counter = Merb::Counter.new
  forks   = 0
  failure = false

  time = Benchmark.measure do
    pid = nil
    globs.each do |glob|
      Dir[glob].each do |spec|
        drb_uri = DRb.start_service(nil, counter).uri
        Kernel.fork do
          $VERBOSE = nil
          DRb.stop_service
          DRb.start_service
          counter_client = DRbObject.new_with_uri(drb_uri)
          err, out = StringIO.new, StringIO.new
          def out.tty?() true end
          options = Spec::Runner::OptionParser.parse(%W(#{spec} -fs --color), err, out)
          options.filename_pattern = File.expand_path(spec)
          failure = ! Spec::Runner::CommandLine.run(options)
          begin
            counter_client.add(spec, out.string, err.string)
          rescue DRb::DRbConnError => e
            puts "#{Process.pid}: Exception caught"
            puts "#{e.class}: #{e.message}"
            retry
          end
          exit(failure ? -1 : 0)
        end
      end
      failure = Process.waitall.any? { |pid, s| !s.success? }
    end
  end
  
  counter.time = time
  counter.report
  exit!(failure ? -1 : 0)
end