diff options
author | francis <francis> | 2008-01-23 01:57:59 +0000 |
---|---|---|
committer | francis <francis> | 2008-01-23 01:57:59 +0000 |
commit | 6d1733e8a0b5f404326cfbd78b7139c87ecbffa3 (patch) | |
tree | c86561445b9ec5179020f8f56afb7b9174b390c5 /vendor/plugins/rspec/lib/spec/runner | |
parent | 8bd6667c7885870af45522315f501a2b87340b1a (diff) |
Add files new to new rspec
Diffstat (limited to 'vendor/plugins/rspec/lib/spec/runner')
7 files changed, 422 insertions, 0 deletions
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 +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <title>Stories</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta http-equiv="Expires" content="-1" /> + <meta http-equiv="Pragma" content="no-cache" /> + <script src="javascripts/prototype.js" type="text/javascript"></script> + <script src="javascripts/scriptaculous.js" type="text/javascript"></script> + <script src="javascripts/rspec.js" type="text/javascript"></script> + <link href="stylesheets/rspec.css" rel="stylesheet" type="text/css" /> + </head> + <body> + <div id="container"> +EOF + end + + def collected_steps(steps) + unless steps.empty? + @output.puts " <ul id=\"stock_steps\" style=\"display: none;\">" + steps.each do |step| + @output.puts " <li>#{step}</li>" + end + @output.puts " </ul>" + end + end + + def run_ended + @output.puts <<-EOF + </div> + </body> +</head> +EOF + end + + def story_started(title, narrative) + @output.puts <<-EOF + <dl class="story passed"> + <dt>Story: #{h title}</dt> + <dd> + <p> + #{h(narrative).split("\n").join("<br />")} + </p> +EOF + end + + def story_ended(title, narrative) + @output.puts <<-EOF + </dd> + </dl> +EOF + end + + def scenario_started(story_title, scenario_name) + @output.puts <<-EOF + <dl class="passed"> + <dt>Scenario: #{h scenario_name}</dt> + <dd> + <ul class="steps"> +EOF + end + + def scenario_ended + @output.puts <<-EOF + </ul> + </dd> + </dl> +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| "<span class=\"param\">#{arg}</span>" } + 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 " <li class=\"#{klass}\">#{inner}</li>" + 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 + "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&line=#{$2}\">#{$1}:#{$2}</a> " + end + end + end + end + end +end |