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([])
  @options.parse_options
  @configuration = RSpec.configuration
  @configuration.setup_load_path_and_require([])
  @world = RSpec.world
  @before_suite_run = false
end

Instance Method Details

#exc_safe_replace_stdoutsObject



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

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

#resetObject



86
87
88
89
# File 'lib/rrrspec/client/rspec_runner.rb', line 86

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

#run(*formatters) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rrrspec/client/rspec_runner.rb', line 56

def run(*formatters)
  status = false
  outbuf, errbuf = exc_safe_replace_stdouts do
    @configuration.output_stream = $stdout
    @configuration.error_stream = $stderr
    @configuration.add_formatter(RSpec::Core::Formatters::BaseTextFormatter)
    if @configuration.respond_to?(:formatter_loader)
      # RSpec >= 2.99
      formatters.each do |formatter|
        @configuration.formatter_loader.formatters << formatter
      end
    else
      formatters.each do |formatter|
        @configuration.formatters << formatter
      end
    end
    @configuration.reporter.report(
      @world.example_count,
      @configuration.randomize? ? @configuration.seed : nil
    ) do |reporter|
      @world.example_groups.ordered.each do |example_group|
        example_group.run(reporter)
      end
    end
    status = true
  end

  [status, outbuf, errbuf]
end

#setup(filepath) ⇒ Object



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

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

  [status, outbuf, errbuf]
end