spec/node_spec.rb in dripdrop-0.6.0 vs spec/node_spec.rb in dripdrop-0.7.1

- old
+ new

@@ -1,31 +1,61 @@ require 'spec_helper' describe DripDrop::Node do - describe "initialization" do - before(:all) do - @ddn = DripDrop::Node.new { - zmq_subscribe(rand_addr,:bind) #Keeps ZMQMachine Happy - } - @ddn.start - sleep 1 - end - + shared_examples_for "all initialization methods" do it "should start EventMachine" do EM.reactor_running?.should be_true end it "should start ZMQMachine" do pending "This is not repeatedly reliable" @ddn.zm_reactor.running?.should be_true end - after do - @ddn.stop rescue nil + it "should run the block" do + @reactor_ran.should be_true end end + + #These tests break all subsequent ones, + #so require a special flag to test them + if ENV['DRIPDROP_INITSPEC'] == 'true' + describe "initialization with a block" do + before(:all) do + reactor_ran = false + @ddn = DripDrop::Node.new do + reactor_ran = true + end + @ddn.start + sleep 1 + + @reactor_ran = reactor_ran + end + + it_should_behave_like "all initialization methods" + end + describe "initialization as a class" do + before(:all) do + class InitializationTest < DripDrop::Node + attr_accessor :reactor_ran + def action + @reactor_ran = true + end + end + + @ddn = InitializationTest.new + @ddn.start + sleep 1 + + @reactor_ran = @ddn.reactor_ran + end + + it_should_behave_like "all initialization methods" + end + end + describe "shutdown" do before do @ddn = DripDrop::Node.new { zmq_subscribe(rand_addr,:bind) #Keeps ZMQMachine Happy } @@ -39,8 +69,22 @@ EM.reactor_running?.should be_false end it "should stop ZMQMachine" do @ddn.zm_reactor.running?.should be_false + end + end + + describe "exceptions in EM reactor" do + class TestException < StandardError; end + + it "should rescue exceptions in the EM reactor" do + expectations = an_instance_of(TestException) + reactor = run_reactor do + self.should_receive(:error_handler).with(expectations) + EM.next_tick do + raise TestException, "foo" + end + end end end end