Class: Distributest::TestRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/distributest/test_runner.rb

Instance Method Summary collapse

Instance Method Details

#capture_outputObject



5
6
7
8
9
10
# File 'lib/distributest/test_runner.rb', line 5

def capture_output
  @stdout = StringIO.new
  @stderr = StringIO.new
  $stderr = @stderr
  $stdout = @stdout
end

#captured_outputObject



12
13
14
# File 'lib/distributest/test_runner.rb', line 12

def captured_output
  [@stdout.string, @stderr.string]
end

#run_rspec_file(file) ⇒ Object



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
# File 'lib/distributest/test_runner.rb', line 16

def run_rspec_file(file)
  capture_output
  
  start_time = Time.now
  begin
    require 'spec'

  rescue LoadError => ex
    return ex.to_s
  end

  output = []
  errors = []
  profile = []

  Spec::Runner.options.instance_variable_set(:@formatters,
    [Distributest::Formatter::BasicFormat.new(output, errors, profile)])
  Spec::Runner.options.instance_variable_set(:@example_groups, [])
  Spec::Runner.options.instance_variable_set(:@files, [file])
  Spec::Runner.options.instance_variable_set(:@files_loaded, false)

  if file == ""
    return nil
  else
    Spec::Runner.options.run_examples
  end
  end_time = Time.now
  total_time_for_file = end_time - start_time
  
  out, err = captured_output
  
  return output, errors, profile, total_time_for_file, out + err
end