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 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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
hydra_response = StringIO.new
|
||||||
|
hydra_response.puts file
|
||||||
|
|
||||||
|
options = @options if @options.is_a?(Array)
|
||||||
|
options = @options.split(' ') if @options.is_a?(String)
|
||||||
|
|
||||||
|
fork_id = fork do
|
||||||
files = [file]
|
files = [file]
|
||||||
dev_null = StringIO.new
|
dev_null = StringIO.new
|
||||||
hydra_response = StringIO.new
|
|
||||||
|
|
||||||
unless @cuke_runtime
|
args = [file, options].flatten.compact
|
||||||
require 'cucumber'
|
hydra_response.puts args.inspect
|
||||||
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])
|
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
|
||||||
cuke_formatter = Cucumber::Formatter::Hydra.new(
|
|
||||||
@cuke_runtime, hydra_response, @cuke_configuration.options
|
|
||||||
)
|
|
||||||
results_directory = "#{Dir.pwd}/results/features"
|
results_directory = "#{Dir.pwd}/results/features"
|
||||||
FileUtils.mkdir_p results_directory
|
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(
|
require 'cucumber/cli/main'
|
||||||
@cuke_runtime, [cuke_formatter, html_formatter], @cuke_configuration
|
require 'hydra/cucumber/formatter'
|
||||||
)
|
require 'hydra/cucumber/partial_html'
|
||||||
@cuke_runtime.visitor = cuke_runner
|
|
||||||
|
|
||||||
loader = Cucumber::Runtime::FeaturesLoader.new(
|
Cucumber.logger.level = Logger::INFO
|
||||||
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)
|
cuke = Cucumber::Cli::Main.new(args, hydra_response, hydra_response)
|
||||||
|
#cuke.configuration.formats.clear
|
||||||
|
cuke.configuration.formats << ['Cucumber::Formatter::Hydra', hydra_response]
|
||||||
|
|
||||||
|
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
|
hydra_response.rewind
|
||||||
|
end
|
||||||
|
Process.wait fork_id
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue