spec/app_spec.rb in hara-0.2.1 vs spec/app_spec.rb in hara-0.2.2

- old
+ new

@@ -15,11 +15,11 @@ def after_action action, *args @states << [:after_action, action, args] end - def on_close + def on_close close_info @states << :closed end def action_missing action, *args socket.send [:action_missing, action, args] @@ -27,20 +27,25 @@ define_action :hello do |msg| socket.send "hello#{msg}" end + define_action :exit do + close 3333, "Bye" + end + def states @states end end end before :each do @handshake = FayeHandshake.new @socket = FayeSocket.new @app = Hara::Application.new @handshake, @socket + @socket.app = @app end after :each do if @app && @app.alive? @app.terminate! @@ -53,32 +58,41 @@ @app.headers.should.is_a? Hash end it 'remote call actions' do @app.process_msg(Hara.encode_msg(:hello, ' world')) - sleep 0.1 until msg = @socket.client_read + msg = nil + wait_until{msg = @socket.client_read} msg.should == 'hello world' end + it 'close should close connection' do + @app.process_msg(Hara.encode_msg(:exit)) + wait_until{!@app.alive?} + @socket.alive?.should == false + @socket.close_info.should == [3333, 'Bye'] + end + it 'error remote call' do @app.process_msg('a error call') - sleep 0.1 while @app.alive? + wait_until{!@app.alive?} msg = @socket.client_read msg.should == nil end it 'action_missing should work' do @app.process_msg(Hara.encode_msg(:hello_world, 'hello', 'world')) - sleep 0.1 until msg = @socket.client_read + msg = nil + wait_until{msg = @socket.client_read} msg.should == [:action_missing, 'hello_world', ['hello', 'world']] end it 'callbacks should work' do 2.times{ @app.process_msg(Hara.encode_msg(:hello, ' world'))} states = @app.states sleep 0.2 @app.terminate - sleep 0.1 while @app.alive? + wait_until{!@app.alive?} action_callbacks = [[:before_action, "hello", [" world"]], [:after_action, "hello", [" world"]]] states.should == [*(action_callbacks * 2),:closed] end end