improved the way that cucumber is called

no longer relying on internal api
This commit is contained in:
Derek Ekins 2011-07-18 17:14:41 +01:00
parent 455fa3674f
commit a5ed377e13
4 changed files with 33 additions and 54 deletions

View File

@ -3,6 +3,7 @@ require 'cucumber/formatter/html'
module Hydra module Hydra
module Formatter module Formatter
class PartialHtml < Cucumber::Formatter::Html class PartialHtml < Cucumber::Formatter::Html
def before_features(features) def before_features(features)
# we do not want the default implementation as we will write our own header # we do not want the default implementation as we will write our own header
end end

View File

@ -33,7 +33,7 @@ module Hydra #:nodoc:
def combine_features def combine_features
wait_for_two_seconds_while_files_are_written 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| File.open( feature, "rb") do |f|
f.each_line do |line| f.each_line do |line|
@builder << line @builder << line

View File

@ -146,53 +146,45 @@ module Hydra #:nodoc:
# run all the scenarios in a cucumber feature file # run all the scenarios in a cucumber feature file
def run_cucumber_file(file) def run_cucumber_file(file)
files = [file]
dev_null = StringIO.new
hydra_response = StringIO.new hydra_response = StringIO.new
hydra_response.puts file
unless @cuke_runtime options = @options if @options.is_a?(Array)
require 'cucumber' 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/formatter'
require 'hydra/cucumber/partial_html' require 'hydra/cucumber/partial_html'
Cucumber.logger.level = Logger::INFO 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?) html_output = cuke.configuration.formats.select{|format| format[0] == 'html'}
support_code.load_files!(@cuke_configuration.support_to_load + @cuke_configuration.step_defs_to_load) if html_output
support_code.fire_hook(:after_configuration, @cuke_configuration) cuke.configuration.formats.delete(html_output)
# i don't like this, but there no access to set the instance of SupportCode in Runtime cuke.configuration.formats << ['Hydra::Formatter::PartialHtml', "#{results_directory}/#{file.split('/').last}.html"]
@cuke_runtime.instance_variable_set('@support_code',support_code) end
cuke_runtime = Cucumber::Runtime.new(cuke.configuration)
cuke_runtime.run!
hydra_response.rewind
end end
cuke_formatter = Cucumber::Formatter::Hydra.new( Process.wait fork_id
@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
)
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 return hydra_response.read
end end
@ -260,17 +252,6 @@ module Hydra #:nodoc:
end end
return klasses.select{|k| k.respond_to? 'suite'} return klasses.select{|k| k.respond_to? 'suite'}
end 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
end end

View File

@ -80,13 +80,10 @@ module Hydra #:nodoc:
def boot_runners(num_runners) #:nodoc: def boot_runners(num_runners) #:nodoc:
trace "Booting #{num_runners} Runners" trace "Booting #{num_runners} Runners"
ports = [7055, 7056]
num_runners.times do num_runners.times do
port = ports.shift
pipe = Hydra::Pipe.new pipe = Hydra::Pipe.new
child = SafeFork.fork do child = SafeFork.fork do
ENV['port'] = port.to_s
pipe.identify_as_child pipe.identify_as_child
Hydra::Runner.new(:io => pipe, :verbose => @verbose, :options => @options) Hydra::Runner.new(:io => pipe, :verbose => @verbose, :options => @options)
end end