diff --git a/bin/flowerbox b/bin/flowerbox index 115b49c..e06da8b 100755 --- a/bin/flowerbox +++ b/bin/flowerbox @@ -6,9 +6,10 @@ require 'thor' class Flowerbox::CLI < Thor desc "test DIR", "Run the specs found in spec dir, loading spec_helper.rb for configuration details" method_options :pwd => :string + method_options :runners => :string def test(dir) Dir.chdir(pwd) do - exit Flowerbox.run(dir) + exit Flowerbox.run(dir, options) end end diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index 0c5aa89..4b90d32 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -4,4 +4,4 @@ Flowerbox = xhr = new XMLHttpRequest() xhr.open("POST", Flowerbox.baseUrl + url, false) xhr.send(JSON.stringify(data)) - + fail: -> diff --git a/lib/assets/javascripts/flowerbox/jasmine.js.coffee b/lib/assets/javascripts/flowerbox/jasmine.js.coffee index 4af33f2..3a54ef4 100644 --- a/lib/assets/javascripts/flowerbox/jasmine.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine.js.coffee @@ -25,3 +25,8 @@ jasmine.Spec.beforeAddMatcherResult = -> jasmine.Spec.beforeAddMatcherResult().push (spec) -> @splitName = spec.getSpecSplitName() +Flowerbox.only = (envs..., code) -> + for env in envs + if Flowerbox.environment == env + describe("only in #{envs.join(', ')}", code) + diff --git a/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee b/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee index ac57c90..ca05f49 100644 --- a/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee @@ -9,3 +9,4 @@ jasmine.Spec.beforeAddMatcherResult().push -> Error.prepareStackTrace = Error.prepareStackTrace_ +Flowerbox.fail = -> process.exit(1) diff --git a/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee b/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee index c658d44..8c11af0 100644 --- a/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine/reporter.js.coffee @@ -5,6 +5,12 @@ class jasmine.FlowerboxReporter Flowerbox.contact("starting") reportSpecStarting: (spec) -> Flowerbox.contact("start_test", spec.description) + + if spec.description == 'encountered a declaration exception' + Flowerbox.contact("finish_test", spec.description, { trace: { stack: [ spec.description ] } }) + Flowerbox.contact("results", 0) + Flowerbox.fail() if Flowerbox.fail? + reportSpecResults: (spec) -> failures = [] diff --git a/lib/flowerbox.rb b/lib/flowerbox.rb index c87628e..053dd50 100644 --- a/lib/flowerbox.rb +++ b/lib/flowerbox.rb @@ -40,7 +40,7 @@ module Flowerbox end def run_with(*whats) - self.runner_environment = whats.collect { |what| Flowerbox::Runner.for(what) } + self.runner_environment = whats.flatten.collect { |what| Flowerbox::Runner.for(what.to_s) } end def path @@ -62,9 +62,13 @@ module Flowerbox @bare_coffeescript ||= true end - def run(dir) + def run(dir, options = {}) load File.join(dir, 'spec_helper.rb') + if options[:runners] + Flowerbox.run_with(options[:runners].split(',')) + end + require 'coffee_script' require 'tilt/coffee' @@ -73,7 +77,7 @@ module Flowerbox result_set = ResultSet.new Flowerbox.runner_environment.each do |env| - result_set << env.run(build_sprockets_for(dir)) + result_set << env.run(build_sprockets_for(dir), spec_files_for(dir)) end result_set.print @@ -95,8 +99,6 @@ module Flowerbox Flowerbox.test_environment.inject_into(sprockets) - spec_files_for(dir).each { |file| sprockets.add(file) } - sprockets end diff --git a/lib/flowerbox/exception.rb b/lib/flowerbox/exception.rb index 5b15fec..5ed78f1 100644 --- a/lib/flowerbox/exception.rb +++ b/lib/flowerbox/exception.rb @@ -1,13 +1,13 @@ module Flowerbox class Exception < Result - attr_reader :message + attr_reader :name - def initialize(message) - @message = message + def initialize(name) + @name = name end def print - puts message + puts "[#{runners.join(',')}] #{name}" puts end end diff --git a/lib/flowerbox/failure.rb b/lib/flowerbox/failure.rb index a5f851a..3e1c2f4 100644 --- a/lib/flowerbox/failure.rb +++ b/lib/flowerbox/failure.rb @@ -6,10 +6,6 @@ module Flowerbox @name, @message, @file = name, message, file end - def runners - @runners ||= [] - end - def ==(other) @name == other.name && @message == other.message end diff --git a/lib/flowerbox/rack.rb b/lib/flowerbox/rack.rb index 80bdb64..28b327e 100644 --- a/lib/flowerbox/rack.rb +++ b/lib/flowerbox/rack.rb @@ -28,7 +28,7 @@ module Flowerbox end empty_post '/start_test' do - runner.tests << data.flatten + runner.add_tests(data.flatten) end empty_post '/finish_test' do diff --git a/lib/flowerbox/result.rb b/lib/flowerbox/result.rb index 1efeb91..bd20686 100644 --- a/lib/flowerbox/result.rb +++ b/lib/flowerbox/result.rb @@ -1,6 +1,8 @@ module Flowerbox class Result - + def runners + @runners ||= [] + end end end diff --git a/lib/flowerbox/result_set.rb b/lib/flowerbox/result_set.rb index ae0c1dd..c99ebb0 100644 --- a/lib/flowerbox/result_set.rb +++ b/lib/flowerbox/result_set.rb @@ -9,7 +9,7 @@ module Flowerbox Failure.new(name, failure['message'], failure['trace']['stack'].first) end else - Exception.new(result_data['trace']['stack']) + Exception.new(result_data.first['trace']['stack']) end end.flatten diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 7c7db22..df5a40b 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -1,12 +1,13 @@ module Flowerbox module Runner class Base - attr_reader :sprockets + attr_reader :sprockets, :spec_files attr_accessor :time, :results - def run(sprockets) + def run(sprockets, spec_files) @sprockets = sprockets + @spec_files = spec_files puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{name}..." @@ -46,6 +47,10 @@ module Flowerbox @tests ||= [] end + def add_tests(new_tests) + tests << new_tests + end + def failures @failures ||= [] end diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index 0ab8a55..82abbef 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -13,7 +13,7 @@ module Flowerbox :node end - def run(sprockets) + def run(sprockets, spec_files) super do begin file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js") @@ -30,6 +30,7 @@ module Flowerbox env = start_test_environment <<-JS +// whoa node var fs = require('fs'), vm = require('vm'), http = require('http'), @@ -45,6 +46,8 @@ jsdom.env( context.window = window; context.XMLHttpRequest = xhr.XMLHttpRequest; + var gotFlowerbox = false; + var files = #{sprockets.files.to_json}; var fileRunner = function() { if (files.length > 0) { @@ -71,8 +74,11 @@ jsdom.env( if (!context[thing]) { context[thing] = window[thing] } } - if (context.Flowerbox) { + if (!gotFlowerbox && context.Flowerbox) { context.Flowerbox.baseUrl = "http://localhost:#{server.port}/"; + context.Flowerbox.environment = 'node'; + + gotFlowerbox = true; } fileRunner(); @@ -92,5 +98,3 @@ JS end end -Flowerbox.runner_environment = Flowerbox::Runner::Node.new - diff --git a/lib/flowerbox/runner/selenium.rb b/lib/flowerbox/runner/selenium.rb index 4934c86..b7cc2e1 100644 --- a/lib/flowerbox/runner/selenium.rb +++ b/lib/flowerbox/runner/selenium.rb @@ -13,7 +13,7 @@ module Flowerbox :selenium end - def run(sprockets) + def run(sprockets, spec_files) super do begin selenium = ::Selenium::WebDriver.for(browser) diff --git a/lib/flowerbox/test_environment/jasmine.rb b/lib/flowerbox/test_environment/jasmine.rb index 0ab1839..3171533 100644 --- a/lib/flowerbox/test_environment/jasmine.rb +++ b/lib/flowerbox/test_environment/jasmine.rb @@ -20,6 +20,8 @@ module Flowerbox @sprockets.add("flowerbox/jasmine") @sprockets.add("flowerbox/jasmine/#{runner.type}") + runner.spec_files.each { |file| @sprockets.add(file) } + case runner.type when :node <<-JS