lib/cucumber/formatter/console.rb in cucumber-1.3.20 vs lib/cucumber/formatter/console.rb in cucumber-2.0.0.beta.1

- old
+ new

@@ -30,11 +30,11 @@ include Duration include Summary def format_step(keyword, step_match, status, source_indent) comment = if source_indent - c = (' # ' + step_match.file_colon_line).indent(source_indent) + c = ('# ' + step_match.file_colon_line).indent(source_indent) format_string(c, :comment) else '' end @@ -75,31 +75,50 @@ @io.flush end end def print_stats(features, options) - @failures = runtime.scenarios(:failed).select { |s| s.is_a?(Cucumber::Ast::Scenario) || s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow) } - @failures.collect! { |s| (s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)) ? s.scenario_outline : s } - - if !@failures.empty? - @io.puts format_string("Failing Scenarios:", :failed) - @failures.each do |failure| - profiles_string = options.custom_profiles.empty? ? '' : (options.custom_profiles.map{|profile| "-p #{profile}" }).join(' ') + ' ' - source = options[:source] ? format_string(" # Scenario: " + failure.name, :comment) : '' - @io.puts format_string("cucumber #{profiles_string}" + failure.file_colon_line, :failed) + source - end - @io.puts + failures = collect_failing_scenarios(runtime) + if !failures.empty? + print_failing_scenarios(failures, options.custom_profiles, options[:source]) end @io.puts scenario_summary(runtime) {|status_count, status| format_string(status_count, status)} @io.puts step_summary(runtime) {|status_count, status| format_string(status_count, status)} @io.puts(format_duration(features.duration)) if features && features.duration + if runtime.configuration.randomize? + @io.puts + @io.puts "Randomized with seed #{runtime.configuration.seed}" + end + @io.flush end + def collect_failing_scenarios(runtime) + # TODO: brittle - stop coupling to types + scenario_class = Cucumber::Reports::Legacy::Ast::Scenario + example_table_class = Cucumber::Core::Ast::ExamplesTable + + runtime.scenarios(:failed).select do |s| + [scenario_class, example_table_class].include?(s.class) + end.map do |s| + s.is_a?(example_table_class)? s.scenario_outline : s + end + end + + def print_failing_scenarios(failures, custom_profiles, given_source) + @io.puts format_string("Failing Scenarios:", :failed) + failures.each do |failure| + profiles_string = custom_profiles.empty? ? '' : (custom_profiles.map{|profile| "-p #{profile}" }).join(' ') + ' ' + source = given_source ? format_string(" # " + failure.name, :comment) : '' + @io.puts format_string("cucumber #{profiles_string}" + failure.location, :failed) + source + end + @io.puts + end + def print_exception(e, status, indent) message = "#{e.message} (#{e.class})" if ENV['CUCUMBER_TRUNCATE_OUTPUT'] message = linebreaks(message, ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i) end @@ -119,23 +138,15 @@ return if undefined.empty? unknown_programming_language = runtime.unknown_programming_language? snippets = undefined.map do |step| step_name = Undefined === step.exception ? step.exception.step_name : step.name - step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil - snippet = @runtime.snippet_text(step.actual_keyword, step_name, step_multiline_class) - snippet + @runtime.snippet_text(step.actual_keyword, step_name, step.multiline_arg) end.compact.uniq text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n" text += snippets.join("\n\n") @io.puts format_string(text, :undefined) - - if unknown_programming_language - @io.puts format_string("\nIf you want snippets in a different programming language," + - "\njust make sure a file with the appropriate file extension" + - "\nexists where cucumber looks for step definitions.", :failed) - end @io.puts @io.flush end