Sha256: a6da28224e997aad6774206b38cc29d07ce3015bc20005eaba80e19afbb3c568
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
require 'spec_helper' describe Hara::App do before :all do Class.new Hara::App do def after_connect @states = [] end def before_action action, *args @states << [:before_action, action, args] end def after_action action, *args @states << [:after_action, action, args] end def on_close @states << :closed end def action_missing action, *args socket.send [:action_missing, action, args] end define_action :hello do |msg| socket.send "hello#{msg}" end def states @states end end end before :each do @handshake = FayeHandshake.new @socket = FayeSocket.new @app = Hara::Application.new @handshake, @socket end after :each do if @app && @app.alive? @app.terminate! end end it 'remote call actions' do @app.process_msg(Hara.encode_msg(:hello, ' world')) sleep 0.1 until msg = @socket.client_read msg.should == 'hello world' end it 'error remote call' do @app.process_msg('a error call') sleep 0.1 while @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.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? action_callbacks = [[:before_action, "hello", [" world"]], [:after_action, "hello", [" world"]]] states.should == [*(action_callbacks * 2),:closed] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hara-0.2.0 | spec/app_spec.rb |