From 120010c2b6f012296ff620a6823d5164d88b2bbc Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 26 Mar 2012 11:31:50 -0400 Subject: [PATCH] queue up messages to send until a socket is available, for browsers --- lib/assets/javascripts/flowerbox.js.coffee | 10 +++++++++- lib/flowerbox/rack.rb | 2 +- lib/flowerbox/run/debug.rb | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index 4062e5a..ee4ec8c 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -7,11 +7,19 @@ Flowerbox = ping: -> Flowerbox.contact('ping') + messageQueue: [] + contact: (url, data...) -> Flowerbox.started = true if !Flowerbox.debug - Flowerbox.socket.send(JSON.stringify([ url, data ])) + message = [ url, data ] + Flowerbox.messageQueue.push(message) + + if Flowerbox.socket + while Flowerbox.messageQueue.length > 0 + message = Flowerbox.messageQueue.shift() + Flowerbox.socket.send(JSON.stringify(message)) Flowerbox.done = true if url == 'results' diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb index 37bc492..50e0f5c 100644 --- a/lib/flowerbox/rack.rb +++ b/lib/flowerbox/rack.rb @@ -12,7 +12,7 @@ module Flowerbox def _call(env) if sprockets_file = env['PATH_INFO'][%r{/__F__(.*)$}, 1] - sprockets.call(env.merge('PATH_INFO' => sprockets_file)) + sprockets.call(env.merge('QUERY_STRING' => 'body=1', 'PATH_INFO' => sprockets_file)) else [ 200, { 'Content-type' => 'text/html' }, [ runner.template ] ] end diff --git a/lib/flowerbox/run/debug.rb b/lib/flowerbox/run/debug.rb index db9ca01..e0803ec 100644 --- a/lib/flowerbox/run/debug.rb +++ b/lib/flowerbox/run/debug.rb @@ -6,7 +6,7 @@ module Flowerbox::Run env = Flowerbox.runner_environment.first env.setup(sprockets, spec_files, options) - Flowerbox.reporters.replace([]) + Flowerbox.reporters.clear! puts "Flowerbox debug server running test prepared for #{env.console_name} on #{env.server.address}"