Class: RSpec::Interactive::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-interactive/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
# File 'lib/rspec-interactive/runner.rb', line 6

def initialize(args)
  ::RSpec.world.wants_to_quit = false
  @options = ::RSpec::Core::ConfigurationOptions.new(args)
end

Instance Method Details

#persist_example_statusesObject



59
60
61
62
63
64
65
66
# File 'lib/rspec-interactive/runner.rb', line 59

def persist_example_statuses
  return if ::RSpec.configuration.dry_run
  return unless (path = ::RSpec.configuration.example_status_persistence_file_path)

  ::RSpec::Core::ExampleStatusPersister.persist(::RSpec.world.all_examples, path)
rescue SystemCallError => e
  ::RSpec.configuration.error_stream.puts "warning: failed to write results to #{path}"
end

#quitObject



55
56
57
# File 'lib/rspec-interactive/runner.rb', line 55

def quit
  ::RSpec.world.wants_to_quit = true
end

#runObject



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
49
50
51
52
53
# File 'lib/rspec-interactive/runner.rb', line 11

def run()
  begin
    @options.configure(::RSpec.configuration)
    return if ::RSpec.world.wants_to_quit

    ::RSpec.configuration.load_spec_files
  ensure
    ::RSpec.world.announce_filters
  end

  return ::RSpec.configuration.reporter.exit_early(::RSpec.configuration.failure_exit_code) if ::RSpec.world.wants_to_quit

  example_groups = ::RSpec.world.ordered_example_groups
  examples_count = ::RSpec.world.example_count(example_groups)

  exit_code = ::RSpec.configuration.reporter.report(examples_count) do |reporter|
    ::RSpec.configuration.with_suite_hooks do
      if examples_count == 0 && ::RSpec.configuration.fail_if_no_examples
        return ::RSpec.configuration.failure_exit_code
      end

      group_results = example_groups.map do |example_group|
        example_group.run(reporter)
      end

      success = group_results.all?
      exit_code = success ? 0 : 1
      if ::RSpec.world.non_example_failure
        success = false
        exit_code = ::RSpec.configuration.failure_exit_code
      end
      persist_example_statuses
      exit_code
    end
  end

  if exit_code != 0 && ::RSpec.configuration.example_status_persistence_file_path
    ::RSpec.configuration.output_stream.puts "Rerun failures by executing the previous command with --only-failures or --next-failure."
    ::RSpec.configuration.output_stream.puts
  end

  exit_code
end