Skip to content

Instantly share code, notes, and snippets.

@shakthimaan
Created March 26, 2014 08:41
Show Gist options
  • Save shakthimaan/9778964 to your computer and use it in GitHub Desktop.
Save shakthimaan/9778964 to your computer and use it in GitHub Desktop.
rspec foo.rb is looping in while
require 'rubygems'
class Foo
attr_accessor :mutex
attr_accessor :started
attr_accessor :running
def initialize
@mutex = Mutex.new
@started = ConditionVariable.new
end
def start
@mutex.synchronize do
while !@running
puts @running
@started.wait(@mutex)
end
end
end
end
describe "Foo" do
before do
@a = Foo.new
end
it "must start" do
expect(@a.mutex).to receive(:synchronize).and_yield
once = true
@a.stub(:running) {
if once
once = false
puts "Once"
false
else
puts "Twice"
once = true
true
end
}
expect(@a.started).to receive(:wait)
@a.start
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment