Class: ParallelRSpec::Runner
- Inherits:
-
RSpec::Core::Runner
- Object
- RSpec::Core::Runner
- ParallelRSpec::Runner
- Defined in:
- lib/parallel_rspec/runner.rb
Constant Summary collapse
- @@running =
false
Class Method Summary collapse
-
.invoke ⇒ Object
Runs the suite of specs and exits the process with an appropriate exit code.
-
.run(args, err = $stderr, out = $stdout) ⇒ Fixnum
Run a suite of RSpec examples.
- .running? ⇒ Boolean
Instance Method Summary collapse
- #run_in_parallel(example_groups, reporter) ⇒ Object
-
#run_specs(example_groups) ⇒ Fixnum
Runs the provided example groups.
Class Method Details
.invoke ⇒ Object
Runs the suite of specs and exits the process with an appropriate exit code.
27 28 29 30 |
# File 'lib/parallel_rspec/runner.rb', line 27 def self.invoke status = run(ARGV, $stderr, $stdout).to_i exit(status) if status != 0 end |
.run(args, err = $stderr, out = $stdout) ⇒ Fixnum
Run a suite of RSpec examples. Does not exit.
This is used internally by RSpec to run a suite, but is available for use by any other automation tool.
If you want to run this multiple times in the same process, and you want files like ‘spec_helper.rb` to be reloaded, be sure to load `load` instead of `require`.
47 48 49 50 51 52 |
# File 'lib/parallel_rspec/runner.rb', line 47 def self.run(args, err=$stderr, out=$stdout) @@running = true RSpec::Core::Runner.trap_interrupt = RSpec::Core::ConfigurationOptions.new(args) new().run(err, out) end |
.running? ⇒ Boolean
21 22 23 |
# File 'lib/parallel_rspec/runner.rb', line 21 def self.running? @@running end |
Instance Method Details
#run_in_parallel(example_groups, reporter) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/parallel_rspec/runner.rb', line 74 def run_in_parallel(example_groups, reporter) server = Server.new(reporter) workers = Workers.new workers.run_test_workers_with_server(server) do |worker, channel_to_server| client = Client.new(channel_to_server) success = true while next_example = client.next_example_to_run example_group, example_index = *next_example example = RSpec.world.filtered_examples[example_group][example_index] example_group.parent_groups.reverse_each { |parent_group| parent_group.new("dummy instance to trigger helper loading order") } example_group_instance = example_group.new(example.inspect_output) success = example.run(example_group_instance, client) && success end client.result(success) end server.success? end |
#run_specs(example_groups) ⇒ Fixnum
Runs the provided example groups.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/parallel_rspec/runner.rb', line 60 def run_specs(example_groups) @configuration.reporter.report(@world.example_count(example_groups)) do |reporter| @configuration.with_suite_hooks do with_context_hooks, without_context_hooks = example_groups.partition(&:any_context_hooks?) success = run_in_parallel(without_context_hooks, reporter) success &&= with_context_hooks.map { |g| g.run(reporter) }.all? persist_example_statuses success ? 0 : @configuration.failure_exit_code end end end |