Created
March 26, 2014 08:41
-
-
Save shakthimaan/9778964 to your computer and use it in GitHub Desktop.
rspec foo.rb is looping in while
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
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