Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RSpec Hell: run examples concurrently (using threads)
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
You can’t perform that action at this time.