improved the way that cucumber is called
no longer relying on internal api
This commit is contained in:
parent
455fa3674f
commit
a5ed377e13
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue