diff --git a/.gitignore b/.gitignore index d87d4be..49f96a9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ spec/reports test/tmp test/version_tmp tmp +.tmp + diff --git a/flowerbox.gemspec b/flowerbox.gemspec index 336d370..3752461 100644 --- a/flowerbox.gemspec +++ b/flowerbox.gemspec @@ -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 diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index 5d4ce74..b7b026e 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -7,6 +7,8 @@ module Flowerbox autoload :Base, 'flowerbox/runner/base' end + autoload :Rack, 'flowerbox/rack' + class << self def spec_patterns @spec_patterns ||= [] diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb new file mode 100644 index 0000000..b866cd6 --- /dev/null +++ b/lib/flowerbox/rack.rb @@ -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 + diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index aee0f26..a581b1a 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -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 diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index 91ba023..9ab893a 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -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 diff --git a/lib/flowerbox/runner/selenium.rb b/lib/flowerbox/runner/selenium.rb index 356b073..4b4a119 100644 --- a/lib/flowerbox/runner/selenium.rb +++ b/lib/flowerbox/runner/selenium.rb @@ -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) diff --git a/spec/javascripts/spec_helper.rb b/spec/javascripts/spec_helper.rb new file mode 100644 index 0000000..810b9a1 --- /dev/null +++ b/spec/javascripts/spec_helper.rb @@ -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 + diff --git a/spec/javascripts/test_spec.js b/spec/javascripts/test_spec.js new file mode 100644 index 0000000..8d22fd9 --- /dev/null +++ b/spec/javascripts/test_spec.js @@ -0,0 +1,5 @@ +describe("cats", function() { + it("should hiss", function() { + expect("hiss").toEqual("hiss"); + }); +});