Class: RRRSpec::Client::RSpecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rrrspec/client/rspec_runner.rb

Instance Method Summary collapse

Constructor Details

#initializeRSpecRunner

Returns a new instance of RSpecRunner.



7
8
9
10
11
12
13
14
# File 'lib/rrrspec/client/rspec_runner.rb', line 7

def initialize
  @options = RSpec::Core::ConfigurationOptions.new([])
  @configuration = RSpec.configuration
  @world = RSpec.world
  @before_suite_run = false
  @stdout_buffer = StringIO.new
  @stderr_buffer = StringIO.new
end

Instance Method Details

#exc_safe_replace_stdoutsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rrrspec/client/rspec_runner.rb', line 16

def exc_safe_replace_stdouts
  @stdout_buffer.string = ''
  @stderr_buffer.string = ''
  $stdout = @stdout_buffer
  $stderr = @stderr_buffer
  begin
    yield
  rescue Exception
    $stdout.puts $!
    $stdout.puts $!.backtrace.join("\n")
  end
  outbuf = @stdout_buffer.string
  errbuf = @stderr_buffer.string
  [outbuf, errbuf]
ensure
  $stdout = STDOUT
  $stderr = STDERR
end

#resetObject



78
79
80
81
# File 'lib/rrrspec/client/rspec_runner.rb', line 78

def reset
  @world.example_groups.clear
  @configuration.reset
end

#run(*formatters) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rrrspec/client/rspec_runner.rb', line 61

def run(*formatters)
  status = false
  outbuf, errbuf = exc_safe_replace_stdouts do
    formatters.each do |formatter|
      @configuration.add_formatter(formatter)
    end
    @configuration.reporter.report(@world.example_count) do |reporter|
      @world.ordered_example_groups.each do |example_group|
        example_group.run(reporter)
      end
    end
    status = true
  end

  [status, outbuf, errbuf]
end

#setup(filepath) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rrrspec/client/rspec_runner.rb', line 35

def setup(filepath)
  status = false
  outbuf, errbuf = exc_safe_replace_stdouts do
    begin
      @options.configure(@configuration)
      @configuration.output_stream = $stdout
      @configuration.error_stream = $stderr
      @configuration.default_formatter = BaseTextFormatter
      @configuration.files_to_run = [filepath]
      @configuration.load_spec_files
      @world.announce_filters
      unless @before_suite_run
        run_before_suite_hooks
        @before_suite_run = true
      end
      status = true
    rescue Exception
      $stdout.puts $!
      $stdout.puts $!.backtrace.join("\n")
      status = false
    end
  end

  [status, outbuf, errbuf]
end