Last active
April 18, 2017 17:59
-
-
Save palkan/9870bb17899c6849bae20a5413d47c35 to your computer and use it in GitHub Desktop.
RSpec Hell: run examples concurrently (using threads)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpecHell | |
def run_examples(reporter) | |
return super unless metadata[:hell] && !(metadata[:parent_example_group] && metadata[:parent_example_group].key?(:hell)) | |
pool_size = ENV['HELL'].to_i | |
q = Queue.new | |
ordering_strategy.order(descendant_filtered_examples).each { |ex| q << ex } | |
workers = [] | |
results = [] | |
pool_size.times do |n| | |
workers << Thread.new do | |
while (example = q.shift(true) rescue nil) do | |
next if RSpec.world.wants_to_quit | |
instance = new(example.inspect_output) | |
set_ivars(instance, before_context_ivars) | |
succeeded = example.run(instance, reporter) | |
if !succeeded && reporter.fail_fast_limit_met? | |
RSpec.world.wants_to_quit = true | |
end | |
results << succeeded | |
end | |
end | |
end | |
workers.each(&:join) | |
children.clear | |
results.all? | |
end | |
end | |
if Nenv.hell? | |
RSpec::Core::ExampleGroup.singleton_class.prepend(RSpecHell) | |
p "Using RSpecHell 👿" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment