diff options
author | francis <francis> | 2008-01-23 01:54:49 +0000 |
---|---|---|
committer | francis <francis> | 2008-01-23 01:54:49 +0000 |
commit | fdaa98e06ba6d6f8b62480a83e9ecffdbcb21402 (patch) | |
tree | 40b8b0d7602a7a17bead44e0fd3a2ea101b18bd6 /vendor/plugins/rspec/lib/spec/expectations | |
parent | 60eaae4f7df1f1dae91defb87d3707451c359cf4 (diff) |
Upgrade to rspec 1.1.2
Diffstat (limited to 'vendor/plugins/rspec/lib/spec/expectations')
4 files changed, 47 insertions, 22 deletions
diff --git a/vendor/plugins/rspec/lib/spec/expectations/differs/default.rb b/vendor/plugins/rspec/lib/spec/expectations/differs/default.rb index 87e59b3a6..a5eb1bb89 100644 --- a/vendor/plugins/rspec/lib/spec/expectations/differs/default.rb +++ b/vendor/plugins/rspec/lib/spec/expectations/differs/default.rb @@ -12,12 +12,8 @@ module Spec # TODO add some rdoc class Default - def initialize(format=:unified,context_lines=nil,colour=nil) - - context_lines ||= 3 - colour ||= false - - @format,@context_lines,@colour = format,context_lines,colour + def initialize(options) + @options = options end # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool) @@ -31,17 +27,17 @@ module Spec file_length_difference = 0 diffs.each do |piece| begin - hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @context_lines, + 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) + if (context_lines > 0) and hunk.overlaps?(oldhunk) hunk.unshift(oldhunk) else - output << oldhunk.diff(@format) + output << oldhunk.diff(format) end ensure oldhunk = hunk @@ -49,12 +45,21 @@ module Spec end end #Handle the last remaining hunk - output << oldhunk.diff(@format) << "\n" + output << oldhunk.diff(format) << "\n" end def diff_as_object(target,expected) diff_as_string(PP.pp(target,""), PP.pp(expected,"")) end + + protected + def format + @options.diff_format + end + + def context_lines + @options.context_lines + end end end end diff --git a/vendor/plugins/rspec/lib/spec/expectations/errors.rb b/vendor/plugins/rspec/lib/spec/expectations/errors.rb index 03e81a064..1fabd105d 100644 --- a/vendor/plugins/rspec/lib/spec/expectations/errors.rb +++ b/vendor/plugins/rspec/lib/spec/expectations/errors.rb @@ -1,6 +1,12 @@ module Spec module Expectations - class ExpectationNotMetError < StandardError + # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit + # will report unmet RSpec expectations as failures rather than errors. + superclass = ['Test::Unit::AssertionFailedError', '::StandardError'].map do |c| + eval(c) rescue nil + end.compact.first + + class ExpectationNotMetError < superclass end end end diff --git a/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb b/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb index f59af722e..a3925bbee 100644 --- a/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb +++ b/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb @@ -3,7 +3,6 @@ module Spec # rspec adds #should and #should_not to every Object (and, # implicitly, every Class). module ObjectExpectations - # :call-seq: # should(matcher) # should == expected @@ -28,9 +27,12 @@ module Spec # # NOTE that this does NOT support receiver.should != expected. # Instead, use receiver.should_not == expected - def should(matcher=nil, &block) - return ExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher - Spec::Matchers::PositiveOperatorMatcher.new(self) + def should(matcher = :default_parameter, &block) + if :default_parameter == matcher + Spec::Matchers::PositiveOperatorMatcher.new(self) + else + ExpectationMatcherHandler.handle_matcher(self, matcher, &block) + end end # :call-seq: @@ -52,9 +54,12 @@ module Spec # => Passes unless (receiver =~ regexp) # # See Spec::Matchers for more information about matchers - def should_not(matcher=nil, &block) - return NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher - Spec::Matchers::NegativeOperatorMatcher.new(self) + def should_not(matcher = :default_parameter, &block) + if :default_parameter == matcher + Spec::Matchers::NegativeOperatorMatcher.new(self) + else + NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block) + end end end diff --git a/vendor/plugins/rspec/lib/spec/expectations/handler.rb b/vendor/plugins/rspec/lib/spec/expectations/handler.rb index 4caa321e4..e6dce0846 100644 --- a/vendor/plugins/rspec/lib/spec/expectations/handler.rb +++ b/vendor/plugins/rspec/lib/spec/expectations/handler.rb @@ -1,18 +1,23 @@ module Spec module Expectations + class InvalidMatcherError < ArgumentError; end module MatcherHandlerHelper - def describe(matcher) + def describe_matcher(matcher) matcher.respond_to?(:description) ? matcher.description : "[#{matcher.class.name} does not provide a description]" end end - class ExpectationMatcherHandler + class ExpectationMatcherHandler class << self include MatcherHandlerHelper def handle_matcher(actual, matcher, &block) + unless matcher.respond_to?(:matches?) + raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}." + end + match = matcher.matches?(actual, &block) - ::Spec::Matchers.generated_description = "should #{describe(matcher)}" + ::Spec::Matchers.generated_description = "should #{describe_matcher(matcher)}" Spec::Expectations.fail_with(matcher.failure_message) unless match end end @@ -22,6 +27,10 @@ module Spec class << self include MatcherHandlerHelper def handle_matcher(actual, matcher, &block) + unless matcher.respond_to?(:matches?) + raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}." + end + unless matcher.respond_to?(:negative_failure_message) Spec::Expectations.fail_with( <<-EOF @@ -32,7 +41,7 @@ EOF ) end match = matcher.matches?(actual, &block) - ::Spec::Matchers.generated_description = "should not #{describe(matcher)}" + ::Spec::Matchers.generated_description = "should not #{describe_matcher(matcher)}" Spec::Expectations.fail_with(matcher.negative_failure_message) if match end end |