Class: Specbandit::Worker
- Inherits:
-
Object
- Object
- Specbandit::Worker
- Defined in:
- lib/specbandit/worker.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#key_rerun ⇒ Object
readonly
Returns the value of attribute key_rerun.
-
#key_rerun_ttl ⇒ Object
readonly
Returns the value of attribute key_rerun_ttl.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#rerun ⇒ Object
readonly
Returns the value of attribute rerun.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(key: Specbandit.configuration.key, batch_size: Specbandit.configuration.batch_size, adapter: nil, key_rerun: Specbandit.configuration.key_rerun, key_rerun_ttl: Specbandit.configuration.key_rerun_ttl, rerun: Specbandit.configuration.rerun, verbose: Specbandit.configuration.verbose, queue: nil, output: $stdout, rspec_opts: nil) ⇒ Worker
constructor
A new instance of Worker.
-
#run ⇒ Object
Main entry point.
Constructor Details
#initialize(key: Specbandit.configuration.key, batch_size: Specbandit.configuration.batch_size, adapter: nil, key_rerun: Specbandit.configuration.key_rerun, key_rerun_ttl: Specbandit.configuration.key_rerun_ttl, rerun: Specbandit.configuration.rerun, verbose: Specbandit.configuration.verbose, queue: nil, output: $stdout, rspec_opts: nil) ⇒ Worker
Returns a new instance of Worker.
10 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 |
# File 'lib/specbandit/worker.rb', line 10 def initialize( key: Specbandit.configuration.key, batch_size: Specbandit.configuration.batch_size, adapter: nil, key_rerun: Specbandit.configuration.key_rerun, key_rerun_ttl: Specbandit.configuration.key_rerun_ttl, rerun: Specbandit.configuration.rerun, verbose: Specbandit.configuration.verbose, queue: nil, output: $stdout, # Legacy parameter for backward compatibility. # When adapter is not provided, rspec_opts is used to build an RspecAdapter. rspec_opts: nil ) @key = key @batch_size = batch_size @key_rerun = key_rerun @key_rerun_ttl = key_rerun_ttl @rerun = rerun @verbose = verbose @queue = queue || RedisQueue.new @output = output @batch_results = [] @accumulated_examples = [] @accumulated_summary = { duration: 0.0, example_count: 0, failure_count: 0, pending_count: 0, errors_outside_of_examples_count: 0 } # Support both new adapter-based and legacy rspec_opts-based construction. # If no adapter is provided, fall back to RspecAdapter for backward compatibility. @adapter = adapter || RspecAdapter.new( rspec_opts: rspec_opts || Specbandit.configuration.rspec_opts, verbose: verbose, output: output ) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def adapter @adapter end |
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def batch_size @batch_size end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def key @key end |
#key_rerun ⇒ Object (readonly)
Returns the value of attribute key_rerun.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def key_rerun @key_rerun end |
#key_rerun_ttl ⇒ Object (readonly)
Returns the value of attribute key_rerun_ttl.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def key_rerun_ttl @key_rerun_ttl end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def output @output end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def queue @queue end |
#rerun ⇒ Object (readonly)
Returns the value of attribute rerun.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def rerun @rerun end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/specbandit/worker.rb', line 8 def verbose @verbose end |
Instance Method Details
#run ⇒ Object
Main entry point. Detects the operating mode and dispatches accordingly.
Returns 0 if all batches passed (or nothing to do), 1 if any batch failed.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/specbandit/worker.rb', line 49 def run adapter.setup exit_code = if key_rerun rerun_files = queue.read_all(key_rerun) if rerun_files.any? run_replay(rerun_files) elsif rerun output.puts "[specbandit] ERROR: --rerun flag is set but rerun key '#{key_rerun}' is empty." output.puts '[specbandit] The rerun key may have expired (TTL) or Redis was flushed.' output.puts '[specbandit] Cannot replay — failing to prevent silent false pass.' 1 else run_steal(record: true) end else run_steal(record: false) end print_summary if @batch_results.any? merge_json_results write_github_step_summary if ENV['GITHUB_STEP_SUMMARY'] exit_code ensure adapter.teardown end |