reeeeealy basic cucumber support
This commit is contained in:
parent
e9212c6743
commit
bbc95564f1
@ -3,5 +3,6 @@ Flowerbox =
|
|||||||
contact: (url, data...) ->
|
contact: (url, data...) ->
|
||||||
xhr = new XMLHttpRequest()
|
xhr = new XMLHttpRequest()
|
||||||
xhr.open("POST", Flowerbox.baseUrl + url, false)
|
xhr.open("POST", Flowerbox.baseUrl + url, false)
|
||||||
|
xhr.setRequestHeader("Accept", "application/json")
|
||||||
xhr.send(JSON.stringify(data))
|
xhr.send(JSON.stringify(data))
|
||||||
fail: ->
|
fail: ->
|
||||||
|
55
lib/assets/javascripts/flowerbox/cucumber.js.coffee
Normal file
55
lib/assets/javascripts/flowerbox/cucumber.js.coffee
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#= require flowerbox/cucumber/reporter
|
||||||
|
|
||||||
|
Flowerbox.Cucumber ||= {}
|
||||||
|
Flowerbox.Cucumber.features = ->
|
||||||
|
Flowerbox.Cucumber.Features ||= []
|
||||||
|
Flowerbox.Cucumber.Features.join("\n")
|
||||||
|
|
||||||
|
Flowerbox.World = (code = null) ->
|
||||||
|
->
|
||||||
|
for code in (Flowerbox.World.Code || [])
|
||||||
|
code.apply(this)
|
||||||
|
|
||||||
|
Flowerbox.Step = (type, match, code) ->
|
||||||
|
Flowerbox.World.Code ||= []
|
||||||
|
Flowerbox.World.Code.push (args..., callback) ->
|
||||||
|
this[type] match, (args..., callback) ->
|
||||||
|
|
||||||
|
pending = false
|
||||||
|
|
||||||
|
this.pending = -> pending = true
|
||||||
|
|
||||||
|
result = code.apply(this)
|
||||||
|
|
||||||
|
if result? and result.__prototype__ == Error
|
||||||
|
callback.fail(result)
|
||||||
|
else
|
||||||
|
if pending then callback.pending("pending") else callback()
|
||||||
|
|
||||||
|
null
|
||||||
|
|
||||||
|
Flowerbox.Step.files ||= {}
|
||||||
|
Flowerbox.Step.matchFile = (name) ->
|
||||||
|
for key, data of Flowerbox.Step.files
|
||||||
|
[ regexp, filename ] = data
|
||||||
|
if name.match(regexp)
|
||||||
|
return filename
|
||||||
|
|
||||||
|
null
|
||||||
|
|
||||||
|
stepGenerator = (type) ->
|
||||||
|
Flowerbox[type] = (match, code) ->
|
||||||
|
if !Flowerbox.Step.files[match.toString()]
|
||||||
|
count = 2
|
||||||
|
for line in (new Error()).stack.split('\n')
|
||||||
|
if line.match(/__F__/)
|
||||||
|
count -= 1
|
||||||
|
|
||||||
|
if count == 0
|
||||||
|
Flowerbox.Step.files[match.toString()] = [ match, line.replace(/^.*__F__/, '') ]
|
||||||
|
break
|
||||||
|
|
||||||
|
Flowerbox.Step(type, match, code)
|
||||||
|
|
||||||
|
stepGenerator(type) for type in [ 'Given', 'When', 'Then' ]
|
||||||
|
|
65
lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee
Normal file
65
lib/assets/javascripts/flowerbox/cucumber/reporter.js.coffee
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
Flowerbox ||= {}
|
||||||
|
Flowerbox.Cucumber ||= {}
|
||||||
|
|
||||||
|
class Flowerbox.Cucumber.Reporter
|
||||||
|
hear: (event, callback) ->
|
||||||
|
switch event.getName()
|
||||||
|
when 'BeforeFeatures'
|
||||||
|
@time = (new Date()).getTime()
|
||||||
|
|
||||||
|
Flowerbox.contact("starting")
|
||||||
|
|
||||||
|
when 'AfterFeatures'
|
||||||
|
Flowerbox.contact("results", (new Date()).getTime() - @time)
|
||||||
|
|
||||||
|
when 'BeforeFeature'
|
||||||
|
@feature = event.getPayloadItem('feature')
|
||||||
|
|
||||||
|
when 'BeforeScenario'
|
||||||
|
@scenario = event.getPayloadItem('scenario')
|
||||||
|
|
||||||
|
when 'BeforeStep'
|
||||||
|
@step = event.getPayloadItem('step')
|
||||||
|
|
||||||
|
Flowerbox.contact("start_test", @step.getName())
|
||||||
|
|
||||||
|
when 'StepResult'
|
||||||
|
stepResult = event.getPayloadItem('stepResult')
|
||||||
|
|
||||||
|
type = "Given"
|
||||||
|
|
||||||
|
if @step.isOutcomeStep()
|
||||||
|
type = "Then"
|
||||||
|
else if @step.isEventStep()
|
||||||
|
type = "When"
|
||||||
|
|
||||||
|
file = Flowerbox.Step.matchFile(@step.getName()) || "unknown:0"
|
||||||
|
|
||||||
|
test = { passed_: false, message: 'skipped', splitName: [ @feature.getName(), @scenario.getName(), "#{type} #{@step.getName()}" ], trace: { stack: [ file ] } }
|
||||||
|
|
||||||
|
if stepResult.isSuccessful()
|
||||||
|
test.passed_ = true
|
||||||
|
else if stepResult.isPending()
|
||||||
|
test.message = "pending"
|
||||||
|
else if stepResult.isUndefined()
|
||||||
|
regexp = @step.getName()
|
||||||
|
regexp = regexp.replace(/"[^"]+"/g, '"([^"]+)"')
|
||||||
|
|
||||||
|
test.message = """
|
||||||
|
Step not defined. Define it with the following:
|
||||||
|
|
||||||
|
Flowerbox.#{type} /^#{regexp}$/, ->
|
||||||
|
@pending()
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
else if stepResult.isFailed()
|
||||||
|
error = stepResult.getFailureException()
|
||||||
|
|
||||||
|
test.message = error.message
|
||||||
|
test.trace.stack = [ 'file:1' ]
|
||||||
|
|
||||||
|
Flowerbox.contact("finish_test", @step.getName(), [ { items_: [ test ] } ])
|
||||||
|
|
||||||
|
callback()
|
||||||
|
|
22
lib/flowerbox/delivery/tilt/feature_template.rb
Normal file
22
lib/flowerbox/delivery/tilt/feature_template.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'tilt'
|
||||||
|
|
||||||
|
module Flowerbox::Delivery::Tilt
|
||||||
|
class FeatureTemplate < Tilt::Template
|
||||||
|
self.default_mime_type = 'application/javascript'
|
||||||
|
|
||||||
|
def prepare; end
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
<<-JS
|
||||||
|
Flowerbox.Cucumber.Features = Flowerbox.Cucumber.Features || [];
|
||||||
|
|
||||||
|
Flowerbox.Cucumber.Features.push("#{escaped_data}");
|
||||||
|
JS
|
||||||
|
end
|
||||||
|
|
||||||
|
def escaped_data
|
||||||
|
data.gsub("\n", "\\n").gsub('"', '\\"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,7 +1,30 @@
|
|||||||
module Flowerbox
|
module Flowerbox
|
||||||
class Failure < BaseResult
|
class Failure < BaseResult
|
||||||
|
def pending?
|
||||||
|
message == "pending"
|
||||||
|
end
|
||||||
|
|
||||||
|
def skipped?
|
||||||
|
message == "skipped"
|
||||||
|
end
|
||||||
|
|
||||||
|
def undefined?
|
||||||
|
message[%r{^Step not defined}]
|
||||||
|
end
|
||||||
|
|
||||||
def print_progress
|
def print_progress
|
||||||
print "F".foreground(:red)
|
case message
|
||||||
|
when "pending"
|
||||||
|
print "P".foreground(:yellow)
|
||||||
|
when "skipped"
|
||||||
|
print "-".foreground(:cyan)
|
||||||
|
else
|
||||||
|
if undefined?
|
||||||
|
print "U".foreground(:yellow)
|
||||||
|
else
|
||||||
|
print "F".foreground(:red)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require 'sinatra'
|
require 'sinatra'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Flowerbox
|
module Flowerbox
|
||||||
class Rack < Sinatra::Base
|
class Rack < Sinatra::Base
|
||||||
|
@ -27,13 +27,13 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
file.split(":").first
|
file.to_s.split(":").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def line_number
|
def line_number
|
||||||
return @line_number if @line_number
|
return @line_number if @line_number
|
||||||
|
|
||||||
@line_number = file.split(":").last
|
@line_number = file.to_s.split(":").last
|
||||||
@line_number = "~#{@line_number}" if file_translated?
|
@line_number = "~#{@line_number}" if file_translated?
|
||||||
@line_number
|
@line_number
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,6 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def time=(time)
|
def time=(time)
|
||||||
p time
|
|
||||||
@results.time = time
|
@results.time = time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,11 +22,12 @@ module Flowerbox
|
|||||||
|
|
||||||
def configured?
|
def configured?
|
||||||
File.directory?(File.join(Dir.pwd, 'node_modules/jsdom')) &&
|
File.directory?(File.join(Dir.pwd, 'node_modules/jsdom')) &&
|
||||||
File.directory?(File.join(Dir.pwd, 'node_modules/XMLHttpRequest'))
|
File.directory?(File.join(Dir.pwd, 'node_modules/XMLHttpRequest')) &&
|
||||||
|
File.directory?(File.join(Dir.pwd, 'node_modules/cucumber'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure
|
def configure
|
||||||
system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link xmlhttprequest"}
|
system %{bash -c "mkdir -p node_modules && npm link jsdom && npm link xmlhttprequest && npm link cucumber"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(sprockets, spec_files, options)
|
def run(sprockets, spec_files, options)
|
||||||
|
@ -20,8 +20,6 @@ module Flowerbox
|
|||||||
|
|
||||||
selenium.navigate.to "http://localhost:#{server.port}/"
|
selenium.navigate.to "http://localhost:#{server.port}/"
|
||||||
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
@count = 0
|
@count = 0
|
||||||
|
|
||||||
while @count < MAX_COUNT && !finished?
|
while @count < MAX_COUNT && !finished?
|
||||||
@ -44,7 +42,7 @@ module Flowerbox
|
|||||||
<<-HTML
|
<<-HTML
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Flowerbox - Selenium Runner</title>
|
<title>Flowerbox - #{Flowerbox.test_environment.name} Runner</title>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
console._log = console.log;
|
console._log = console.log;
|
||||||
|
|
||||||
@ -56,10 +54,12 @@ console.log = function(msg) {
|
|||||||
#{template_files.join("\n")}
|
#{template_files.join("\n")}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Flowerbox - Selenium Runner</h1>
|
<h1>Flowerbox - #{Flowerbox.test_environment.name} Runner</h1>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Flowerbox.environment = '#{browser}';
|
Flowerbox.environment = '#{browser}';
|
||||||
|
|
||||||
|
var context = this;
|
||||||
|
|
||||||
#{env}
|
#{env}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
module Flowerbox
|
module Flowerbox
|
||||||
module TestEnvironment
|
module TestEnvironment
|
||||||
class Cucumber
|
class Cucumber < Base
|
||||||
def inject_into(sprockets)
|
def inject_into(sprockets)
|
||||||
@sprockets = sprockets
|
@sprockets = sprockets
|
||||||
|
|
||||||
|
@sprockets.register_engine('.feature', Flowerbox::Delivery::Tilt::FeatureTemplate)
|
||||||
|
|
||||||
@sprockets.add('cucumber.js')
|
@sprockets.add('cucumber.js')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -14,21 +16,18 @@ module Flowerbox
|
|||||||
runner.spec_files.each { |file| @sprockets.add(file) }
|
runner.spec_files.each { |file| @sprockets.add(file) }
|
||||||
|
|
||||||
<<-JS
|
<<-JS
|
||||||
if (typeof context != 'undefined' && typeof jasmine == 'undefined') {
|
context.Cucumber = context.require('./cucumber');
|
||||||
jasmine = context.jasmine;
|
|
||||||
}
|
|
||||||
|
|
||||||
jasmine.getEnv().addReporter(new jasmine.FlowerboxReporter());
|
context.cucumber = context.Cucumber(context.Flowerbox.Cucumber.features(), context.Flowerbox.World());
|
||||||
#{jasmine_reporters.join("\n")}
|
context.cucumber.attachListener(new context.Flowerbox.Cucumber.Reporter());
|
||||||
jasmine.getEnv().execute();
|
context.cucumber.start(function() {});
|
||||||
JS
|
JS
|
||||||
end
|
end
|
||||||
|
|
||||||
def jasmine_reporters
|
|
||||||
reporters.collect { |reporter| %{jasmine.getEnv().addReporter(new jasmine.#{reporter}());} }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Flowerbox::Delivery::Tilt
|
||||||
|
autoload :FeatureTemplate, 'flowerbox/delivery/tilt/feature_template'
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user