simplfy, always use server for file delivery

This commit is contained in:
John Bintz 2012-02-29 14:23:56 -05:00
parent cbdb553c42
commit 230034ed16
9 changed files with 106 additions and 47 deletions

2
.gitignore vendored
View File

@ -15,3 +15,5 @@ spec/reports
test/tmp
test/version_tmp
tmp
.tmp

View File

@ -21,6 +21,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'flowerbox-delivery'
gem.add_dependency 'thor'
gem.add_dependency 'capybara'
gem.add_dependency 'selenium-webdriver'
gem.add_dependency 'sinatra'
end

View File

@ -7,6 +7,8 @@ module Flowerbox
autoload :Base, 'flowerbox/runner/base'
end
autoload :Rack, 'flowerbox/rack'
class << self
def spec_patterns
@spec_patterns ||= []

30
lib/flowerbox/rack.rb Normal file
View File

@ -0,0 +1,30 @@
require 'sinatra'
module Flowerbox
class Rack < Sinatra::Base
class << self
attr_accessor :runner
end
def runner
self.class.runner
end
post '/results' do
runner.results = request.body.string
end
post '/log' do
runner.log(request.body.string)
end
get %r{^/__F__(/.*)$} do |file|
File.read(file)
end
get '/' do
runner.template
end
end
end

View File

@ -14,6 +14,15 @@ module Flowerbox
def start_test_environment
Flowerbox.test_environment.start_for(type)
end
def server
return @server if @server
@server = Flowerbox::Delivery::Server.new(:app => Flowerbox::Rack)
Flowerbox::Rack.runner = self
@server
end
end
end
end

View File

@ -1,4 +1,6 @@
require 'tempfile'
require 'flowerbox/delivery/server'
require 'json'
module Flowerbox
module Runner
@ -10,8 +12,12 @@ module Flowerbox
file.print template
file.close
server.start
system %{node #{file.path}}
server.stop
$?.exitstatus
end
@ -20,20 +26,47 @@ module Flowerbox
<<-JS
var fs = require('fs'),
vm = require('vm');
vm = require('vm'),
http = require('http');
// expand the sandbox a bit
var context = function() {};
context.window = true;
for (method in global) { context[method] = global[method]; }
#{template_files.join("\n")}
#{env}
JS
end
var files = #{sprockets.files.to_json};
var fileRunner = function() {
if (files.length > 0) {
var file = files.shift();
console.log(file);
def template_files
sprockets.files.collect { |file| %{vm.runInNewContext(fs.readFileSync('#{file}', 'utf-8'), context, '#{file}');} }
var options = {
host: "localhost",
port: #{server.port},
path: "/__F__" + file,
method: "GET"
};
var request = http.request(options, function(response) {
var data = '';
response.on('data', function(chunk) {
data += chunk;
});
response.on('end', function() {
vm.runInNewContext(data, context, file);
fileRunner();
});
});
request.end();
} else {
#{env}
}
};
fileRunner();
JS
end
end
end

View File

@ -1,54 +1,20 @@
require 'capybara'
require 'capybara/dsl'
require 'sinatra'
require 'thread'
require 'selenium-webdriver'
module Flowerbox
module Runner
class Selenium < Base
include Capybara::DSL
class Rack < Sinatra::Base
class << self
attr_accessor :runner
end
def runner
self.class.runner
end
post '/results' do
runner.results = request.body.string
end
post '/log' do
runner.log(request.body.string)
end
get %r{^/__F__(/.*)$} do |file|
File.read(file)
end
get '/' do
runner.template
end
end
attr_accessor :browser, :results
def run(sprockets)
super
Capybara.register_driver :firefox do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
Capybara.default_driver = :firefox
selenium = ::Selenium::WebDriver.for :firefox
Rack.runner = self
Capybara.app = Rack
visit '/'
server.start
selenium.navigate.to "http://localhost:#{server.port}/"
1.upto(30) do
if results
@ -65,6 +31,8 @@ module Flowerbox
else
exit 1
end
ensure
selenium.quit if selenium
end
def log(msg)

View File

@ -0,0 +1,10 @@
Flowerbox.configure do |c|
c.test_with :jasmine
c.run_with :selenium
c.spec_patterns << "*_spec.*"
c.spec_patterns << "**/*_spec.*"
c.test_environment.reporters << "SimpleSeleniumReporter"
end

View File

@ -0,0 +1,5 @@
describe("cats", function() {
it("should hiss", function() {
expect("hiss").toEqual("hiss");
});
});