spec/timer_spec.rb in rbuv-0.0.2 vs spec/timer_spec.rb in rbuv-0.0.3

- old
+ new

@@ -1,144 +1,161 @@ require 'spec_helper' describe Rbuv::Timer do it { should be_a_kind_of Rbuv::Handle } - context "run in loop" do - before(:each) { @skip_running_loop = false } - after(:each) { Rbuv.run_loop unless @skip_running_loop } + context "when timeout == 0" do + context "#start" do + it "when repeat == 0" do + timer = Rbuv::Timer.new - context "when timeout == 0" do - context "#start" do - it "when repeat == 0" do - timer = Rbuv::Timer.new + block = mock + block.should_receive(:call).once - block = mock - block.should_receive(:call).once - + Rbuv.run do timer.start 0, 0 do block.call end end + end - it "when repeat != 0" do - timer = Rbuv::Timer.new + it "when repeat != 0" do + timer = Rbuv::Timer.new - block = mock - count_limit = 10 - block.should_receive(:call).exactly(count_limit) + block = mock + count_limit = 10 + block.should_receive(:call).exactly(count_limit) - count = 0 + count = 0 + + Rbuv.run do timer.start 0, 1 do |t| block.call count += 1 if count >= count_limit t.stop end end end - end # context "#start" + end + end # context "#start" - it "#stop" do - timer = Rbuv::Timer.new + it "#stop" do + timer = Rbuv::Timer.new - block = mock - block.should_receive(:call).once + block = mock + block.should_receive(:call).once + Rbuv.run do timer.start 0, 1 do |t| block.call t.stop end end + end - context "#active?" do - it "should be false" do - timer = Rbuv::Timer.new + context "#active?" do + it "should be false" do + timer = Rbuv::Timer.new + Rbuv.run do timer.start 0, 0 do |t| t.active?.should be_false end end + end - it "should be true" do - timer = Rbuv::Timer.new + it "should be true" do + timer = Rbuv::Timer.new + Rbuv.run do timer.start 0, 1 do |t| t.active?.should be_true t.stop end end end + end - context "#repeat" do - [0, 10, 100].each do |repeat| - it "should eq #{repeat}" do - timer = Rbuv::Timer.new + context "#repeat" do + [0, 10, 100].each do |repeat| + it "should eq #{repeat}" do + timer = Rbuv::Timer.new + Rbuv.run do timer.start 0, repeat do |t| t.repeat.should eq repeat t.stop end end end end + end - context "#repeat=" do - [0, 10, 100].each do |repeat| - it "should eq #{repeat}" do - timer = Rbuv::Timer.new + context "#repeat=" do + [0, 10, 100].each do |repeat| + it "should eq #{repeat}" do + timer = Rbuv::Timer.new + Rbuv.run do timer.start 0, 0 do |t| t.repeat = repeat end - Rbuv.run_loop - timer.repeat.should eq repeat - @skip_running_loop = true end + timer.repeat.should eq repeat end end + end - context ".start" do - context 'be valid' do - it "when repeat == 0" do - block = mock - block.should_receive(:call).once + context ".start" do + context 'be valid' do + it "when repeat == 0" do + block = mock + block.should_receive(:call).once + Rbuv.run do Rbuv::Timer.start(0, 0) { block.call } end + end - it "when repeat != 0" do - block = mock - block.should_receive(:call).once + it "when repeat != 0" do + block = mock + block.should_receive(:call).once + Rbuv.run do Rbuv::Timer.start 0, 1 do |t| block.call t.stop end end end + end - context "won't segfault" do - it "when repeat == 0" do + context "won't segfault" do + it "when repeat == 0" do + Rbuv.run do Rbuv::Timer.start(0, 0) {} - GC.start end + GC.start + end - it "when repeat != 0" do - count = 0 - count_limit = 10 + it "when repeat != 0" do + count = 0 + count_limit = 10 + + Rbuv.run do Rbuv::Timer.start 0, 1 do |timer| GC.start count += 1 if count >= count_limit timer.stop end end - GC.start end + GC.start end + end - end # context ".start" + end # context ".start" - end # context "timeout == 0" - end # context "run in loop" + end # context "timeout == 0" end