still fllailing away

This commit is contained in:
John Bintz 2012-03-08 08:54:27 -05:00
parent 7a7c5debc4
commit fe51eda8a3
20 changed files with 5049 additions and 61 deletions

View File

@ -7,6 +7,7 @@ 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
method_options :verbose => false
def test(dir)
Dir.chdir(pwd) do
exit Flowerbox.run(dir, options)

View File

@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
gem.add_dependency 'thor'
gem.add_dependency 'selenium-webdriver'
gem.add_dependency 'sinatra'
gem.add_dependency 'rainbow'
end

View File

@ -12,13 +12,7 @@ class jasmine.FlowerboxReporter
Flowerbox.fail() if Flowerbox.fail?
reportSpecResults: (spec) ->
failures = []
for result in spec.results().getItems()
if result.type == 'expect' && !result.passed_
failures.push(result)
Flowerbox.contact("finish_test", spec.description, failures)
Flowerbox.contact("finish_test", spec.description, spec.results())
reportRunnerResults: (runner) ->
Flowerbox.contact("results", (new Date().getTime()) - @time)

View File

@ -1,5 +1,6 @@
require "flowerbox/version"
require 'flowerbox-delivery'
require 'rainbow'
module Flowerbox
autoload :Runner, 'flowerbox/runner'
@ -15,7 +16,9 @@ module Flowerbox
autoload :TestEnvironment, 'flowerbox/test_environment'
module TestEnvironment
autoload :Base, 'flowerbox/test_environment/base'
autoload :Jasmine, 'flowerbox/test_environment/jasmine'
autoload :Cucumber, 'flowerbox/test_environment/cucumber'
end
autoload :Rack, 'flowerbox/rack'
@ -23,6 +26,8 @@ module Flowerbox
autoload :ResultSet, 'flowerbox/result_set'
autoload :GatheredResult, 'flowerbox/gathered_result'
autoload :Result, 'flowerbox/result'
autoload :BaseResult, 'flowerbox/base_result'
autoload :Success, 'flowerbox/success'
autoload :Failure, 'flowerbox/failure'
autoload :Exception, 'flowerbox/exception'
@ -77,7 +82,7 @@ module Flowerbox
result_set = ResultSet.new
Flowerbox.runner_environment.each do |env|
result_set << env.run(build_sprockets_for(dir), spec_files_for(dir))
result_set << env.run(build_sprockets_for(dir), spec_files_for(dir), options)
end
result_set.print

View File

@ -0,0 +1,18 @@
module Flowerbox
class BaseResult < Result
attr_reader :name, :message, :file
def initialize(name, message, file = nil)
@name, @message, @file = name, message, file
end
def ==(other)
@name == other.name && @message == other.message
end
def to_s
"#{message} [#{runners.join(',')}] (#{translated_file}:#{line_number})"
end
end
end

View File

@ -1,17 +1,7 @@
module Flowerbox
class Failure < Result
attr_reader :name, :message, :file
def initialize(name, message, file)
@name, @message, @file = name, message, file
end
def ==(other)
@name == other.name && @message == other.message
end
def to_s
"#{message} [#{runners.join(',')}] (#{file})"
class Failure < BaseResult
def print_progress
print "F".foreground(:red)
end
end
end

View File

@ -14,6 +14,18 @@ module Flowerbox
@results ||= []
end
def successes
results.find_all(&:success?)
end
def failures
results.reject(&:success?)
end
def success?
@results.all?(&:success?)
end
def print
puts name.join(' ')

View File

@ -24,6 +24,10 @@ module Flowerbox
end
empty_post '/results' do
p "made it"
p data
runner.finish!(data.flatten.first)
end
@ -32,7 +36,7 @@ module Flowerbox
end
empty_post '/finish_test' do
runner.add_failures(data.flatten[1..-1])
runner.add_results(data.flatten[1..-1])
end
empty_post '/log' do

View File

@ -1,8 +1,46 @@
module Flowerbox
class Result
def <=>(other)
result = self.name.length <=> other.name.length
if result == 0
end
result
end
def runners
@runners ||= []
end
def translated_file
@translated_file ||= if actual_file_base = filename[%r{\.tmp/sprockets(.*)}, 1]
Dir[actual_file_base + "*"].first
else
filename
end
end
def file_translated?
translated_file != filename
end
def filename
file.split(":").first
end
def line_number
return @line_number if @line_number
@line_number = file.split(":").last
@line_number = "~#{@line_number}" if file_translated?
@line_number
end
def success?
false
end
end
end

View File

@ -2,14 +2,19 @@ module Flowerbox
class ResultSet
attr_reader :results, :options
def self.from_failures(failures, options)
results = failures.collect do |result_data|
if name = result_data.first['splitName']
result_data.collect do |failure|
Failure.new(name, failure['message'], failure['trace']['stack'].first)
attr_accessor :time
def self.from_results(results, options)
results = results['items_'].collect do |result|
if name = result['splitName']
case result['passed_']
when true
Success.new(name, result['message'])
else
Failure.new(name, result['message'], result['trace']['stack'].first)
end
else
Exception.new(result_data.first['trace']['stack'])
Exception.new(result.first['trace']['stack'])
end
end.flatten
@ -18,6 +23,10 @@ module Flowerbox
new(results, options)
end
def self.for(runner)
new(results, :runner => runner)
end
def initialize(results = [], options = {})
@results, @options = results, options
end
@ -38,6 +47,20 @@ module Flowerbox
def print
gathered_results.each(&:print)
puts "#{total_tests} total, #{total_failures} failures, #{time} secs."
end
def total_tests
results.length
end
def total_failures
results.reject(&:success?).length
end
def print_progress
@results.each { |result| result.print_progress ; $stdout.flush }
end
def gathered_results

View File

@ -1,15 +1,18 @@
module Flowerbox
module Runner
class Base
attr_reader :sprockets, :spec_files
attr_reader :sprockets, :spec_files, :options
attr_accessor :time, :results
attr_accessor :results
def run(sprockets, spec_files)
@sprockets = sprockets
@spec_files = spec_files
def initialize
@results = ResultSet.new
end
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{name}..."
def run(sprockets, spec_files, options)
@sprockets, @spec_files, @options = sprockets, spec_files, options
puts "Flowerbox running your #{Flowerbox.test_environment.name} tests on #{console_name}..."
server.start
@ -17,9 +20,10 @@ module Flowerbox
server.stop
puts
puts
ResultSet.from_failures(failures, :runner => name, :time => time)
@results
end
def type
@ -30,6 +34,11 @@ module Flowerbox
Flowerbox.test_environment.start_for(self)
end
def time=(time)
p time
@results.time = time
end
def server
return @server if @server
@ -55,16 +64,12 @@ module Flowerbox
@failures ||= []
end
def add_failures(test_failures)
if test_failures.length == 0
print '.'
else
print 'F'
end
def add_results(test_results)
results = result_set_from_test_results(test_results)
$stdout.flush
results.print_progress
failures << test_failures
@results << results
end
def total_count
@ -84,6 +89,11 @@ module Flowerbox
def finished?
@finished
end
private
def result_set_from_test_results(test_results)
ResultSet.from_results(test_results.first, options.merge(:runner => name))
end
end
end
end

View File

@ -3,6 +3,15 @@ class Flowerbox::Runner::Chrome < Flowerbox::Runner::Selenium
"Chrome"
end
def console_name
"C".foreground('#4f97d1') +
"h".foreground('#ec5244') +
"r".foreground('#fdd901') +
"o".foreground('#4f97d1') +
"m".foreground('#5cb15b') +
"e".foreground('#ec5244')
end
def browser
:chrome
end

View File

@ -3,6 +3,10 @@ class Flowerbox::Runner::Firefox < Flowerbox::Runner::Selenium
"Firefox"
end
def console_name
"Firefox".foreground('#d0450b')
end
def browser
:firefox
end

View File

@ -6,14 +6,21 @@ module Flowerbox
module Runner
class Node < Base
def name
"Node.js"
"node.js"
end
def console_name
"n".foreground(:white) +
"o".foreground('#8cc84b') +
"de".foreground(:white) +
".js".foreground('#8cc84b')
end
def type
:node
end
def run(sprockets, spec_files)
def run(sprockets, spec_files, options)
super do
begin
file = File.join(Dir.pwd, ".node-tmp.#{Time.now.to_i}.js")

View File

@ -13,13 +13,15 @@ module Flowerbox
:selenium
end
def run(sprockets, spec_files)
def run(sprockets, spec_files, options)
super do
begin
selenium = ::Selenium::WebDriver.for(browser)
selenium.navigate.to "http://localhost:#{server.port}/"
sleep 10
@count = 0
while @count < MAX_COUNT && !finished?

12
lib/flowerbox/success.rb Normal file
View File

@ -0,0 +1,12 @@
module Flowerbox
class Success < BaseResult
def print_progress
print ".".foreground(:green)
end
def success?
true
end
end
end

View File

@ -0,0 +1,14 @@
module Flowerbox
module TestEnvironment
class Base
def name
self.class.name.split("::").last
end
def reporters
@reporters ||= []
end
end
end
end

View File

@ -0,0 +1,34 @@
module Flowerbox
module TestEnvironment
class Cucumber
def inject_into(sprockets)
@sprockets = sprockets
@sprockets.add('cucumber.js')
end
def start_for(runner)
@sprockets.add("flowerbox/cucumber")
@sprockets.add("flowerbox/cucumber/#{runner.type}")
runner.spec_files.each { |file| @sprockets.add(file) }
<<-JS
if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
jasmine = context.jasmine;
}
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
#{jasmine_reporters.join("\n")}
jasmine.getEnv().execute();
JS
end
def jasmine_reporters
reporters.collect { |reporter| %{jasmine.getEnv().addReporter(new jasmine.#{reporter}());} }
end
end
end
end

View File

@ -2,10 +2,7 @@ require 'jasmine-core'
module Flowerbox
module TestEnvironment
class Jasmine
def name
self.class.name.split("::").last
end
class Jasmine < Base
def inject_into(sprockets)
@sprockets = sprockets
@ -22,20 +19,15 @@ module Flowerbox
runner.spec_files.each { |file| @sprockets.add(file) }
case runner.type
when :node
<<-JS
var jasmine = context.jasmine;
<<-JS
if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
jasmine = context.jasmine;
}
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
#{jasmine_reporters.join("\n")}
jasmine.getEnv().execute();
JS
when :selenium
<<-JS
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
jasmine.getEnv().execute();
JS
end
end
def jasmine_reporters
@ -43,7 +35,7 @@ JS
end
def reporters
@reporters ||= [ 'FlowerboxReporter' ]
@reporters ||= []
end
end
end

4818
vendor/assets/javascripts/cucumber.js vendored Normal file

File diff suppressed because it is too large Load Diff