From a5ed377e13472ac85c65180dd40cd16b3bfde463 Mon Sep 17 00:00:00 2001 From: Derek Ekins Date: Mon, 18 Jul 2011 17:14:41 +0100 Subject: [PATCH] improved the way that cucumber is called no longer relying on internal api --- lib/hydra/cucumber/partial_html.rb | 1 + lib/hydra/listener/cucumber_html_report.rb | 2 +- lib/hydra/runner.rb | 81 +++++++++------------- lib/hydra/worker.rb | 3 - 4 files changed, 33 insertions(+), 54 deletions(-) diff --git a/lib/hydra/cucumber/partial_html.rb b/lib/hydra/cucumber/partial_html.rb index 3b06a25..fcbb3e3 100644 --- a/lib/hydra/cucumber/partial_html.rb +++ b/lib/hydra/cucumber/partial_html.rb @@ -3,6 +3,7 @@ require 'cucumber/formatter/html' module Hydra module Formatter class PartialHtml < Cucumber::Formatter::Html + def before_features(features) # we do not want the default implementation as we will write our own header end diff --git a/lib/hydra/listener/cucumber_html_report.rb b/lib/hydra/listener/cucumber_html_report.rb index 61349dd..a2f43d2 100644 --- a/lib/hydra/listener/cucumber_html_report.rb +++ b/lib/hydra/listener/cucumber_html_report.rb @@ -33,7 +33,7 @@ module Hydra #:nodoc: def combine_features wait_for_two_seconds_while_files_are_written - Dir.glob(File.join(@results_path, 'features/*.html')).each do |feature| + Dir.glob(File.join(@results_path, 'features/*.html')).sort.each do |feature| File.open( feature, "rb") do |f| f.each_line do |line| @builder << line diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index 155f2ad..fe4d6d5 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -146,53 +146,45 @@ module Hydra #:nodoc: # run all the scenarios in a cucumber feature file def run_cucumber_file(file) - - files = [file] - dev_null = StringIO.new hydra_response = StringIO.new + hydra_response.puts file - unless @cuke_runtime - require 'cucumber' + options = @options if @options.is_a?(Array) + options = @options.split(' ') if @options.is_a?(String) + + fork_id = fork do + files = [file] + dev_null = StringIO.new + + args = [file, options].flatten.compact + hydra_response.puts args.inspect + + results_directory = "#{Dir.pwd}/results/features" + FileUtils.mkdir_p results_directory + + require 'cucumber/cli/main' require 'hydra/cucumber/formatter' require 'hydra/cucumber/partial_html' + Cucumber.logger.level = Logger::INFO - @cuke_runtime = Cucumber::Runtime.new - @cuke_configuration = Cucumber::Cli::Configuration.new(dev_null, dev_null) - @cuke_configuration.parse!(['features']+files+[@options]) + cuke = Cucumber::Cli::Main.new(args, hydra_response, hydra_response) + #cuke.configuration.formats.clear + cuke.configuration.formats << ['Cucumber::Formatter::Hydra', hydra_response] - support_code = Cucumber::Runtime::SupportCode.new(@cuke_runtime, @cuke_configuration.guess?) - support_code.load_files!(@cuke_configuration.support_to_load + @cuke_configuration.step_defs_to_load) - support_code.fire_hook(:after_configuration, @cuke_configuration) - # i don't like this, but there no access to set the instance of SupportCode in Runtime - @cuke_runtime.instance_variable_set('@support_code',support_code) + html_output = cuke.configuration.formats.select{|format| format[0] == 'html'} + if html_output + cuke.configuration.formats.delete(html_output) + cuke.configuration.formats << ['Hydra::Formatter::PartialHtml', "#{results_directory}/#{file.split('/').last}.html"] + end + + cuke_runtime = Cucumber::Runtime.new(cuke.configuration) + cuke_runtime.run! + + hydra_response.rewind end - cuke_formatter = Cucumber::Formatter::Hydra.new( - @cuke_runtime, hydra_response, @cuke_configuration.options - ) - results_directory = "#{Dir.pwd}/results/features" - FileUtils.mkdir_p results_directory - html_formatter = Hydra::Formatter::PartialHtml.new( - @cuke_runtime, "#{results_directory}/#{file.split('/').last}#{Time.now.strftime('%H%M%S')}.html", @cuke_configuration.options - ) + Process.wait fork_id - cuke_runner ||= Cucumber::Ast::TreeWalker.new( - @cuke_runtime, [cuke_formatter, html_formatter], @cuke_configuration - ) - @cuke_runtime.visitor = cuke_runner - - loader = Cucumber::Runtime::FeaturesLoader.new( - files, - @cuke_configuration.filters, - @cuke_configuration.tag_expression - ) - features = loader.features - tag_excess = tag_excess(features, @cuke_configuration.options[:tag_expression].limits) - @cuke_configuration.options[:tag_excess] = tag_excess - - cuke_runner.visit_features(features) - - hydra_response.rewind return hydra_response.read end @@ -260,17 +252,6 @@ module Hydra #:nodoc: end return klasses.select{|k| k.respond_to? 'suite'} end - - # Yanked a method from Cucumber - def tag_excess(features, limits) - limits.map do |tag_name, tag_limit| - tag_locations = features.tag_locations(tag_name) - if tag_limit && (tag_locations.length > tag_limit) - [tag_name, tag_limit, tag_locations] - else - nil - end - end.compact - end end end + diff --git a/lib/hydra/worker.rb b/lib/hydra/worker.rb index 93df440..f949d62 100644 --- a/lib/hydra/worker.rb +++ b/lib/hydra/worker.rb @@ -80,13 +80,10 @@ module Hydra #:nodoc: def boot_runners(num_runners) #:nodoc: trace "Booting #{num_runners} Runners" - ports = [7055, 7056] num_runners.times do - port = ports.shift pipe = Hydra::Pipe.new child = SafeFork.fork do - ENV['port'] = port.to_s pipe.identify_as_child Hydra::Runner.new(:io => pipe, :verbose => @verbose, :options => @options) end