Permalink
Browse files

reducing the warnings

- before: running rspec's own specs - 2380 warnings from lib
- after: 0
- still have warnings from the spec dir, but progress is progress
- thanks to a tweet from @ntalbott
  • Loading branch information...
1 parent c45c173 commit a6ff201d466e03984024a1a56deec7dbc1a1a19e @dchelimsky committed Mar 18, 2009
@@ -3,16 +3,18 @@
module Spec
module Adapters
- module MockFramework
- include Spec::Mocks::ExampleMethods
- def setup_mocks_for_rspec
- $rspec_mocks ||= Spec::Mocks::Space.new
- end
- def verify_mocks_for_rspec
- $rspec_mocks.verify_all
- end
- def teardown_mocks_for_rspec
- $rspec_mocks.reset_all
+ unless defined?(MockFramework)
+ module MockFramework
+ include Spec::Mocks::ExampleMethods
+ def setup_mocks_for_rspec
+ $rspec_mocks ||= Spec::Mocks::Space.new
+ end
+ def verify_mocks_for_rspec
+ $rspec_mocks.verify_all
+ end
+ def teardown_mocks_for_rspec
+ $rspec_mocks.reset_all
+ end
end
end
end
@@ -19,7 +19,7 @@ def inherited(klass) # :nodoc:
# Provides the backtrace up to where this example_group was declared.
def backtrace
- @backtrace
+ defined?(@backtrace) ? @backtrace : nil
end
# Deprecated - use +backtrace()+
@@ -16,7 +16,8 @@ module ExampleGroupMethods
# See +ExampleMethods#should+ for more information about this approach.
def subject(&block)
if block.nil?
- @_subject_block || (described_class ? lambda {described_class.new} : lambda {description_args.first})
+ defined?(@_subject_block) ? @_subject_block :
+ (described_class ? lambda {described_class.new} : lambda {description_args.first})
else
@_subject_block = block
end
View
@@ -31,7 +31,7 @@ module Spec
# matchers is quite simple. See Spec::Matchers for details.
module Expectations
def self.differ
- @differ
+ defined?(@differ) ? @differ : nil
end
def self.differ=(differ)
@@ -4,57 +4,58 @@
module Spec
module Expectations
module Differs
+ unless defined?(Default)
+ class Default
+ def initialize(options)
+ @options = options
+ end
- # TODO add some rdoc
- class Default
- def initialize(options)
- @options = options
- end
-
- # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
- def diff_as_string(data_new, data_old)
- data_old = data_old.split(/\n/).map! { |e| e.chomp }
- data_new = data_new.split(/\n/).map! { |e| e.chomp }
- output = ""
- diffs = Diff::LCS.diff(data_old, data_new)
- return output if diffs.empty?
- oldhunk = hunk = nil
- file_length_difference = 0
- diffs.each do |piece|
- begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
- file_length_difference)
- file_length_difference = hunk.file_length_difference
- next unless oldhunk
- # Hunks may overlap, which is why we need to be careful when our
- # diff includes lines of context. Otherwise, we might print
- # redundant lines.
- if (context_lines > 0) and hunk.overlaps?(oldhunk)
- hunk.unshift(oldhunk)
- else
- output << oldhunk.diff(format)
+ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
+ def diff_as_string(data_new, data_old)
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
+ output = ""
+ diffs = Diff::LCS.diff(data_old, data_new)
+ return output if diffs.empty?
+ oldhunk = hunk = nil
+ file_length_difference = 0
+ diffs.each do |piece|
+ begin
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
+ file_length_difference)
+ file_length_difference = hunk.file_length_difference
+ next unless oldhunk
+ # Hunks may overlap, which is why we need to be careful when our
+ # diff includes lines of context. Otherwise, we might print
+ # redundant lines.
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
+ hunk.unshift(oldhunk)
+ else
+ output << oldhunk.diff(format)
+ end
+ ensure
+ oldhunk = hunk
+ output << "\n"
end
- ensure
- oldhunk = hunk
- output << "\n"
- end
+ end
+ #Handle the last remaining hunk
+ output << oldhunk.diff(format) << "\n"
end
- #Handle the last remaining hunk
- output << oldhunk.diff(format) << "\n"
- end
- def diff_as_object(target,expected)
- diff_as_string(PP.pp(target,""), PP.pp(expected,""))
- end
+ def diff_as_object(target,expected)
+ diff_as_string(PP.pp(target,""), PP.pp(expected,""))
+ end
- protected
- def format
- @options.diff_format
- end
+ protected
+ def format
+ @options.diff_format
+ end
- def context_lines
- @options.context_lines
+ def context_lines
+ @options.context_lines
+ end
end
+
end
end
end
View
@@ -7,6 +7,7 @@ class Be #:nodoc:
def initialize(*args)
@expected = args.empty? ? true : set_expected(args.shift)
@args = args
+ @comparison_method = nil
end
def matches?(actual)
@@ -100,6 +101,9 @@ def set_prefix(prefix)
end
def prefix
+ # FIXME - this is a bit goofy - but we get failures
+ # if just defining @prefix = nil in initialize
+ @prefix = nil unless defined?(@prefix)
@prefix
end
@@ -109,7 +113,9 @@ def handling_predicate!
def handling_predicate?
return false if [true, false, nil].include?(expected)
- return @handling_predicate
+ # FIXME - this is a bit goofy - but we get failures
+ # if just defining @handling_predicate = nil or false in initialize
+ return defined?(@handling_predicate) ? @handling_predicate : nil
end
def predicate
@@ -6,6 +6,7 @@ class Change #:nodoc:
def initialize(receiver=nil, message=nil, &block)
@message = message || "result"
@value_proc = block || lambda {receiver.__send__(message)}
+ @to = @from = @minimum = @maximum = @amount = nil
end
def matches?(event_proc)
View
@@ -4,6 +4,7 @@ class Have #:nodoc:
def initialize(expected, relativity=:exactly)
@expected = (expected == :no ? 0 : expected)
@relativity = relativity
+ @actual = nil
end
def relativities
@@ -24,25 +25,25 @@ def matches?(collection_owner)
else
collection_owner.__send__(@collection_name, *@args, &@block)
end
- @given = collection.size if collection.respond_to?(:size)
- @given = collection.length if collection.respond_to?(:length)
- raise not_a_collection if @given.nil?
- return @given >= @expected if @relativity == :at_least
- return @given <= @expected if @relativity == :at_most
- return @given == @expected
+ @actual = collection.size if collection.respond_to?(:size)
+ @actual = collection.length if collection.respond_to?(:length)
+ raise not_a_collection if @actual.nil?
+ return @actual >= @expected if @relativity == :at_least
+ return @actual <= @expected if @relativity == :at_most
+ return @actual == @expected
end
def not_a_collection
"expected #{@collection_name} to be a collection but it does not respond to #length or #size"
end
def failure_message_for_should
- "expected #{relative_expectation} #{@collection_name}, got #{@given}"
+ "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
end
def failure_message_for_should_not
if @relativity == :exactly
- return "expected target not to have #{@expected} #{@collection_name}, got #{@given}"
+ return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
elsif @relativity == :at_most
return <<-EOF
Isn't life confusing enough?
@@ -3,6 +3,7 @@ module Matchers
class RaiseError #:nodoc:
def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
@block = block
+ @actual_error = nil
case expected_error_or_message
when String, Regexp
@expected_error, @expected_message = Exception, expected_error_or_message
@@ -18,10 +19,10 @@ def matches?(given_proc)
@eval_block_passed = false
begin
given_proc.call
- rescue @expected_error => @given_error
+ rescue @expected_error => @actual_error
@raised_expected_error = true
@with_expected_message = verify_message
- rescue Exception => @given_error
+ rescue Exception => @actual_error
# This clause should be empty, but rcov will not report it as covered
# unless something (anything) is executed within the clause
rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
@@ -37,10 +38,10 @@ def matches?(given_proc)
def eval_block
@eval_block = true
begin
- @block[@given_error]
+ @block[@actual_error]
@eval_block_passed = true
rescue Exception => err
- @given_error = err
+ @actual_error = err
end
end
@@ -49,14 +50,14 @@ def verify_message
when nil
true
when Regexp
- @expected_message =~ @given_error.message
+ @expected_message =~ @actual_error.message
else
- @expected_message == @given_error.message
+ @expected_message == @actual_error.message
end
end
def failure_message_for_should
- @eval_block ? @given_error.message : "expected #{expected_error}#{given_error}"
+ @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
end
def failure_message_for_should_not
@@ -80,7 +81,7 @@ def expected_error
end
def given_error
- @given_error.nil? ? " but nothing was raised" : ", got #{@given_error.inspect}"
+ @actual_error.nil? ? " but nothing was raised" : ", got #{@actual_error.inspect}"
end
def negative_expectation?
@@ -6,6 +6,7 @@ class SimpleMatcher
def initialize(description, &match_block)
@description = description
@match_block = match_block
+ @failure_message = @negative_failure_message = nil
end
def matches?(given)
@@ -5,7 +5,7 @@ class ThrowSymbol #:nodoc:
def initialize(expected_symbol = nil, expected_arg=nil)
@expected_symbol = expected_symbol
@expected_arg = expected_arg
- @caught_symbol = nil
+ @caught_symbol = @caught_arg = nil
end
def matches?(given_proc)
@@ -7,6 +7,8 @@ class ArgumentExpectation
def initialize(args, &block)
@args = args
@matchers_block = block
+ @match_any_args = false
+ @matchers = nil
if ArgumentMatchers::AnyArgsMatcher === args.first
@match_any_args = true
@@ -25,6 +25,8 @@ def initialize(error_generator, expectation_ordering, expected_from, sym, method
@at_least = nil
@at_most = nil
@args_to_yield = []
+ @failed_fast = nil
+ @args_to_yield_were_cloned = false
end
def build_child(expected_from, method_block, expected_received_count, opts={})
View
@@ -25,6 +25,7 @@ def initialize(target, name=nil, options={})
@stubs = []
@proxied_methods = []
@options = options ? DEFAULT_OPTIONS.dup.merge(options) : DEFAULT_OPTIONS
+ @already_proxied_respond_to = false
end
def null_object?
@@ -128,23 +129,22 @@ def warn_if_nil_class(sym)
end
def define_expected_method(sym)
- visibility_string = "#{visibility(sym)} :#{sym}"
unless @proxied_methods.include?(sym)
+ visibility_string = "#{visibility(sym)} :#{sym}"
if target_responds_to?(sym)
munged_sym = munge(sym)
target_metaclass.instance_eval do
alias_method munged_sym, sym if method_defined?(sym)
end
@proxied_methods << sym
end
+ target_metaclass.class_eval(<<-EOF, __FILE__, __LINE__)
+ def #{sym}(*args, &block)
+ __mock_proxy.message_received :#{sym}, *args, &block
+ end
+ #{visibility_string}
+ EOF
end
-
- target_metaclass.class_eval(<<-EOF, __FILE__, __LINE__)
- def #{sym}(*args, &block)
- __mock_proxy.message_received :#{sym}, *args, &block
- end
- #{visibility_string}
- EOF
end
def target_responds_to?(sym)
@@ -195,11 +195,10 @@ def reset_proxied_methods
@proxied_methods.each do |sym|
munged_sym = munge(sym)
target_metaclass.instance_eval do
+ remove_method sym
if method_defined?(munged_sym)
alias_method sym, munged_sym
remove_method munged_sym
- else
- remove_method sym
end
end
end
@@ -11,6 +11,7 @@ def initialize(options, output)
super
@example_group_number = 0
@example_number = 0
+ @header_red = nil
end
def method_missing(sym, *args)
Oops, something went wrong.

0 comments on commit a6ff201

Please sign in to comment.