lib/hydra/runner.rb in arturop-hydra-0.23.4 vs lib/hydra/runner.rb in arturop-hydra-0.24.0

- old
+ new

@@ -23,10 +23,12 @@ reg_trap_sighup @io = opts.fetch(:io) { raise "No IO Object" } @verbose = opts.fetch(:verbose) { false } @event_listeners = Array( opts.fetch( :runner_listeners ) { nil } ) + @options = opts.fetch(:options) { "" } + @directory = get_directory $stdout.sync = true runner_begin trace 'Booted. Sending Request for file' @@ -117,11 +119,11 @@ end # Run all the Test::Unit Suites in a ruby file def run_test_unit_file(file) begin - require file + require @directory + file rescue LoadError => ex trace "#{file} does not exist [#{ex.to_s}]" return ex.to_s rescue Exception => ex trace "Error requiring #{file} [#{ex.to_s}]" @@ -171,51 +173,50 @@ return output end # run all the scenarios in a cucumber feature file def run_cucumber_file(file) - - files = [file] - dev_null = StringIO.new hydra_response = StringIO.new - 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) - 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 - ) + cuke = Cucumber::Cli::Main.new(args, dev_null, dev_null) + cuke.configuration.formats << ['Cucumber::Formatter::Hydra', hydra_response] - cuke_runner ||= Cucumber::Ast::TreeWalker.new( - @cuke_runtime, [cuke_formatter], @cuke_configuration - ) - @cuke_runtime.visitor = cuke_runner + 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 - 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_runtime = Cucumber::Runtime.new(cuke.configuration) + cuke_runtime.run! + exit 1 if cuke_runtime.results.failure? + end + Process.wait fork_id - cuke_runner.visit_features(features) - + hydra_response.puts "." if not $?.exitstatus == 0 hydra_response.rewind - return hydra_response.read + + hydra_response.read end def run_javascript_file(file) errors = [] require 'v8' @@ -224,11 +225,11 @@ context['input'] = lambda{ File.read(file) } context['reportErrors'] = lambda{|js_errors| js_errors.each do |e| - e = V8::To.rb(e) + e = context.instance_variable_get("@to").rb(e) errors << "\n\e[1;31mJSLINT: #{file}\e[0m" errors << " Error at line #{e['line'].to_i + 1} " + "character #{e['character'].to_i + 1}: \e[1;33m#{e['reason']}\e[0m" errors << "#{e['evidence']}" end @@ -300,7 +301,12 @@ # it should always redirect output in order to handle unexpected interruption # successfully $stderr = $stdout = File.open(DEFAULT_LOG_FILE, 'a') end end + + def get_directory + RUBY_VERSION < "1.9" ? "" : Dir.pwd + "/" + end end end +