From 6d1733e8a0b5f404326cfbd78b7139c87ecbffa3 Mon Sep 17 00:00:00 2001 From: francis Date: Wed, 23 Jan 2008 01:57:59 +0000 Subject: Add files new to new rspec --- .../lib/spec/runner/class_and_arguments_parser.rb | 16 +++ .../rspec/lib/spec/runner/example_group_runner.rb | 59 ++++++++++ .../formatter/failing_example_groups_formatter.rb | 31 +++++ .../lib/spec/runner/formatter/profile_formatter.rb | 47 ++++++++ .../spec/runner/formatter/story/html_formatter.rb | 125 ++++++++++++++++++++ .../runner/formatter/story/plain_text_formatter.rb | 128 +++++++++++++++++++++ .../spec/runner/formatter/text_mate_formatter.rb | 16 +++ 7 files changed, 422 insertions(+) create mode 100644 vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb create mode 100644 vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb (limited to 'vendor/plugins/rspec/lib/spec/runner') diff --git a/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb b/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb new file mode 100644 index 000000000..65dc4519c --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb @@ -0,0 +1,16 @@ +module Spec + module Runner + class ClassAndArgumentsParser + class << self + def parse(s) + if s =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/ + arg = $2 == "" ? nil : $2 + [$1, arg] + else + raise "Couldn't parse #{s.inspect}" + end + end + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb b/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb new file mode 100644 index 000000000..7275c6a88 --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb @@ -0,0 +1,59 @@ +module Spec + module Runner + class ExampleGroupRunner + def initialize(options) + @options = options + end + + def load_files(files) + # It's important that loading files (or choosing not to) stays the + # responsibility of the ExampleGroupRunner. Some implementations (like) + # the one using DRb may choose *not* to load files, but instead tell + # someone else to do it over the wire. + files.each do |file| + load file + end + end + + def run + prepare + success = true + example_groups.each do |example_group| + success = success & example_group.run + end + return success + ensure + finish + end + + protected + def prepare + reporter.start(number_of_examples) + example_groups.reverse! if reverse + end + + def finish + reporter.end + reporter.dump + end + + def reporter + @options.reporter + end + + def reverse + @options.reverse + end + + def example_groups + @options.example_groups + end + + def number_of_examples + @options.number_of_examples + end + end + # TODO: BT - Deprecate BehaviourRunner? + BehaviourRunner = ExampleGroupRunner + end +end \ No newline at end of file diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb new file mode 100644 index 000000000..5a4607983 --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb @@ -0,0 +1,31 @@ +require 'spec/runner/formatter/base_text_formatter' + +module Spec + module Runner + module Formatter + class FailingExampleGroupsFormatter < BaseTextFormatter + def add_example_group(example_group) + super + @example_group_description_parts = example_group.description_parts + end + + def example_failed(example, counter, failure) + if @example_group_description_parts + description_parts = @example_group_description_parts.collect do |description| + description =~ /(.*) \(druby.*\)$/ ? $1 : description + end + @output.puts ::Spec::Example::ExampleGroupMethods.description_text(*description_parts) + @output.flush + @example_group_description_parts = nil + end + end + + def dump_failure(counter, failure) + end + + def dump_summary(duration, example_count, failure_count, pending_count) + end + end + end + end +end diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb new file mode 100644 index 000000000..3784f3ac7 --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb @@ -0,0 +1,47 @@ +require 'spec/runner/formatter/progress_bar_formatter' + +module Spec + module Runner + module Formatter + class ProfileFormatter < ProgressBarFormatter + + def initialize(options, where) + super + @example_times = [] + end + + def start(count) + @output.puts "Profiling enabled." + end + + def example_started(example) + @time = Time.now + end + + def example_passed(example) + super + @example_times << [ + example_group.description, + example.description, + Time.now - @time + ] + end + + def start_dump + super + @output.puts "\n\nTop 10 slowest examples:\n" + + @example_times = @example_times.sort_by do |description, example, time| + time + end.reverse + + @example_times[0..9].each do |description, example, time| + @output.print red(sprintf("%.7f", time)) + @output.puts " #{description} #{example}" + end + @output.flush + end + end + end + end +end diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb new file mode 100644 index 000000000..b70ac153a --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb @@ -0,0 +1,125 @@ +require 'erb' +require 'spec/runner/formatter/base_text_formatter' + +module Spec + module Runner + module Formatter + module Story + class HtmlFormatter < BaseTextFormatter + include ERB::Util + + def run_started(count) + @output.puts <<-EOF + + + + + Stories + + + + + + + + + +
+EOF + end + + def collected_steps(steps) + unless steps.empty? + @output.puts " " + end + end + + def run_ended + @output.puts <<-EOF +
+ + +EOF + end + + def story_started(title, narrative) + @output.puts <<-EOF +
+
Story: #{h title}
+
+

+ #{h(narrative).split("\n").join("
")} +

+EOF + end + + def story_ended(title, narrative) + @output.puts <<-EOF +
+
+EOF + end + + def scenario_started(story_title, scenario_name) + @output.puts <<-EOF +
+
Scenario: #{h scenario_name}
+
+
    +EOF + end + + def scenario_ended + @output.puts <<-EOF +
+
+
+EOF + end + + def found_scenario(type, description) + end + + def scenario_succeeded(story_title, scenario_name) + scenario_ended + end + + def scenario_pending(story_title, scenario_name, reason) + scenario_ended + end + + def scenario_failed(story_title, scenario_name, err) + scenario_ended + end + + def step_succeeded(type, description, *args) + print_step('passed', type, description, *args) # TODO: uses succeeded CSS class + end + + def step_pending(type, description, *args) + print_step('pending', type, description, *args) + end + + def step_failed(type, description, *args) + print_step('failed', type, description, *args) + end + + def print_step(klass, type, description, *args) + spans = args.map { |arg| "#{arg}" } + desc_string = description.step_name + arg_regexp = description.arg_regexp + i = -1 + inner = type.to_s.capitalize + ' ' + desc_string.gsub(arg_regexp) { |param| spans[i+=1] } + @output.puts "
  • #{inner}
  • " + end + end + end + end + end +end \ No newline at end of file diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb new file mode 100644 index 000000000..424e27cc6 --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb @@ -0,0 +1,128 @@ +require 'spec/runner/formatter/base_text_formatter' + +module Spec + module Runner + module Formatter + module Story + class PlainTextFormatter < BaseTextFormatter + def initialize(options, where) + super + @successful_scenario_count = 0 + @pending_scenario_count = 0 + @failed_scenarios = [] + @pending_steps = [] + @previous_type = nil + end + + def run_started(count) + @count = count + @output.puts "Running #@count scenarios\n\n" + end + + def story_started(title, narrative) + @current_story_title = title + @output.puts "Story: #{title}\n\n" + narrative.each_line do |line| + @output.print " " + @output.print line + end + end + + def story_ended(title, narrative) + @output.puts + @output.puts + end + + def scenario_started(story_title, scenario_name) + @current_scenario_name = scenario_name + @scenario_already_failed = false + @output.print "\n\n Scenario: #{scenario_name}" + @scenario_ok = true + end + + def scenario_succeeded(story_title, scenario_name) + @successful_scenario_count += 1 + end + + def scenario_failed(story_title, scenario_name, err) + @options.backtrace_tweaker.tweak_backtrace(err) + @failed_scenarios << [story_title, scenario_name, err] unless @scenario_already_failed + @scenario_already_failed = true + end + + def scenario_pending(story_title, scenario_name, msg) + @pending_scenario_count += 1 unless @scenario_already_failed + @scenario_already_failed = true + end + + def run_ended + @output.puts "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending" + unless @pending_steps.empty? + @output.puts "\nPending Steps:" + @pending_steps.each_with_index do |pending, i| + story_name, scenario_name, msg = pending + @output.puts "#{i+1}) #{story_name} (#{scenario_name}): #{msg}" + end + end + unless @failed_scenarios.empty? + @output.print "\nFAILURES:" + @failed_scenarios.each_with_index do |failure, i| + title, scenario_name, err = failure + @output.print %[ + #{i+1}) #{title} (#{scenario_name}) FAILED + #{err.class}: #{err.message} + #{err.backtrace.join("\n")} +] + end + end + end + + def step_succeeded(type, description, *args) + found_step(type, description, false, *args) + end + + def step_pending(type, description, *args) + found_step(type, description, false, *args) + @pending_steps << [@current_story_title, @current_scenario_name, description] + @output.print " (PENDING)" + @scenario_ok = false + end + + def step_failed(type, description, *args) + found_step(type, description, true, *args) + @output.print red(@scenario_ok ? " (FAILED)" : " (SKIPPED)") + @scenario_ok = false + end + + def collected_steps(steps) + end + + def method_missing(sym, *args, &block) #:nodoc: + # noop - ignore unknown messages + end + + private + + def found_step(type, description, failed, *args) + desc_string = description.step_name + arg_regexp = description.arg_regexp + text = if(type == @previous_type) + "\n And " + else + "\n\n #{type.to_s.capitalize} " + end + i = -1 + text << desc_string.gsub(arg_regexp) { |param| args[i+=1] } + @output.print(failed ? red(text) : green(text)) + + if type == :'given scenario' + @previous_type = :given + else + @previous_type = type + end + end + end + end + end + end +end diff --git a/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb b/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb new file mode 100644 index 000000000..4c0a9c7de --- /dev/null +++ b/vendor/plugins/rspec/lib/spec/runner/formatter/text_mate_formatter.rb @@ -0,0 +1,16 @@ +require 'spec/runner/formatter/html_formatter' + +module Spec + module Runner + module Formatter + # Formats backtraces so they're clickable by TextMate + class TextMateFormatter < HtmlFormatter + def backtrace_line(line) + line.gsub(/([^:]*\.rb):(\d*)/) do + "#{$1}:#{$2} " + end + end + end + end + end +end -- cgit v1.2.3