Skip to content

Instantly share code, notes, and snippets.

@palkan
Last active April 18, 2017 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save palkan/9870bb17899c6849bae20a5413d47c35 to your computer and use it in GitHub Desktop.
Save palkan/9870bb17899c6849bae20a5413d47c35 to your computer and use it in GitHub Desktop.
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