Class: KnapsackPro::Runners::Queue::RSpecRunner
- Inherits:
-
BaseRunner
- Object
- BaseRunner
- KnapsackPro::Runners::Queue::RSpecRunner
show all
- Defined in:
- lib/knapsack_pro/runners/queue/rspec_runner.rb
Constant Summary
Constants inherited
from BaseRunner
BaseRunner::TERMINATION_SIGNALS, BaseRunner::TerminationError
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseRunner
run_tests, #test_dir, #test_file_paths
Constructor Details
#initialize(adapter_class, rspec_pure, args, stream_error, stream_out) ⇒ RSpecRunner
Returns a new instance of RSpecRunner.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/knapsack_pro/runners/queue/rspec_runner.rb', line 23
def initialize(adapter_class, rspec_pure, args, stream_error, stream_out)
super(adapter_class)
@adapter_class = adapter_class
@rspec_pure = rspec_pure
args_array = (args || '').split
has_format_option = @adapter_class.has_format_option?(args_array)
has_require_rails_helper_option = @adapter_class.has_require_rails_helper_option?(args_array)
rails_helper_exists = @adapter_class.rails_helper_exists?(test_dir)
@cli_args = rspec_pure.prepare_cli_args(args, has_format_option, has_require_rails_helper_option, rails_helper_exists, test_dir)
@stream_error = stream_error
@stream_out = stream_out
@node_test_file_paths = []
@rspec_runner = nil end
|
Class Method Details
.run(args, stream_error = $stderr, stream_out = $stdout) ⇒ Object
Instance Method Details
#handle_signal! ⇒ Object
104
105
106
|
# File 'lib/knapsack_pro/runners/queue/rspec_runner.rb', line 104
def handle_signal!
self.class.handle_signal!
end
|
#log_fail_fast_limit_met ⇒ Object
108
109
110
|
# File 'lib/knapsack_pro/runners/queue/rspec_runner.rb', line 108
def log_fail_fast_limit_met
KnapsackPro.logger.warn('Test execution has been canceled because the RSpec --fail-fast option is enabled. It will cause other CI nodes to run tests longer because they need to consume more tests from the Knapsack Pro Queue API.')
end
|
#run ⇒ Fixnum
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/knapsack_pro/runners/queue/rspec_runner.rb', line 44
def run
pre_run_setup
if @rspec_runner.knapsack__wants_to_quit?
exit_code = @rspec_runner.knapsack__exit_early
Kernel.exit(exit_code)
end
begin
exit_code = @rspec_runner.knapsack__run_specs(self)
rescue KnapsackPro::Runners::Queue::BaseRunner::TerminationError
exit_code = @rspec_pure.error_exit_code(@rspec_runner.knapsack__error_exit_code)
Kernel.exit(exit_code)
rescue Exception => exception
KnapsackPro.logger.error("An unexpected exception happened. RSpec cannot handle it. The exception: #{exception.inspect}")
KnapsackPro.logger.error("Exception message: #{exception.message}")
KnapsackPro.logger.error("Exception backtrace: #{exception.backtrace.join("\n")}")
message = @rspec_pure.exit_summary(unexecuted_test_files)
KnapsackPro.logger.warn(message) if message
exit_code = @rspec_pure.error_exit_code(@rspec_runner.knapsack__error_exit_code)
Kernel.exit(exit_code)
end
post_run_tasks(exit_code)
end
|
#with_batch ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/knapsack_pro/runners/queue/rspec_runner.rb', line 72
def with_batch
can_initialize_queue = true
loop do
handle_signal!
test_file_paths = pull_tests_from_queue(can_initialize_queue: can_initialize_queue)
can_initialize_queue = false
break if test_file_paths.empty?
subset_queue_id = KnapsackPro::Config::EnvGenerator.set_subset_queue_id
ENV['KNAPSACK_PRO_SUBSET_QUEUE_ID'] = subset_queue_id
KnapsackPro::Hooks::Queue.call_before_subset_queue
yield test_file_paths
KnapsackPro::Hooks::Queue.call_after_subset_queue
if @rspec_runner.knapsack__wants_to_quit?
KnapsackPro.logger.warn('RSpec wants to quit.')
set_terminate_process
end
if @rspec_runner.knapsack__rspec_is_quitting?
KnapsackPro.logger.warn('RSpec is quitting.')
set_terminate_process
end
log_rspec_batch_command(test_file_paths)
end
end
|