diff --git a/lib/assets/javascripts/flowerbox/cucumber.js.coffee b/lib/assets/javascripts/flowerbox/cucumber.js.coffee index 5c833f8..4de13eb 100644 --- a/lib/assets/javascripts/flowerbox/cucumber.js.coffee +++ b/lib/assets/javascripts/flowerbox/cucumber.js.coffee @@ -39,20 +39,6 @@ Flowerbox.World -> Flowerbox.Matcher.matchers = {} @addMatchers(Flowerbox.Matchers) - if Flowerbox.Cucumber.tags - negatedTags = [] - for tagSet in Flowerbox.Cucumber.tags - tags = for tag in tagSet.split(',') - if tag.substr(0, 1) == '@' - "~" + tag - else - tag.substr(1) - - negatedTags.push(tags) - - @around (negatedTags..., runScenario) -> - - class Flowerbox.Matcher @addMatchers: (data) -> for method, code of data @@ -106,15 +92,20 @@ Flowerbox.Step.matchFile = (name) -> stepGenerator = (type) -> Flowerbox[type] = (match, code) -> if !Flowerbox.Step.files[match.toString()] - count = 2 + nextLine = false if stack = (new Error()).stack for line in stack.split('\n') - if line.match(/__F__/) - count -= 1 + if nextLine + result = if line.match(/__F__/) + line.replace(/^.*__F__\/([^:]+:\d+).*$/, '$1') + else + line.replace(/^.*(\(| )([^:]+:\d+).*$/, '$2') - if count == 0 - Flowerbox.Step.files[match.toString()] = [ match, line.replace(/^.*__F__/, '') ] - break + Flowerbox.Step.files[match.toString()] = [ match, result ] + break + + if line.match(/(Given|When|Then)/) + nextLine = true Flowerbox.Step(type, match, code) diff --git a/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee b/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee index 79e74db..95a88da 100644 --- a/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee +++ b/lib/assets/javascripts/flowerbox/jasmine/node.js.coffee @@ -1,12 +1,5 @@ jasmine.Spec.beforeAddMatcherResult().push -> if !@passed_ - Error.prepareStackTrace_ = Error.prepareStackTrace - Error.prepareStackTrace = (err, stack) -> stack - - errorInfo = new Error().stack[3] - - @trace = { stack: "#{errorInfo.getFileName()}:#{errorInfo.getLineNumber()}" } - - Error.prepareStackTrace = Error.prepareStackTrace_ + @trace = { stack: new Error().stack } Flowerbox.fail = -> process.exit(1) diff --git a/lib/flowerbox/result/failure_message.rb b/lib/flowerbox/result/failure_message.rb index 67b2548..8a06b01 100644 --- a/lib/flowerbox/result/failure_message.rb +++ b/lib/flowerbox/result/failure_message.rb @@ -13,7 +13,7 @@ module Flowerbox::Result end def file - first_local_stack[%r{__F__/(.*)$}, 1] + first_local_stack[%r{\(([^:]+\:\d+)}, 1] end def runner @@ -25,7 +25,9 @@ module Flowerbox::Result end def first_local_stack - @data['stack'].find { |line| line['__F__'] } || @data['stack'][1] + @data['stack'][1..-1].find do |line| + !system_files.any? { |file| line[%r{\(#{file}}] } + end || @data['stack'][1] end end end diff --git a/lib/flowerbox/result/file_info.rb b/lib/flowerbox/result/file_info.rb index 287628b..1859d99 100644 --- a/lib/flowerbox/result/file_info.rb +++ b/lib/flowerbox/result/file_info.rb @@ -28,5 +28,9 @@ module Flowerbox::Result::FileInfo def translated_file_and_line "#{translated_file.gsub(%r{^/}, '')}:#{line_number}" end + + def system_files + Flowerbox.test_environment.system_files + end end diff --git a/lib/flowerbox/run/base.rb b/lib/flowerbox/run/base.rb index 90d59ec..189fde5 100644 --- a/lib/flowerbox/run/base.rb +++ b/lib/flowerbox/run/base.rb @@ -28,11 +28,12 @@ module Flowerbox::Run Flowerbox.run_with(runners.split(',')) end + Flowerbox.test_environment.run = self Flowerbox.test_environment.set_additional_options(options[:env_options]) end def sprockets - sprockets = Flowerbox::Delivery::SprocketsHandler.new( + Flowerbox::Delivery::SprocketsHandler.new( :asset_paths => [ Flowerbox.path.join("lib/assets/javascripts"), Flowerbox.path.join("vendor/assets/javascripts"), @@ -40,15 +41,6 @@ module Flowerbox::Run Flowerbox.asset_paths ].flatten ) - - sprockets.add('flowerbox') - sprockets.add('json2') - - Flowerbox.test_environment.inject_into(sprockets) - - Flowerbox.additional_files.each { |file| sprockets.add(file) } - - sprockets end def spec_files @@ -74,6 +66,10 @@ module Flowerbox::Run @only = nil if only.empty? @only end + + def system_files + %w{flowerbox json2} + end end end diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 7fc5bdc..8379448 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -20,6 +20,10 @@ module Flowerbox def setup(sprockets, spec_files, options) @sprockets, @spec_files, @options = sprockets, spec_files, options + + Flowerbox.test_environment.runner = self + Flowerbox.test_environment.inject_into(sprockets) + Flowerbox.additional_files.each { |file| sprockets.add(file) } end def run(*args) @@ -61,7 +65,7 @@ module Flowerbox end def start_test_environment - Flowerbox.test_environment.start_for(self) + Flowerbox.test_environment.start end def time=(time) diff --git a/lib/flowerbox/runner/node.rb b/lib/flowerbox/runner/node.rb index 07ed0b1..e642895 100644 --- a/lib/flowerbox/runner/node.rb +++ b/lib/flowerbox/runner/node.rb @@ -107,6 +107,12 @@ jsdom.env( request.end(); } else { #{env} + + var waitForFinish; + waitForFinish = function() { + if (context.Flowerbox.working) { process.nextTick(waitForFinish); } + }; + waitForFinish(); } }; fileRunner(); diff --git a/lib/flowerbox/test_environment/base.rb b/lib/flowerbox/test_environment/base.rb index d371db5..bc8cc3a 100644 --- a/lib/flowerbox/test_environment/base.rb +++ b/lib/flowerbox/test_environment/base.rb @@ -3,6 +3,8 @@ require 'yaml' module Flowerbox module TestEnvironment class Base + attr_accessor :runner, :run + def name self.class.name.split("::").last end @@ -25,6 +27,20 @@ module Flowerbox @options[:tags] = [ @options[:tags] ].flatten(1) if @options[:tags] end end + + def inject_into(sprockets) + @sprockets = sprockets + + system_files.each { |file| @sprockets.add(file) } + end + + def system_files + run.system_files + global_system_files + runner_system_files + end + + def start + runner.spec_files.each { |file| @sprockets.add(file) } + end end end end diff --git a/lib/flowerbox/test_environment/cucumber.rb b/lib/flowerbox/test_environment/cucumber.rb index af6b5db..c0ba320 100644 --- a/lib/flowerbox/test_environment/cucumber.rb +++ b/lib/flowerbox/test_environment/cucumber.rb @@ -4,26 +4,27 @@ module Flowerbox def initialize @step_language = nil end - + def prefer_step_language(language) @step_language = language end def inject_into(sprockets) - @sprockets = sprockets + super @sprockets.register_engine('.feature', Flowerbox::Delivery::Tilt::FeatureTemplate) - - @sprockets.add('cucumber.js') end - def start_for(runner) - @runner = runner + def global_system_files + %w{cucumber.js flowerbox/cucumber} + end - @sprockets.add("flowerbox/cucumber") - @sprockets.add("flowerbox/cucumber/#{runner.type}") + def runner_system_files + [ "flowerbox/cucumber/#{@runner.type}" ] + end - @runner.spec_files.each { |file| @sprockets.add(file) } + def start + super <<-JS context.Cucumber = context.require('./cucumber'); diff --git a/lib/flowerbox/test_environment/jasmine.rb b/lib/flowerbox/test_environment/jasmine.rb index 4c42203..6bfadd0 100644 --- a/lib/flowerbox/test_environment/jasmine.rb +++ b/lib/flowerbox/test_environment/jasmine.rb @@ -3,21 +3,22 @@ require 'jasmine-core' module Flowerbox module TestEnvironment class Jasmine < Base - def inject_into(sprockets) - @sprockets = sprockets + sprockets.append_path(::Jasmine::Core.path) - @sprockets.append_path(::Jasmine::Core.path) - - @sprockets.add('jasmine.js') - @sprockets.add('jasmine-html.js') + super end - def start_for(runner) - @sprockets.add("flowerbox/jasmine.js") - @sprockets.add("flowerbox/jasmine/#{runner.type}.js") + def global_system_files + %w{jasmine.js flowerbox/jasmine.js} + end - runner.spec_files.each { |file| @sprockets.add(file) } + def runner_system_files + [ "flowerbox/jasmine/#{@runner.type}.js" ] + end + + def start + super <<-JS if (typeof context != 'undefined' && typeof jasmine == 'undefined') {