Skip to content
bicarbon8 edited this page May 21, 2014 · 1 revision

Examples

Difference between rspec-parallel and other, similar gems

Using one spec file with 2 examples in a single example_group (the describe block):

RSpec.configure do |config|
  config.before(:suite) { puts 'Before Suite' }
  config.before(:all) { puts 'Before All' }
  config.before(:each) { puts 'Before Each' }
  config.after(:each) { puts 'After Each' }
  config.after(:all) { puts 'After All' }
  config.after(:suite) { puts 'After Suite' }
end

describe 'Parallel Testing' do
  it 'example 1' do 
    sleep 2; puts 'Example 1' 
  end
  it 'example 2' do 
    sleep 2; puts 'Example 2' 
  end
end

Comparison between rspec-parallel, prspec and parallel_tests

> rspec --parallel-test 2 > prspec -n 2 > parallel_rspec spec -n 2
Before Suite
Before All
Before Each
Example 2
After Each
Before Each
Example 1
After Each
After All
After Suite


Finished in 2.01 seconds
2 examples, 0 failures
Before Suite
Before Suite
Before All
Before All
Before Each
Example 1
Before Each
Example 2
After Each
After Each
After All
After All
After Suite
After Suite


Finished in 2.01 seconds
1 example, 0 failures
Finished in 2.01 seconds
1 example, 0 failures
Before Suite
Before All
Before Each
Example 1
After Each
Before Each
Example 2
After Each
After All
After Suite


Finished in 4 seconds
examples, 0 failures

2 examples, 0 failures

Took 4.36225 seconds
Total execution time is 2.01 seconds (both examples run in parallel) Total execution time is 2.01 seconds (both examples run in parallel) Total execution time is 4.36 seconds (both examples run sequentially because parallel_tests splits by spec file, not example)

Using two spec files with 2 examples in each (spec_helper.rb is used for before(:suite) to ensure both spec files have access to it):

# spec_helper.rb
RSpec.configure do |config|
  config.before(:suite) { puts 'Before Suite' }
  config.after(:suite) { puts 'After Suite' }
end
# one_spec.rb
require_relative 'spec_helper'

describe 'Parallel Testing' do
  before(:all) { puts 'Before All One' }
  before(:each) { puts 'Before Each One' }
  after(:each) { puts 'After Each One' }
  after(:all) { puts 'After All One' }

  it 'example 1' do 
    sleep 2; puts 'Example 1' 
  end
  it 'example 2' do 
    sleep 2; puts 'Example 2' 
  end
end
# two_spec.rb
require_relative 'spec_helper'

describe 'Parallel Testing Two' do
  before(:all) { puts 'Before All Two' }
  before(:each) { puts 'Before Each Two' }
  after(:each) { puts 'After Each Two' }
  after(:all) { puts 'After All Two' }

  it 'example 3' do 
    sleep 2; puts 'Example 3' 
  end
  it 'example 4' do 
    sleep 2; puts 'Example 4' 
  end
end

Comparison between rspec-parallel, prspec and parallel_tests

> rspec --parallel-test 4 > prspec -n 4 > parallel_rspec spec -n 4
Before Suite
Before All Two
Before All One
Before Each Two
Before Each Two
Before Each One
Before Each One
Example 3
After Each Two
Example 4
After Each Two
Example 2
After Each One
Example 1
After Each One
After All Two
After All
After Suite


Finished in 2.02 seconds
4 examples, 0 failures
Before Suite
Before All Two
Before Each Two
Before Suite
Before All Two
Before Each Two
Before Suite
Before All One
Before Each One
Before Suite
Before All One
Before Each One
Example 4
After Each Two
After All Two
After Suite


Finished in 2.01 seconds
1 example, 0 failures
Example 3
After Each Two
After All Two
After Suite


Finished in 2.01 seconds
1 example, 0 failures
Example 2
After Each One
After All One
After Suite


Finished in 2.01 seconds
1 example, 0 failures
Example 1
After Each One
After All One
After Suite


Finished in 2.01 seconds
1 example, 0 failures
Before Suite
Before All Two
Before Each Two
Before Suite
Before All One
Before Each One
Example 3
After Each Two
Before Each Two
Example 1
After Each One
Before Each One
Example 4
After Each Two
After All Two
After Suite


Finished in 4.01 seconds
examples, 0 failures
Example 2
After Each One
After All One
After Suite


Finished in 4 seconds
examples, 0 failures

4 examples, 0 failures

Took 4.406252 seconds
Total execution time is 2.02 seconds (all 4 examples run in parallel) Total execution time is 2.01 seconds (all 4 examples run in parallel) Total execution time is 4.40 seconds (both spec files run in parallel, but each example in the spec files is run sequentially because parallel_tests splits by spec file, not example)
Clone this wiki locally