a ton more cowboy hacking
This commit is contained in:
parent
a39daffdbb
commit
7a7c5debc4
@ -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
|
||||
|
||||
|
@ -4,4 +4,4 @@ Flowerbox =
|
||||
xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", Flowerbox.baseUrl + url, false)
|
||||
xhr.send(JSON.stringify(data))
|
||||
|
||||
fail: ->
|
||||
|
@ -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)
|
||||
|
||||
|
@ -9,3 +9,4 @@ jasmine.Spec.beforeAddMatcherResult().push ->
|
||||
|
||||
Error.prepareStackTrace = Error.prepareStackTrace_
|
||||
|
||||
Flowerbox.fail = -> process.exit(1)
|
||||
|
@ -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 = []
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,8 @@
|
||||
module Flowerbox
|
||||
class Result
|
||||
|
||||
def runners
|
||||
@runners ||= []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -13,7 +13,7 @@ module Flowerbox
|
||||
:selenium
|
||||
end
|
||||
|
||||
def run(sprockets)
|
||||
def run(sprockets, spec_files)
|
||||
super do
|
||||
begin
|
||||
selenium = ::Selenium::WebDriver.for(browser)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user