Class: Crspec::Runner
- Inherits:
-
Object
- Object
- Crspec::Runner
- Defined in:
- lib/crspec/runner.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#failed_examples ⇒ Object
readonly
Returns the value of attribute failed_examples.
-
#fibers ⇒ Object
readonly
Returns the value of attribute fibers.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#passed_examples ⇒ Object
readonly
Returns the value of attribute passed_examples.
-
#pending_examples ⇒ Object
readonly
Returns the value of attribute pending_examples.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#total_duration ⇒ Object
readonly
Returns the value of attribute total_duration.
Instance Method Summary collapse
-
#initialize(concurrency: Etc.nprocessors, fibers: 1, formatter: nil, fail_fast: false, seed: nil, only_failures: false, persistence_path: nil, tags: nil, locations: nil) ⇒ Runner
constructor
A new instance of Runner.
- #run(example_groups) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(concurrency: Etc.nprocessors, fibers: 1, formatter: nil, fail_fast: false, seed: nil, only_failures: false, persistence_path: nil, tags: nil, locations: nil) ⇒ Runner
Returns a new instance of Runner.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/crspec/runner.rb', line 18 def initialize(concurrency: Etc.nprocessors, fibers: 1, formatter: nil, fail_fast: false, seed: nil, only_failures: false, persistence_path: nil, tags: nil, locations: nil) @concurrency = concurrency @fibers = fibers && fibers > 1 && defined?(Async) ? fibers : 1 @formatter = formatter || Formatters::ProgressFormatter.new @queue = Thread::Queue.new @passed_examples = [] @failed_examples = [] @pending_examples = [] @total_duration = 0 @fail_fast = fail_fast == true ? 1 : fail_fast @failure_count = 0 @failure_mutex = Mutex.new @seed = seed @only_failures = only_failures @tags = @locations = locations @persistence = StatusPersistence.new( persistence_path || Crspec.configuration.example_status_persistence_file_path ) end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def concurrency @concurrency end |
#failed_examples ⇒ Object (readonly)
Returns the value of attribute failed_examples.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def failed_examples @failed_examples end |
#fibers ⇒ Object (readonly)
Returns the value of attribute fibers.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def fibers @fibers end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def formatter @formatter end |
#passed_examples ⇒ Object (readonly)
Returns the value of attribute passed_examples.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def passed_examples @passed_examples end |
#pending_examples ⇒ Object (readonly)
Returns the value of attribute pending_examples.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def pending_examples @pending_examples end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def seed @seed end |
#total_duration ⇒ Object (readonly)
Returns the value of attribute total_duration.
16 17 18 |
# File 'lib/crspec/runner.rb', line 16 def total_duration @total_duration end |
Instance Method Details
#run(example_groups) ⇒ Object
41 42 43 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/crspec/runner.rb', line 41 def run(example_groups) Rails::AssetsShim.install! if defined?(Rails::AssetsShim) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @formatter.start example_groups.each(&:finalize!) examples = [] example_groups.each { |group| collect_examples(group, examples) } examples = filter_examples(examples) previous_statuses = @persistence.load examples = order_examples(examples, previous_statuses) examples.each { |example| @queue.push(example) } @queue.close workers = Array.new(@concurrency) do |worker_idx| Thread.new do worker_number = worker_idx + 1 results = { passed: [], failed: [], pending: [] } Thread.current[:crspec_results] = results Rails::Parallel.setup_worker(worker_number) if defined?(Rails::Parallel) && Rails::Parallel.enabled? if @fibers > 1 run_worker_fibers(results) else while (example = @queue.pop) execute_example(example, results) end end ensure Rails::DatabaseIsolation.finish_worker if defined?(Rails::DatabaseIsolation) Rails::Parallel.teardown_worker(worker_number) if defined?(Rails::Parallel) && Rails::Parallel.enabled? end end workers.each do |worker| worker.join results = worker[:crspec_results] next unless results @passed_examples.concat(results[:passed]) @failed_examples.concat(results[:failed]) @pending_examples.concat(results[:pending]) end @total_duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time Mock::Interceptor.cleanup! if defined?(Mock::Interceptor) @persistence.save(@passed_examples + @failed_examples) @formatter.finish self end |
#success? ⇒ Boolean
91 92 93 |
# File 'lib/crspec/runner.rb', line 91 def success? @failed_examples.empty? end |