Sha256: 70fb53e4df15415773af4b22addefbedc87888043f3162345f444ca39f23487f
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
require 'spec_helper' describe Hara::App do before :all do Class.new do include Hara::App 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 'client_infos' do @app.client_ip.should == '127.0.0.1' @app.client_port.should.is_a? Integer @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.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.1 | spec/app_spec.rb |