Skip to content

Instantly share code, notes, and snippets.

@hobodave
Created July 20, 2015 19:10
Show Gist options
  • Save hobodave/68b96890a8f0b36c60ec to your computer and use it in GitHub Desktop.
Save hobodave/68b96890a8f0b36c60ec to your computer and use it in GitHub Desktop.
require 'rspec'
class Bar
def self.bar(num)
puts "#{num}: Called!"
end
end
class Foo
def self.foo(num = 100)
threads = []
(1..num).each do |i|
threads << Thread.new do
Bar.bar(i)
end
end
threads.map(&:join)
end
end
describe Foo do
context 'many' do
100.times do
it 'works' do
num = 2
#allow(Thread).to receive(:new).and_yield.and_return(Thread.new {})
expect(Bar).to receive(:bar).exactly(num).times.and_call_original
Foo.foo(num)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment