Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into no-stub-shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Maddox committed Sep 17, 2008
2 parents 443b0b6 + ac8d28c commit dab567d
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 130 deletions.
79 changes: 0 additions & 79 deletions colour_tty.patch

This file was deleted.

6 changes: 6 additions & 0 deletions lib/spec/example/errors.rb
@@ -1,6 +1,12 @@
module Spec
module Example
class ExamplePendingError < StandardError
def initialize(a_message=nil)
super
@pending_caller = caller[2]
end

attr_reader :pending_caller
end

class PendingExampleFixedError < StandardError
Expand Down
4 changes: 3 additions & 1 deletion lib/spec/runner/formatter/base_formatter.rb
Expand Up @@ -45,7 +45,9 @@ def example_failed(example, counter, failure)
# been provided a block), or when an ExamplePendingError is raised.
# +message+ is the message from the ExamplePendingError, if it exists, or the
# default value of "Not Yet Implemented"
def example_pending(example, message)
# +pending_caller+ is the file and line number of the spec which
# has called the pending method
def example_pending(example, message, pending_caller)
end

# This method is invoked after all of the examples have executed. The next method
Expand Down
5 changes: 3 additions & 2 deletions lib/spec/runner/formatter/base_text_formatter.rb
Expand Up @@ -21,8 +21,8 @@ def initialize(options, where)
@pending_examples = []
end

def example_pending(example, message)
@pending_examples << [example.__full_description, message]
def example_pending(example, message, pending_caller)
@pending_examples << [example.__full_description, message, pending_caller]
end

def dump_failure(counter, failure)
Expand Down Expand Up @@ -70,6 +70,7 @@ def dump_pending
@output.puts "Pending:"
@pending_examples.each do |pending_example|
@output.puts "#{pending_example[0]} (#{pending_example[1]})"
@output.puts " Called from #{pending_example[2]}"
end
end
@output.flush
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/runner/formatter/html_formatter.rb
Expand Up @@ -85,7 +85,7 @@ def example_failed(example, counter, failure)
@output.flush
end

def example_pending(example, message)
def example_pending(example, message, pending_caller)
@output.puts " <script type=\"text/javascript\">makeYellow('rspec-header');</script>" unless @header_red
@output.puts " <script type=\"text/javascript\">makeYellow('example_group_#{example_group_number}');</script>" unless @example_group_red
move_progress
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/runner/formatter/nested_text_formatter.rb
Expand Up @@ -40,7 +40,7 @@ def example_passed(example)
output.flush
end

def example_pending(example, message)
def example_pending(example, message, pending_caller)
super
output.puts yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
output.flush
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/runner/formatter/progress_bar_formatter.rb
Expand Up @@ -14,7 +14,7 @@ def example_passed(example)
@output.flush
end

def example_pending(example, message)
def example_pending(example, message, pending_caller)
super
@output.print yellow('P')
@output.flush
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/runner/formatter/specdoc_formatter.rb
Expand Up @@ -28,7 +28,7 @@ def example_passed(example)
output.flush
end

def example_pending(example, message)
def example_pending(example, message, pending_caller)
super
output.puts yellow("- #{example.description} (PENDING: #{message})")
output.flush
Expand Down
26 changes: 22 additions & 4 deletions lib/spec/runner/reporter.rb
@@ -1,6 +1,11 @@
module Spec
module Runner
class Reporter
PENDING_FORMATTER_DEPRECATION_MESSAGE = <<-HERE
Formatter deprecation: pending_example now takes three arguments, not two.
See http://rspec.info/deprecation_warnings for more info
HERE

attr_reader :options, :example_groups

def initialize(options)
Expand All @@ -26,7 +31,7 @@ def example_finished(example, error=nil)
if error.nil?
example_passed(example)
elsif Spec::Example::ExamplePendingError === error
example_pending(example, error.message)
example_pending(example, error.pending_caller, error.message)
else
example_failed(example, error)
end
Expand Down Expand Up @@ -104,13 +109,26 @@ def example_passed(example)
formatters.each{|f| f.example_passed(example)}
end

def example_pending(example, message="Not Yet Implemented")
def example_pending(example, pending_caller, message="Not Yet Implemented")
@pending_count += 1
formatters.each do |f|
f.example_pending(example, message)
formatters.each do |formatter|
if pending_method_deprecated_on_formatter?(formatter)
warn_with_deprecation_message PENDING_FORMATTER_DEPRECATION_MESSAGE
formatter.example_pending(example, message)
else
formatter.example_pending(example, message, pending_caller)
end
end
end

def pending_method_deprecated_on_formatter?(formatter)
formatter.method(:example_pending).arity == 2
end

def warn_with_deprecation_message(message)
Kernel.warn(message)
end

class Failure
attr_reader :example, :exception

Expand Down
112 changes: 112 additions & 0 deletions spec/spec/example/base_formatter_spec.rb
@@ -0,0 +1,112 @@
require File.dirname(__FILE__) + "/../../spec_helper"

module Spec
module Runner
module Formatter
describe BaseFormatter do
before :each do
@options, @where = nil, nil
@formatter = BaseFormatter.new(@options, @where)
end

class HaveInterfaceMatcher
def initialize(method)
@method = method
end

attr_reader :object
attr_reader :method

def matches?(object)
@object = object
object.respond_to?(@method)
end

def with(arity)
WithArity.new(self, @method, arity)
end

class WithArity
def initialize(matcher, method, arity)
@have_matcher = matcher
@method = method
@arity = arity
end

def matches?(an_object)
@have_matcher.matches?(an_object) && real_arity == @arity
end

def failure_message
"#{@have_matcher} should have method :#{@method} with #{argument_arity}, but it had #{real_arity}"
end

def arguments
self
end

alias_method :argument, :arguments

private

def real_arity
@have_matcher.object.method(@method).arity
end

def argument_arity
if @arity == 1
"1 argument"
else
"#{@arity} arguments"
end
end
end
end

def have_interface_for(method)
HaveInterfaceMatcher.new(method)
end

it "should have start as an interface with one argument"do
@formatter.should have_interface_for(:start).with(1).argument
end

it "should have add_example_group as an interface with one argument" do
@formatter.should have_interface_for(:add_example_group).with(1).argument
end

it "should have example_started as an interface with one argument" do
@formatter.should have_interface_for(:example_started).with(1).argument
end

it "should have example_failed as an interface with three arguments" do
@formatter.should have_interface_for(:example_failed).with(3).arguments
end

it "should have example_pending as an interface with three arguments" do
@formatter.should have_interface_for(:example_pending).with(3).arguments
end

it "should have start_dump as an interface with zero arguments" do
@formatter.should have_interface_for(:start_dump).with(0).arguments
end

it "should have dump_failure as an interface with two arguments" do
@formatter.should have_interface_for(:dump_failure).with(2).arguments
end

it "should have dump_summary as an interface with two arguments" do
@formatter.should have_interface_for(:dump_failure).with(2).arguments
end

it "should have dump_pending as an interface with zero arguments" do
@formatter.should have_interface_for(:dump_pending).with(0).arguments
end

it "should have close as an interface with zero arguments" do
@formatter.should have_interface_for(:close).with(0).arguments
end
end
end
end
end
4 changes: 3 additions & 1 deletion spec/spec/example/example_group_methods_spec.rb
Expand Up @@ -6,7 +6,9 @@ module Example
include SandboxedOptions
attr_reader :example_group, :result, :reporter
before(:each) do
options.formatters << mock("formatter", :null_object => true)
# See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
method_with_three_args = lambda { |arg1, arg2, arg3| }
options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
@reporter = FakeReporter.new(@options)
options.reporter = reporter
Expand Down
3 changes: 2 additions & 1 deletion spec/spec/example/example_group_spec.rb
Expand Up @@ -68,7 +68,8 @@ class ExampleClassVariablePollutionSpec < ExampleGroup
include SandboxedOptions
attr_reader :example_group, :formatter, :reporter
before :each do
@formatter = mock("formatter", :null_object => true)
method_with_three_args = lambda { |arg1, arg2, arg3| }
@formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
options.formatters << formatter
options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
@reporter = FakeReporter.new(options)
Expand Down
27 changes: 27 additions & 0 deletions spec/spec/example/pending_module_spec.rb
Expand Up @@ -38,5 +38,32 @@ module Example
}.should raise_error(PendingExampleFixedError, /TODO/)
end
end

describe ExamplePendingError do
it "should have the caller (from two calls from initialization)" do
two_calls_ago = caller[0]
ExamplePendingError.new("a message").pending_caller.should == two_calls_ago
end

it "should keep the trace information from initialization" do
two_calls_ago = caller[0]
obj = ExamplePendingError.new("a message")
obj.pending_caller
def another_caller(obj)
obj.pending_caller
end

another_caller(obj).should == two_calls_ago
end

it "should have the message provided" do
ExamplePendingError.new("a message").message.should == "a message"
end

it "should use a 'ExamplePendingError' as it's default message" do
ExamplePendingError.new.message.should == "Spec::Example::ExamplePendingError"
end
end

end
end

0 comments on commit dab567d

Please sign in to comment.