You are viewing a plain text version of this content. The canonical link for it is here.
Posted to olio-commits@incubator.apache.org by ws...@apache.org on 2008/12/11 01:34:30 UTC
svn commit: r725524 [8/14] - in /incubator/olio/webapp/rails/trunk:
app/controllers/ app/models/ app/views/events/ config/ config/environments/
spec/controllers/ spec/models/ vendor/plugins/attachment_fu/
vendor/plugins/attachment_fu/lib/ vendor/plugin...
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/exist.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/exist.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/exist.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/exist.rb Wed Dec 10 17:34:18 2008
@@ -1,17 +1,16 @@
module Spec
module Matchers
- class Exist
- def matches? actual
- @actual = actual
- @actual.exist?
- end
- def failure_message
- "expected #{@actual.inspect} to exist, but it doesn't."
- end
- def negative_failure_message
- "expected #{@actual.inspect} to not exist, but it does."
+ # :call-seq:
+ # should exist
+ # should_not exist
+ #
+ # Passes if actual.exist?
+ def exist
+ simple_matcher do |actual, matcher|
+ matcher.failure_message = "expected #{actual.inspect} to exist, but it doesn't."
+ matcher.negative_failure_message = "expected #{actual.inspect} to not exist, but it does."
+ actual.exist?
end
end
- def exist; Exist.new; end
end
end
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/generated_descriptions.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,48 @@
+module Spec
+ module Matchers
+ def self.last_matcher
+ @last_matcher
+ end
+
+ def self.last_matcher=(last_matcher)
+ @last_matcher = last_matcher
+ end
+
+ def self.last_should
+ @last_should
+ end
+
+ def self.last_should=(last_should)
+ @last_should = last_should
+ end
+
+ def self.clear_generated_description
+ self.last_matcher = nil
+ self.last_should = nil
+ end
+
+ def self.generated_description
+ return nil if last_should.nil?
+ "#{last_should} #{last_description}"
+ end
+
+ private
+
+ def self.last_description
+ last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
+When you call a matcher in an example without a String, like this:
+
+specify { object.should matcher }
+
+or this:
+
+it { should matcher }
+
+the runner expects the matcher to have a #describe method. You should either
+add a String to the example this matcher is being used in, or give it a
+description method. Then you won't have to suffer this lengthy warning again.
+MESSAGE
+ end
+ end
+end
+
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/has.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/has.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/has.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/has.rb Wed Dec 10 17:34:18 2008
@@ -1,34 +1,18 @@
module Spec
module Matchers
-
- class Has #:nodoc:
- def initialize(sym, *args)
- @sym = sym
- @args = args
- end
-
- def matches?(target)
- target.send(predicate, *@args)
- end
-
- def failure_message
- "expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
- end
-
- def negative_failure_message
- "expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
+ def has(sym, *args) # :nodoc:
+ simple_matcher do |actual, matcher|
+ matcher.failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return true, got false"
+ matcher.negative_failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return false, got true"
+ matcher.description = "have key #{args[0].inspect}"
+ actual.__send__(predicate(sym), *args)
end
-
- def description
- "have key #{@args[0].inspect}"
- end
-
- private
- def predicate
- "#{@sym.to_s.sub("have_","has_")}?".to_sym
- end
-
end
-
+
+ private
+ def predicate(sym)
+ "#{sym.to_s.sub("have_","has_")}?".to_sym
+ end
+
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/have.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/have.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/have.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/have.rb Wed Dec 10 17:34:18 2008
@@ -1,6 +1,5 @@
module Spec
module Matchers
-
class Have #:nodoc:
def initialize(expected, relativity=:exactly)
@expected = (expected == :no ? 0 : expected)
@@ -15,34 +14,22 @@
}
end
- def method_missing(sym, *args, &block)
- @collection_name = sym
- if defined?(ActiveSupport::Inflector)
- @plural_collection_name = ActiveSupport::Inflector.pluralize(sym.to_s)
- elsif Object.const_defined?(:Inflector)
- @plural_collection_name = Inflector.pluralize(sym.to_s)
- end
- @args = args
- @block = block
- self
- end
-
def matches?(collection_owner)
if collection_owner.respond_to?(@collection_name)
- collection = collection_owner.send(@collection_name, *@args, &@block)
+ collection = collection_owner.__send__(@collection_name, *@args, &@block)
elsif (@plural_collection_name && collection_owner.respond_to?(@plural_collection_name))
- collection = collection_owner.send(@plural_collection_name, *@args, &@block)
+ collection = collection_owner.__send__(@plural_collection_name, *@args, &@block)
elsif (collection_owner.respond_to?(:length) || collection_owner.respond_to?(:size))
collection = collection_owner
else
- collection_owner.send(@collection_name, *@args, &@block)
+ collection_owner.__send__(@collection_name, *@args, &@block)
end
- @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
+ @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
end
def not_a_collection
@@ -50,12 +37,12 @@
end
def failure_message
- "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
+ "expected #{relative_expectation} #{@collection_name}, got #{@given}"
end
def negative_failure_message
if @relativity == :exactly
- return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
+ return "expected target not to have #{@expected} #{@collection_name}, got #{@given}"
elsif @relativity == :at_most
return <<-EOF
Isn't life confusing enough?
@@ -79,8 +66,22 @@
"have #{relative_expectation} #{@collection_name}"
end
+ def respond_to?(sym)
+ @expected.respond_to?(sym) || super
+ end
+
private
+ def method_missing(sym, *args, &block)
+ @collection_name = sym
+ if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
+ @plural_collection_name = inflector.pluralize(sym.to_s)
+ end
+ @args = args
+ @block = block
+ self
+ end
+
def relative_expectation
"#{relativities[@relativity]}#{@expected}"
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/include.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/include.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/include.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/include.rb Wed Dec 10 17:34:18 2008
@@ -10,7 +10,17 @@
def matches?(actual)
@actual = actual
@expecteds.each do |expected|
- return false unless actual.include?(expected)
+ if actual.is_a?(Hash)
+ if expected.is_a?(Hash)
+ expected.each_pair do |k,v|
+ return false unless actual[k] == v
+ end
+ else
+ return false unless actual.has_key?(expected)
+ end
+ else
+ return false unless actual.include?(expected)
+ end
end
true
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match.rb Wed Dec 10 17:34:18 2008
@@ -1,30 +1,6 @@
module Spec
module Matchers
- class Match #:nodoc:
- def initialize(expected)
- @expected = expected
- end
-
- def matches?(actual)
- @actual = actual
- return true if actual =~ @expected
- return false
- end
-
- def failure_message
- return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
- end
-
- def negative_failure_message
- return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
- end
-
- def description
- "match #{@expected.inspect}"
- end
- end
-
# :call-seq:
# should match(regexp)
# should_not match(regexp)
@@ -33,9 +9,14 @@
#
# == Examples
#
- # email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
+ # email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
def match(regexp)
- Matchers::Match.new(regexp)
+ simple_matcher do |actual, matcher|
+ matcher.failure_message = "expected #{actual.inspect} to match #{regexp.inspect}", regexp, actual
+ matcher.negative_failure_message = "expected #{actual.inspect} not to match #{regexp.inspect}", regexp, actual
+ matcher.description = "match #{regexp.inspect}"
+ actual =~ regexp
+ end
end
end
end
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match_array.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match_array.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match_array.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/match_array.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,75 @@
+module Spec
+ module Matchers
+
+ class MatchArray #:nodoc:
+
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ @extra_items = difference_between_arrays(@actual, @expected)
+ @missing_items = difference_between_arrays(@expected, @actual)
+ @extra_items.empty? && @missing_items.empty?
+ end
+
+ def failure_message
+ message = "expected collection contained: #{@expected.sort.inspect}\n"
+ message += "actual collection contained: #{@actual.sort.inspect}\n"
+ message += "the missing elements were: #{@missing_items.sort.inspect}\n" unless @missing_items.empty?
+ message += "the extra elements were: #{@extra_items.sort.inspect}\n" unless @extra_items.empty?
+ message
+ end
+
+ def description
+ "contain exactly #{_pretty_print(@expected)}"
+ end
+
+ private
+
+ def difference_between_arrays(array_1, array_2)
+ difference = array_1.dup
+ array_2.each do |element|
+ if index = difference.index(element)
+ difference.delete_at(index)
+ end
+ end
+ difference
+ end
+
+ def _pretty_print(array)
+ result = ""
+ array.each_with_index do |item, index|
+ if index < (array.length - 2)
+ result << "#{item.inspect}, "
+ elsif index < (array.length - 1)
+ result << "#{item.inspect} and "
+ else
+ result << "#{item.inspect}"
+ end
+ end
+ result
+ end
+
+ end
+
+ # :call-seq:
+ # should =~ expected
+ #
+ # Passes if actual contains all of the expected regardless of order.
+ # This works for collections. Pass in multiple args and it will only
+ # pass if all args are found in collection.
+ #
+ # NOTE: there is no should_not version of array.should =~ other_array
+ #
+ # == Examples
+ #
+ # [1,2,3].should =~ [1,2,3] # => would pass
+ # [1,2,3].should =~ [2,3,1] # => would pass
+ # [1,2,3,4].should =~ [1,2,3] # => would fail
+ # [1,2,2,3].should =~ [1,2,3] # => would fail
+ # [1,2,3].should =~ [1,2,3,4] # => would fail
+ OperatorMatcher.register(Array, '=~', Spec::Matchers::MatchArray)
+ end
+end
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/method_missing.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,9 @@
+module Spec
+ module Matchers
+ def method_missing(sym, *args, &block) # :nodoc:
+ return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
+ return has(sym, *args) if sym.starts_with?("have_")
+ super
+ end
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/operator_matcher.rb Wed Dec 10 17:34:18 2008
@@ -1,70 +1,73 @@
module Spec
module Matchers
- class BaseOperatorMatcher
- attr_reader :generated_description
-
- def initialize(target)
- @target = target
- end
- def ==(expected)
- @expected = expected
- __delegate_method_missing_to_target("==", expected)
- end
+ class OperatorMatcher
+ @operator_registry = {}
- def ===(expected)
- @expected = expected
- __delegate_method_missing_to_target("===", expected)
+ def self.register(klass, operator, matcher)
+ @operator_registry[klass] ||= {}
+ @operator_registry[klass][operator] = matcher
end
- def =~(expected)
- @expected = expected
- __delegate_method_missing_to_target("=~", expected)
+ def self.get(klass, operator)
+ return @operator_registry[klass][operator] if @operator_registry[klass]
+ nil
end
- def >(expected)
- @expected = expected
- __delegate_method_missing_to_target(">", expected)
+ def initialize(actual)
+ @actual = actual
end
- def >=(expected)
- @expected = expected
- __delegate_method_missing_to_target(">=", expected)
+ def self.use_custom_matcher_or_delegate(operator)
+ define_method(operator) do |expected|
+ if matcher = OperatorMatcher.get(@actual.class, operator)
+ return @actual.send(matcher_method, matcher.new(expected))
+ else
+ ::Spec::Matchers.last_matcher = self
+ @operator, @expected = operator, expected
+ __delegate_operator(@actual, operator, expected)
+ end
+ end
end
- def <(expected)
- @expected = expected
- __delegate_method_missing_to_target("<", expected)
+ ['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
+ use_custom_matcher_or_delegate operator
end
- def <=(expected)
- @expected = expected
- __delegate_method_missing_to_target("<=", expected)
+ def fail_with_message(message)
+ Spec::Expectations.fail_with(message, @expected, @actual)
end
- def fail_with_message(message)
- Spec::Expectations.fail_with(message, @expected, @target)
+ def description
+ "#{@operator} #{@expected.inspect}"
end
end
- class PositiveOperatorMatcher < BaseOperatorMatcher #:nodoc:
+ class PositiveOperatorMatcher < OperatorMatcher #:nodoc:
+ def matcher_method
+ :should
+ end
- def __delegate_method_missing_to_target(operator, expected)
- ::Spec::Matchers.generated_description = "should #{operator} #{expected.inspect}"
- return if @target.send(operator, expected)
- return fail_with_message("expected: #{expected.inspect},\n got: #{@target.inspect} (using #{operator})") if ['==','===', '=~'].include?(operator)
- return fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
+ def __delegate_operator(actual, operator, expected)
+ return true if actual.__send__(operator, expected)
+ if ['==','===', '=~'].include?(operator)
+ fail_with_message("expected: #{expected.inspect},\n got: #{actual.inspect} (using #{operator})")
+ else
+ fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
+ end
end
end
- class NegativeOperatorMatcher < BaseOperatorMatcher #:nodoc:
+ class NegativeOperatorMatcher < OperatorMatcher #:nodoc:
+ def matcher_method
+ :should_not
+ end
- def __delegate_method_missing_to_target(operator, expected)
- ::Spec::Matchers.generated_description = "should not #{operator} #{expected.inspect}"
- return unless @target.send(operator, expected)
- return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
+ def __delegate_operator(actual, operator, expected)
+ return true unless actual.__send__(operator, expected)
+ return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/raise_error.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/raise_error.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/raise_error.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/raise_error.rb Wed Dec 10 17:34:18 2008
@@ -1,27 +1,27 @@
module Spec
module Matchers
class RaiseError #:nodoc:
- def initialize(error_or_message=Exception, message=nil, &block)
+ def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
@block = block
- case error_or_message
+ case expected_error_or_message
when String, Regexp
- @expected_error, @expected_message = Exception, error_or_message
+ @expected_error, @expected_message = Exception, expected_error_or_message
else
- @expected_error, @expected_message = error_or_message, message
+ @expected_error, @expected_message = expected_error_or_message, expected_message
end
end
- def matches?(proc)
+ def matches?(given_proc)
@raised_expected_error = false
@with_expected_message = false
@eval_block = false
@eval_block_passed = false
begin
- proc.call
- rescue @expected_error => @actual_error
+ given_proc.call
+ rescue @expected_error => @given_error
@raised_expected_error = true
@with_expected_message = verify_message
- rescue Exception => @actual_error
+ rescue Exception => @given_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,34 +37,30 @@
def eval_block
@eval_block = true
begin
- @block[@actual_error]
+ @block[@given_error]
@eval_block_passed = true
rescue Exception => err
- @actual_error = err
+ @given_error = err
end
end
def verify_message
case @expected_message
when nil
- return true
+ true
when Regexp
- return @expected_message =~ @actual_error.message
+ @expected_message =~ @given_error.message
else
- return @expected_message == @actual_error.message
+ @expected_message == @given_error.message
end
end
def failure_message
- if @eval_block
- return @actual_error.message
- else
- return "expected #{expected_error}#{actual_error}"
- end
+ @eval_block ? @given_error.message : "expected #{expected_error}#{given_error}"
end
def negative_failure_message
- "expected no #{expected_error}#{actual_error}"
+ "expected no #{expected_error}#{given_error}"
end
def description
@@ -83,8 +79,8 @@
end
end
- def actual_error
- @actual_error.nil? ? " but nothing was raised" : ", got #{@actual_error.inspect}"
+ def given_error
+ @given_error.nil? ? " but nothing was raised" : ", got #{@given_error.inspect}"
end
def negative_expectation?
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/respond_to.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/respond_to.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/respond_to.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/respond_to.rb Wed Dec 10 17:34:18 2008
@@ -7,9 +7,10 @@
@names_not_responded_to = []
end
- def matches?(target)
+ def matches?(given)
+ @given = given
@names.each do |name|
- unless target.respond_to?(name)
+ unless given.respond_to?(name)
@names_not_responded_to << name
end
end
@@ -17,15 +18,16 @@
end
def failure_message
- "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
+ "expected #{@given.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
end
def negative_failure_message
- "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
+ "expected #{@given.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
end
def description
- "respond to ##{@names.to_s}"
+ # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
+ "respond to #{@names.inspect}"
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb Wed Dec 10 17:34:18 2008
@@ -6,18 +6,18 @@
@block = block
end
- def matches?(actual, &block)
+ def matches?(given, &block)
@block = block if block
- @actual = actual
- @block.call(actual)
+ @given = given
+ @block.call(given)
end
def failure_message
- "expected #{@actual} to satisfy block"
+ "expected #{@given} to satisfy block"
end
def negative_failure_message
- "expected #{@actual} not to satisfy block"
+ "expected #{@given} not to satisfy block"
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb Wed Dec 10 17:34:18 2008
@@ -1,29 +1,132 @@
module Spec
module Matchers
class SimpleMatcher
- attr_reader :description
+ attr_writer :failure_message, :negative_failure_message, :description
def initialize(description, &match_block)
@description = description
@match_block = match_block
end
- def matches?(actual)
- @actual = actual
- return @match_block.call(@actual)
+ def matches?(given)
+ @given = given
+ case @match_block.arity
+ when 2
+ @match_block.call(@given, self)
+ else
+ @match_block.call(@given)
+ end
+ end
+
+ def description
+ @description || explanation
end
- def failure_message()
- return %[expected #{@description.inspect} but got #{@actual.inspect}]
+ def failure_message
+ @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
end
-
- def negative_failure_message()
- return %[expected not to get #{@description.inspect}, but got #{@actual.inspect}]
+
+ def negative_failure_message
+ @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
+ end
+
+ def explanation
+ "No description provided. See RDoc for simple_matcher()"
end
end
-
- def simple_matcher(message, &match_block)
- SimpleMatcher.new(message, &match_block)
+
+ # simple_matcher makes it easy for you to create your own custom matchers
+ # in just a few lines of code when you don't need all the power of a
+ # completely custom matcher object.
+ #
+ # The <tt>description</tt> argument will appear as part of any failure
+ # message, and is also the source for auto-generated descriptions.
+ #
+ # The <tt>match_block</tt> can have an arity of 1 or 2. The first block
+ # argument will be the given value. The second, if the block accepts it
+ # will be the matcher itself, giving you access to set custom failure
+ # messages in favor of the defaults.
+ #
+ # The <tt>match_block</tt> should return a boolean: <tt>true</tt>
+ # indicates a match, which will pass if you use <tt>should</tt> and fail
+ # if you use <tt>should_not</tt>. false (or nil) indicates no match,
+ # which will do the reverse: fail if you use <tt>should</tt> and pass if
+ # you use <tt>should_not</tt>.
+ #
+ # An error in the <tt>match_block</tt> will bubble up, resulting in a
+ # failure.
+ #
+ # == Example with default messages
+ #
+ # def be_even
+ # simple_matcher("an even number") { |given| given % 2 == 0 }
+ # end
+ #
+ # describe 2 do
+ # it "should be even" do
+ # 2.should be_even
+ # end
+ # end
+ #
+ # Given an odd number, this example would produce an error message stating:
+ # expected "an even number", got 3.
+ #
+ # Unfortunately, if you're a fan of auto-generated descriptions, this will
+ # produce "should an even number." Not the most desirable result. You can
+ # control that using custom messages:
+ #
+ # == Example with custom messages
+ #
+ # def rhyme_with(expected)
+ # simple_matcher("rhyme with #{expected.inspect}") do |given, matcher|
+ # matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
+ # matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
+ # given.rhymes_with? expected
+ # end
+ # end
+ #
+ # # OR
+ #
+ # def rhyme_with(expected)
+ # simple_matcher do |given, matcher|
+ # matcher.description = "rhyme with #{expected.inspect}"
+ # matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
+ # matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
+ # given.rhymes_with? expected
+ # end
+ # end
+ #
+ # describe "pecan" do
+ # it "should rhyme with 'be gone'" do
+ # nut = "pecan"
+ # nut.extend Rhymer
+ # nut.should rhyme_with("be gone")
+ # end
+ # end
+ #
+ # The resulting messages would be:
+ # description: rhyme with "be gone"
+ # failure_message: expected "pecan" to rhyme with "be gone"
+ # negative failure_message: expected "pecan" not to rhyme with "be gone"
+ #
+ # == Wrapped Expectations
+ #
+ # Because errors will bubble up, it is possible to wrap other expectations
+ # in a SimpleMatcher.
+ #
+ # def be_even
+ # simple_matcher("an even number") { |given| (given % 2).should == 0 }
+ # end
+ #
+ # BE VERY CAREFUL when you do this. Only use wrapped expectations for
+ # matchers that will always be used in only the positive
+ # (<tt>should</tt>) or negative (<tt>should_not</tt>), but not both.
+ # The reason is that is you wrap a <tt>should</tt> and call the wrapper
+ # with <tt>should_not</tt>, the correct result (the <tt>should</tt>
+ # failing), will fail when you want it to pass.
+ #
+ def simple_matcher(description=nil, &match_block)
+ SimpleMatcher.new(description, &match_block)
end
end
end
\ No newline at end of file
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/throw_symbol.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/throw_symbol.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/throw_symbol.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/matchers/throw_symbol.rb Wed Dec 10 17:34:18 2008
@@ -2,39 +2,60 @@
module Matchers
class ThrowSymbol #:nodoc:
- def initialize(expected=nil)
- @expected = expected
- @actual = nil
+ def initialize(expected_symbol = nil, expected_arg=nil)
+ @expected_symbol = expected_symbol
+ @expected_arg = expected_arg
+ @caught_symbol = nil
end
- def matches?(proc)
+ def matches?(given_proc)
begin
- proc.call
- rescue NameError => e
- raise e unless e.message =~ /uncaught throw/
- @actual = e.name.to_sym
+ if @expected_symbol.nil?
+ given_proc.call
+ else
+ @caught_arg = catch :proc_did_not_throw_anything do
+ catch @expected_symbol do
+ given_proc.call
+ throw :proc_did_not_throw_anything, :nothing_thrown
+ end
+ end
+ @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
+ end
+
+ # Ruby 1.8 uses NameError with `symbol'
+ # Ruby 1.9 uses ArgumentError with :symbol
+ rescue NameError, ArgumentError => e
+ raise e unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
+ @caught_symbol = $2.to_sym
+
ensure
- if @expected.nil?
- return @actual.nil? ? false : true
+ if @expected_symbol.nil?
+ return !@caught_symbol.nil?
else
- return @actual == @expected
+ if @expected_arg.nil?
+ return @caught_symbol == @expected_symbol
+ else
+ # puts [@caught_symbol, @expected_symbol].inspect
+ # puts [@caught_arg, @expected_arg].inspect
+ return @caught_symbol == @expected_symbol && @caught_arg == @expected_arg
+ end
end
end
end
def failure_message
- if @actual
- "expected #{expected}, got #{@actual.inspect}"
+ if @caught_symbol
+ "expected #{expected}, got #{@caught_symbol.inspect}"
else
"expected #{expected} but nothing was thrown"
end
end
def negative_failure_message
- if @expected
+ if @expected_symbol
"expected #{expected} not to be thrown"
else
- "expected no Symbol, got :#{@actual}"
+ "expected no Symbol, got :#{@caught_symbol}"
end
end
@@ -45,7 +66,11 @@
private
def expected
- @expected.nil? ? "a Symbol" : @expected.inspect
+ @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
+ end
+
+ def args
+ @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
end
end
@@ -53,20 +78,27 @@
# :call-seq:
# should throw_symbol()
# should throw_symbol(:sym)
+ # should throw_symbol(:sym, arg)
# should_not throw_symbol()
# should_not throw_symbol(:sym)
- #
- # Given a Symbol argument, matches if a proc throws the specified Symbol.
+ # should_not throw_symbol(:sym, arg)
#
# Given no argument, matches if a proc throws any Symbol.
#
+ # Given a Symbol, matches if the given proc throws the specified Symbol.
+ #
+ # Given a Symbol and an arg, matches if the given proc throws the
+ # specified Symbol with the specified arg.
+ #
# == Examples
#
# lambda { do_something_risky }.should throw_symbol
# lambda { do_something_risky }.should throw_symbol(:that_was_risky)
+ # lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit)
#
# lambda { do_something_risky }.should_not throw_symbol
# lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
+ # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
def throw_symbol(sym=nil)
Matchers::ThrowSymbol.new(sym)
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks.rb Wed Dec 10 17:34:18 2008
@@ -1,16 +1,5 @@
require 'spec/mocks/framework'
-require 'spec/mocks/methods'
-require 'spec/mocks/argument_constraint_matchers'
-require 'spec/mocks/spec_methods'
-require 'spec/mocks/proxy'
-require 'spec/mocks/mock'
-require 'spec/mocks/argument_expectation'
-require 'spec/mocks/message_expectation'
-require 'spec/mocks/order_group'
-require 'spec/mocks/errors'
-require 'spec/mocks/error_generator'
require 'spec/mocks/extensions/object'
-require 'spec/mocks/space'
module Spec
# == Mocks and Stubs
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_constraints.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_constraints.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_constraints.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_constraints.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,165 @@
+module Spec
+ module Mocks
+
+ # ArgumentConstraints are messages that you can include in message
+ # expectations to match arguments against a broader check than simple
+ # equality.
+ #
+ # With the exception of any_args() and no_args(), the constraints
+ # are all positional - they match against the arg in the given position.
+ module ArgumentConstraints
+
+ class AnyArgsConstraint
+ def description
+ "any args"
+ end
+ end
+
+ class AnyArgConstraint
+ def initialize(ignore)
+ end
+
+ def ==(other)
+ true
+ end
+ end
+
+ class NoArgsConstraint
+ def description
+ "no args"
+ end
+
+ def ==(args)
+ args == []
+ end
+ end
+
+ class RegexpConstraint
+ def initialize(regexp)
+ @regexp = regexp
+ end
+
+ def ==(value)
+ return value =~ @regexp unless value.is_a?(Regexp)
+ value == @regexp
+ end
+ end
+
+ class BooleanConstraint
+ def initialize(ignore)
+ end
+
+ def ==(value)
+ TrueClass === value || FalseClass === value
+ end
+ end
+
+ class HashIncludingConstraint
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def ==(actual)
+ @expected.each do | key, value |
+ return false unless actual.has_key?(key) && value == actual[key]
+ end
+ true
+ rescue NoMethodError => ex
+ return false
+ end
+
+ def description
+ "hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
+ end
+ end
+
+ class DuckTypeConstraint
+ def initialize(*methods_to_respond_to)
+ @methods_to_respond_to = methods_to_respond_to
+ end
+
+ def ==(value)
+ @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
+ end
+ end
+
+ class MatcherConstraint
+ def initialize(matcher)
+ @matcher = matcher
+ end
+
+ def ==(value)
+ @matcher.matches?(value)
+ end
+ end
+
+ class EqualityProxy
+ def initialize(given)
+ @given = given
+ end
+
+ def ==(expected)
+ @given == expected
+ end
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(any_args())
+ #
+ # Passes if object receives :message with any args at all. This is
+ # really a more explicit variation of object.should_receive(:message)
+ def any_args
+ AnyArgsConstraint.new
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(anything())
+ #
+ # Passes as long as there is an argument.
+ def anything
+ AnyArgConstraint.new(nil)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(no_args)
+ #
+ # Passes if no arguments are passed along with the message
+ def no_args
+ NoArgsConstraint.new
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(duck_type(:hello))
+ # object.should_receive(:message).with(duck_type(:hello, :goodbye))
+ #
+ # Passes if the argument responds to the specified messages.
+ #
+ # == Examples
+ #
+ # array = []
+ # display = mock('display')
+ # display.should_receive(:present_names).with(duck_type(:length, :each))
+ # => passes
+ def duck_type(*args)
+ DuckTypeConstraint.new(*args)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(boolean())
+ #
+ # Passes if the argument is boolean.
+ def boolean
+ BooleanConstraint.new(nil)
+ end
+
+ # :call-seq:
+ # object.should_receive(:message).with(hash_including(:this => that))
+ #
+ # Passes if the argument is a hash that includes the specified key/value
+ # pairs. If the hash includes other keys, it will still pass.
+ def hash_including(expected={})
+ HashIncludingConstraint.new(expected)
+ end
+ end
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb Wed Dec 10 17:34:18 2008
@@ -1,215 +1,48 @@
module Spec
module Mocks
-
- class MatcherConstraint
- def initialize(matcher)
- @matcher = matcher
- end
-
- def matches?(value)
- @matcher.matches?(value)
- end
- end
-
- class LiteralArgConstraint
- def initialize(literal)
- @literal_value = literal
- end
-
- def matches?(value)
- @literal_value == value
- end
- end
-
- class RegexpArgConstraint
- def initialize(regexp)
- @regexp = regexp
- end
-
- def matches?(value)
- return value =~ @regexp unless value.is_a?(Regexp)
- value == @regexp
- end
- end
-
- class AnyArgConstraint
- def initialize(ignore)
- end
-
- def ==(other)
- true
- end
-
- # TODO - need this?
- def matches?(value)
- true
- end
- end
-
- class AnyArgsConstraint
- def description
- "any args"
- end
- end
-
- class NoArgsConstraint
- def description
- "no args"
- end
-
- def ==(args)
- args == []
- end
- end
-
- class NumericArgConstraint
- def initialize(ignore)
- end
-
- def matches?(value)
- value.is_a?(Numeric)
- end
- end
-
- class BooleanArgConstraint
- def initialize(ignore)
- end
-
- def ==(value)
- matches?(value)
- end
-
- def matches?(value)
- return true if value.is_a?(TrueClass)
- return true if value.is_a?(FalseClass)
- false
- end
- end
-
- class StringArgConstraint
- def initialize(ignore)
- end
-
- def matches?(value)
- value.is_a?(String)
- end
- end
-
- class DuckTypeArgConstraint
- def initialize(*methods_to_respond_to)
- @methods_to_respond_to = methods_to_respond_to
- end
-
- def matches?(value)
- @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
- end
-
- def description
- "duck_type"
- end
- end
-
- class HashIncludingConstraint
- def initialize(expected)
- @expected = expected
- end
-
- def ==(actual)
- @expected.each do | key, value |
- # check key for case that value evaluates to nil
- return false unless actual.has_key?(key) && actual[key] == value
- end
- true
- rescue NoMethodError => ex
- return false
- end
-
- def matches?(value)
- self == value
- end
-
- def description
- "hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
- end
-
- end
-
class ArgumentExpectation
attr_reader :args
- @@constraint_classes = Hash.new { |hash, key| LiteralArgConstraint}
- @@constraint_classes[:anything] = AnyArgConstraint
- @@constraint_classes[:numeric] = NumericArgConstraint
- @@constraint_classes[:boolean] = BooleanArgConstraint
- @@constraint_classes[:string] = StringArgConstraint
def initialize(args, &block)
@args = args
@constraints_block = block
- if [:any_args] == args
- @expected_params = nil
- warn_deprecated(:any_args.inspect, "any_args()")
- elsif args.length == 1 && args[0].is_a?(AnyArgsConstraint) then @expected_params = nil
- elsif [:no_args] == args
- @expected_params = []
- warn_deprecated(:no_args.inspect, "no_args()")
- elsif args.length == 1 && args[0].is_a?(NoArgsConstraint) then @expected_params = []
- else @expected_params = process_arg_constraints(args)
+ if ArgumentConstraints::AnyArgsConstraint === args.first
+ @match_any_args = true
+ elsif ArgumentConstraints::NoArgsConstraint === args.first
+ @constraints = []
+ else
+ @constraints = args.collect {|arg| constraint_for(arg)}
end
end
- def process_arg_constraints(constraints)
- constraints.collect do |constraint|
- convert_constraint(constraint)
- end
+ def constraint_for(arg)
+ return ArgumentConstraints::MatcherConstraint.new(arg) if is_matcher?(arg)
+ return ArgumentConstraints::RegexpConstraint.new(arg) if arg.is_a?(Regexp)
+ return ArgumentConstraints::EqualityProxy.new(arg)
end
- def warn_deprecated(deprecated_method, instead)
- Kernel.warn "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
+ def is_matcher?(obj)
+ return obj.respond_to?(:matches?) && obj.respond_to?(:description)
end
- def convert_constraint(constraint)
- if [:anything, :numeric, :boolean, :string].include?(constraint)
- case constraint
- when :anything
- instead = "anything()"
- when :boolean
- instead = "boolean()"
- when :numeric
- instead = "an_instance_of(Numeric)"
- when :string
- instead = "an_instance_of(String)"
- end
- warn_deprecated(constraint.inspect, instead)
- return @@constraint_classes[constraint].new(constraint)
- end
- return MatcherConstraint.new(constraint) if is_matcher?(constraint)
- return RegexpArgConstraint.new(constraint) if constraint.is_a?(Regexp)
- return LiteralArgConstraint.new(constraint)
+ def args_match?(given_args)
+ match_any_args? || constraints_block_matches?(given_args) || constraints_match?(given_args)
end
- def is_matcher?(obj)
- return obj.respond_to?(:matches?) && obj.respond_to?(:description)
+ def constraints_block_matches?(given_args)
+ @constraints_block ? @constraints_block.call(*given_args) : nil
end
- def check_args(args)
- if @constraints_block
- @constraints_block.call(*args)
- return true
- end
-
- return true if @expected_params.nil?
- return true if @expected_params == args
- return constraints_match?(args)
+ def constraints_match?(given_args)
+ @constraints == given_args
end
- def constraints_match?(args)
- return false if args.length != @expected_params.length
- @expected_params.each_index { |i| return false unless @expected_params[i].matches?(args[i]) }
- return true
+ def match_any_args?
+ @match_any_args
end
-
+
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/error_generator.rb Wed Dec 10 17:34:18 2008
@@ -44,7 +44,7 @@
private
def intro
- @name ? "Mock '#{@name}'" : @target.inspect
+ @name ? "Mock '#{@name}'" : @target.class == Class ? "<#{@target.inspect} (class)>" : (@target.nil? ? "nil" : @target.to_s)
end
def __raise(message)
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/framework.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/framework.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/framework.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/framework.rb Wed Dec 10 17:34:18 2008
@@ -3,7 +3,7 @@
# object in the system.
require 'spec/mocks/methods'
-require 'spec/mocks/argument_constraint_matchers'
+require 'spec/mocks/argument_constraints'
require 'spec/mocks/spec_methods'
require 'spec/mocks/proxy'
require 'spec/mocks/mock'
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/message_expectation.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/message_expectation.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/message_expectation.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/message_expectation.rb Wed Dec 10 17:34:18 2008
@@ -3,6 +3,10 @@
class BaseExpectation
attr_reader :sym
+ attr_writer :expected_received_count, :method_block, :expected_from
+ protected :expected_received_count=, :method_block=, :expected_from=
+ attr_accessor :error_generator
+ protected :error_generator, :error_generator=
def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={})
@error_generator = error_generator
@@ -13,7 +17,7 @@
@return_block = nil
@actual_received_count = 0
@expected_received_count = expected_received_count
- @args_expectation = ArgumentExpectation.new([AnyArgsConstraint.new])
+ @args_expectation = ArgumentExpectation.new([ArgumentConstraints::AnyArgsConstraint.new])
@consecutive = false
@exception_to_raise = nil
@symbol_to_throw = nil
@@ -23,6 +27,18 @@
@args_to_yield = []
end
+ def build_child(expected_from, method_block, expected_received_count, opts={})
+ child = clone
+ child.expected_from = expected_from
+ child.method_block = method_block
+ child.expected_received_count = expected_received_count
+ new_gen = error_generator.clone
+ new_gen.opts = opts
+ child.error_generator = new_gen
+ child.clone_args_to_yield @args_to_yield
+ child
+ end
+
def expected_args
@args_expectation.args
end
@@ -63,16 +79,22 @@
end
def and_yield(*args)
+ if @args_to_yield_were_cloned
+ @args_to_yield.clear
+ @args_to_yield_were_cloned = false
+ end
+
@args_to_yield << args
self
end
def matches(sym, args)
- @sym == sym and @args_expectation.check_args(args)
+ @sym == sym and @args_expectation.args_match?(args)
end
def invoke(args, block)
if @expected_received_count == 0
+ @failed_fast = true
@actual_received_count += 1
@error_generator.raise_expectation_error @sym, @expected_received_count, @actual_received_count, *args
end
@@ -103,6 +125,11 @@
@actual_received_count += 1
end
end
+
+ def called_max_times?
+ @expected_received_count != :any && @expected_received_count > 0 &&
+ @actual_received_count >= @expected_received_count
+ end
protected
@@ -147,16 +174,25 @@
@return_block.call(*args)
end
end
+
+ def clone_args_to_yield(args)
+ @args_to_yield = args.clone
+ @args_to_yield_were_cloned = true
+ end
+
+ def failed_fast?
+ @failed_fast
+ end
end
class MessageExpectation < BaseExpectation
def matches_name_but_not_args(sym, args)
- @sym == sym and not @args_expectation.check_args(args)
+ @sym == sym and not @args_expectation.args_match?(args)
end
def verify_messages_received
- return if expected_messages_received?
+ return if expected_messages_received? || failed_fast?
generate_error
rescue Spec::Mocks::MockExpectationError => error
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/methods.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/methods.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/methods.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/methods.rb Wed Dec 10 17:34:18 2008
@@ -9,8 +9,12 @@
__mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block)
end
- def stub!(sym, opts={})
- __mock_proxy.add_stub(caller(1)[0], sym.to_sym, opts)
+ def stub!(sym_or_hash, opts={})
+ if Hash === sym_or_hash
+ sym_or_hash.each {|method, value| stub!(method).and_return value }
+ else
+ __mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts)
+ end
end
def received_message?(sym, *args, &block) #:nodoc:
@@ -24,6 +28,14 @@
def rspec_reset #:nodoc:
__mock_proxy.reset
end
+
+ def as_null_object
+ __mock_proxy.as_null_object
+ end
+
+ def null_object?
+ __mock_proxy.null_object?
+ end
private
@@ -31,7 +43,7 @@
if Mock === self
@mock_proxy ||= Proxy.new(self, @name, @options)
else
- @mock_proxy ||= Proxy.new(self, self.class.name)
+ @mock_proxy ||= Proxy.new(self)
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/proxy.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/proxy.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/proxy.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/proxy.rb Wed Dec 10 17:34:18 2008
@@ -4,8 +4,18 @@
DEFAULT_OPTIONS = {
:null_object => false,
}
+
+ @@warn_about_expectations_on_nil = true
+
+ def self.allow_message_expectations_on_nil
+ @@warn_about_expectations_on_nil = false
+
+ # ensure nil.rspec_verify is called even if an expectation is not set in the example
+ # otherwise the allowance would effect subsequent examples
+ $rspec_mocks.add(nil) unless $rspec_mocks.nil?
+ end
- def initialize(target, name, options={})
+ def initialize(target, name=nil, options={})
@target = target
@name = name
@error_generator = ErrorGenerator.new target, name
@@ -20,15 +30,27 @@
def null_object?
@options[:null_object]
end
+
+ def as_null_object
+ @options[:null_object] = true
+ @target
+ end
- def add_message_expectation(expected_from, sym, opts={}, &block)
+ def add_message_expectation(expected_from, sym, opts={}, &block)
__add sym
- @expectations << MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
+ warn_if_nil_class sym
+ if existing_stub = @stubs.detect {|s| s.sym == sym }
+ expectation = existing_stub.build_child(expected_from, block_given?? block : nil, 1, opts)
+ else
+ expectation = MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
+ end
+ @expectations << expectation
@expectations.last
end
def add_negative_message_expectation(expected_from, sym, &block)
__add sym
+ warn_if_nil_class sym
@expectations << NegativeMessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
@expectations.last
end
@@ -50,6 +72,7 @@
clear_stubs
reset_proxied_methods
clear_proxied_methods
+ reset_nil_expectations_warning
end
def received_message?(sym, *args, &block)
@@ -61,18 +84,21 @@
end
def message_received(sym, *args, &block)
- if expectation = find_matching_expectation(sym, *args)
- expectation.invoke(args, block)
- elsif (stub = find_matching_method_stub(sym, *args))
+ expectation = find_matching_expectation(sym, *args)
+ stub = find_matching_method_stub(sym, *args)
+
+ if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
if expectation = find_almost_matching_expectation(sym, *args)
expectation.advise(args, block) unless expectation.expected_messages_received?
end
stub.invoke([], block)
+ elsif expectation
+ expectation.invoke(args, block)
elsif expectation = find_almost_matching_expectation(sym, *args)
expectation.advise(args, block) if null_object? unless expectation.expected_messages_received?
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?)
else
- @target.send :method_missing, sym, *args, &block
+ @target.__send__ :method_missing, sym, *args, &block
end
end
@@ -91,16 +117,24 @@
define_expected_method(sym)
end
+ def warn_if_nil_class(sym)
+ if proxy_for_nil_class? && @@warn_about_expectations_on_nil
+ Kernel.warn("An expectation of :#{sym} was set on nil. Called from #{caller[2]}. Use allow_message_expectations_on_nil to disable warnings.")
+ end
+ end
+
def define_expected_method(sym)
visibility_string = "#{visibility(sym)} :#{sym}"
- if target_responds_to?(sym) && !target_metaclass.method_defined?(munge(sym))
- munged_sym = munge(sym)
- target_metaclass.instance_eval do
- alias_method munged_sym, sym if method_defined?(sym.to_s)
+ unless @proxied_methods.include?(sym)
+ if target_responds_to?(sym)
+ munged_sym = munge(sym)
+ target_metaclass.instance_eval do
+ alias_method munged_sym, sym if method_defined?(sym.to_s)
+ end
+ @proxied_methods << sym
end
- @proxied_methods << sym
end
-
+
target_metaclass.class_eval(<<-EOF, __FILE__, __LINE__)
def #{sym}(*args, &block)
__mock_proxy.message_received :#{sym}, *args, &block
@@ -110,9 +144,9 @@
end
def target_responds_to?(sym)
- return @target.send(munge(:respond_to?),sym) if @already_proxied_respond_to
+ return @target.__send__(munge(:respond_to?),sym) if @already_proxied_respond_to
return @already_proxied_respond_to = true if sym == :respond_to?
- return @target.respond_to?(sym)
+ return @target.respond_to?(sym, true)
end
def visibility(sym)
@@ -161,11 +195,19 @@
alias_method sym, munged_sym
undef_method munged_sym
else
- undef_method sym
+ remove_method sym
end
end
end
end
+
+ def proxy_for_nil_class?
+ @target.nil?
+ end
+
+ def reset_nil_expectations_warning
+ @@warn_about_expectations_on_nil = true if proxy_for_nil_class?
+ end
def find_matching_expectation(sym, *args)
@expectations.find {|expectation| expectation.matches(sym, args)}
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/spec_methods.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/spec_methods.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/spec_methods.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/mocks/spec_methods.rb Wed Dec 10 17:34:18 2008
@@ -1,7 +1,7 @@
module Spec
module Mocks
module ExampleMethods
- include Spec::Mocks::ArgumentConstraintMatchers
+ include Spec::Mocks::ArgumentConstraints
# Shortcut for creating an instance of Spec::Mocks::Mock.
#
@@ -32,6 +32,14 @@
def stub_everything(name = 'stub')
mock(name, :null_object => true)
end
+
+ # Disables warning messages about expectations being set on nil.
+ #
+ # By default warning messages are issued when expectations are set on nil. This is to
+ # prevent false-positives and to catch potential bugs early on.
+ def allow_message_expectations_on_nil
+ Proxy.allow_message_expectations_on_nil
+ end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/spectask.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/spectask.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/spectask.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/spectask.rb Wed Dec 10 17:34:18 2008
@@ -56,12 +56,10 @@
# end
#
class SpecTask < ::Rake::TaskLib
- class << self
- def attr_accessor(*names)
- super(*names)
- names.each do |name|
- module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
- end
+ def self.attr_accessor(*names)
+ super(*names)
+ names.each do |name|
+ module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
end
end
@@ -107,7 +105,7 @@
# A message to print to stderr when there are failures.
attr_accessor :failure_message
- # Where RSpec's output is written. Defaults to STDOUT.
+ # Where RSpec's output is written. Defaults to $stdout.
# DEPRECATED. Use --format FORMAT:WHERE in spec_opts.
attr_accessor :out
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb Wed Dec 10 17:34:18 2008
@@ -35,11 +35,11 @@
def define
desc "Verify that rcov coverage is at least #{threshold}%"
task @name do
- total_coverage = nil
+ total_coverage = 0
File.open(index_html).each_line do |line|
- if line =~ /<tt class='coverage_total'>(\d+\.\d+)%<\/tt>/
- total_coverage = eval($1)
+ if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
+ total_coverage = $1.to_f
break
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner.rb Wed Dec 10 17:34:18 2008
@@ -164,38 +164,48 @@
# end
# end
module Runner
- class << self
- def configuration # :nodoc:
- @configuration ||= Spec::Example::Configuration.new
- end
-
- # Use this to configure various configurable aspects of
- # RSpec:
- #
- # Spec::Runner.configure do |configuration|
- # # Configure RSpec here
- # end
- #
- # The yielded <tt>configuration</tt> object is a
- # Spec::Example::Configuration instance. See its RDoc
- # for details about what you can do with it.
- #
- def configure
- yield configuration
- end
-
- def register_at_exit_hook # :nodoc:
- $spec_runner_at_exit_hook_registered ||= nil
- unless $spec_runner_at_exit_hook_registered
- at_exit do
- unless $! || Spec.run?
- success = Spec.run
- exit success if Spec.exit?
- end
+ def self.configuration # :nodoc:
+ @configuration ||= Spec::Example::Configuration.new
+ end
+
+ # Use this to configure various configurable aspects of
+ # RSpec:
+ #
+ # Spec::Runner.configure do |configuration|
+ # # Configure RSpec here
+ # end
+ #
+ # The yielded <tt>configuration</tt> object is a
+ # Spec::Example::Configuration instance. See its RDoc
+ # for details about what you can do with it.
+ #
+ def self.configure
+ yield configuration
+ end
+
+ def self.register_at_exit_hook # :nodoc:
+ unless @already_registered_at_exit_hook
+ at_exit do
+ unless $! || Spec.run? || Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?(options.example_groups)
+ success = Spec.run
+ exit success if Spec.exit?
end
- $spec_runner_at_exit_hook_registered = true
end
+ @already_registered_at_exit_hook = true
end
end
+
+ def self.options # :nodoc:
+ @options ||= begin
+ parser = ::Spec::Runner::OptionParser.new($stderr, $stdout)
+ parser.order!(ARGV)
+ parser.options
+ end
+ end
+
+ def self.use options
+ @options = options
+ end
+
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/backtrace_tweaker.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/backtrace_tweaker.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/backtrace_tweaker.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/backtrace_tweaker.rb Wed Dec 10 17:34:18 2008
@@ -40,15 +40,14 @@
def tweak_backtrace(error)
return if error.backtrace.nil?
- error.backtrace.collect! do |line|
- clean_up_double_slashes(line)
- IGNORE_PATTERNS.each do |ignore|
- if line =~ ignore
- line = nil
- break
+ error.backtrace.collect! do |message|
+ clean_up_double_slashes(message)
+ kept_lines = message.split("\n").select do |line|
+ IGNORE_PATTERNS.each do |ignore|
+ break if line =~ ignore
end
end
- line
+ kept_lines.empty?? nil : kept_lines.join("\n")
end
error.backtrace.compact!
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/class_and_arguments_parser.rb Wed Dec 10 17:34:18 2008
@@ -1,16 +1,14 @@
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
+ def self.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
\ No newline at end of file
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb Wed Dec 10 17:34:18 2008
@@ -2,26 +2,13 @@
module Spec
module Runner
- # Facade to run specs without having to fork a new ruby process (using `spec ...`)
class CommandLine
- class << self
- # Runs specs. +argv+ is the commandline args as per the spec commandline API, +err+
- # and +out+ are the streams output will be written to.
- def run(instance_rspec_options)
- # NOTE - this call to init_rspec_options is not spec'd, but neither is any of this
- # swapping of $rspec_options. That is all here to enable rspec to run against itself
- # and maintain coverage in a single process. Therefore, DO NOT mess with this stuff
- # unless you know what you are doing!
- init_rspec_options(instance_rspec_options)
- orig_rspec_options = rspec_options
- begin
- $rspec_options = instance_rspec_options
- return $rspec_options.run_examples
- ensure
- ::Spec.run = true
- $rspec_options = orig_rspec_options
- end
- end
+ def self.run(tmp_options=Spec::Runner.options)
+ orig_options = Spec::Runner.options
+ Spec::Runner.use tmp_options
+ tmp_options.run_examples
+ ensure
+ Spec::Runner.use orig_options
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_formatter.rb Wed Dec 10 17:34:18 2008
@@ -45,7 +45,9 @@
# 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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb Wed Dec 10 17:34:18 2008
@@ -14,20 +14,16 @@
def initialize(options, where)
super
if where.is_a?(String)
+ FileUtils.mkdir_p(File.dirname(where))
@output = File.open(where, 'w')
- elsif where == STDOUT
- @output = Kernel
- def @output.flush
- STDOUT.flush
- end
else
@output = where
end
@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)
@@ -74,14 +70,15 @@
@output.puts
@output.puts "Pending:"
@pending_examples.each do |pending_example|
- @output.puts "#{pending_example[0]} (#{pending_example[1]})"
+ @output.puts "\n#{pending_example[0]} (#{pending_example[1]})"
+ @output.puts "#{pending_example[2]}\n"
end
end
@output.flush
end
def close
- if IO === @output
+ if IO === @output && @output != $stdout
@output.close
end
end
@@ -112,7 +109,7 @@
def output_to_tty?
begin
- @output == Kernel || @output.tty?
+ @output.tty? || ENV.has_key?("AUTOTEST")
rescue NoMethodError
false
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb Wed Dec 10 17:34:18 2008
@@ -85,7 +85,7 @@
@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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/nested_text_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/nested_text_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/nested_text_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/nested_text_formatter.rb Wed Dec 10 17:34:18 2008
@@ -40,7 +40,7 @@
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
@@ -52,9 +52,9 @@
def described_example_group_chain
example_group_chain = []
- example_group.send(:execute_in_class_hierarchy) do |parent_example_group|
- if parent_example_group.description_args && !parent_example_group.description_args.empty?
- example_group_chain << parent_example_group
+ example_group.__send__(:each_ancestor_example_group_class) do |example_group_class|
+ unless example_group_class.description_args.empty?
+ example_group_chain << example_group_class
end
end
example_group_chain
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/progress_bar_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/progress_bar_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/progress_bar_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/progress_bar_formatter.rb Wed Dec 10 17:34:18 2008
@@ -14,9 +14,9 @@
@output.flush
end
- def example_pending(example, message)
+ def example_pending(example, message, pending_caller)
super
- @output.print yellow('P')
+ @output.print yellow('*')
@output.flush
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/specdoc_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/specdoc_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/specdoc_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/specdoc_formatter.rb Wed Dec 10 17:34:18 2008
@@ -28,7 +28,7 @@
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
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/html_formatter.rb Wed Dec 10 17:34:18 2008
@@ -86,6 +86,7 @@
end
def scenario_started(story_title, scenario_name)
+ @previous_type = nil
@scenario_failed = false
@scenario_text = <<-EOF
<dt>Scenario: #{h scenario_name}</dt>
@@ -149,10 +150,22 @@
spans = args.map { |arg| "<span class=\"param\">#{arg}</span>" }
desc_string = description.step_name
arg_regexp = description.arg_regexp
+ inner = if(type == @previous_type)
+ "And "
+ else
+ "#{type.to_s.capitalize} "
+ end
i = -1
- inner = type.to_s.capitalize + ' ' + desc_string.gsub(arg_regexp) { |param| spans[i+=1] }
+ inner += desc_string.gsub(arg_regexp) { |param| spans[i+=1] }
+
@scenario_text += " <li class=\"#{klass}\">#{inner}</li>\n"
+ if type == :'given scenario'
+ @previous_type = :given
+ else
+ @previous_type = type
+ end
+
end
end
end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/plain_text_formatter.rb Wed Dec 10 17:34:18 2008
@@ -104,7 +104,14 @@
end
def run_ended
- @output.puts "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
+ summary_text = "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending"
+ if !@failed_scenarios.empty?
+ @output.puts red(summary_text)
+ elsif !@pending_steps.empty?
+ @output.puts yellow(summary_text)
+ else
+ @output.puts green(summary_text)
+ end
unless @pending_steps.empty?
@output.puts "\nPending Steps:"
@pending_steps.each_with_index do |pending, i|
@@ -116,11 +123,10 @@
@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")}
-]
+ @output.print "\n #{i+1}) "
+ @output.print red("#{title} (#{scenario_name}) FAILED")
+ @output.print red("\n #{err.class}: #{err.message}")
+ @output.print "\n #{err.backtrace.join("\n")}\n"
end
end
end
Added: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/progress_bar_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/progress_bar_formatter.rb?rev=725524&view=auto
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/progress_bar_formatter.rb (added)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/formatter/story/progress_bar_formatter.rb Wed Dec 10 17:34:18 2008
@@ -0,0 +1,42 @@
+require 'spec/runner/formatter/story/plain_text_formatter'
+
+module Spec
+ module Runner
+ module Formatter
+ module Story
+ class ProgressBarFormatter < PlainTextFormatter
+
+ def story_started(title, narrative) end
+ def story_ended(title, narrative) end
+
+ def run_started(count)
+ @start_time = Time.now
+ super
+ end
+
+ def run_ended
+ @output.puts
+ @output.puts
+ @output.puts "Finished in %f seconds" % (Time.now - @start_time)
+ @output.puts
+ super
+ end
+
+ def scenario_ended
+ if @scenario_failed
+ @output.print red('F')
+ @output.flush
+ elsif @scenario_pending
+ @output.print yellow('P')
+ @output.flush
+ else
+ @output.print green('.')
+ @output.flush
+ end
+ end
+
+ end
+ end
+ end
+ end
+end
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/heckle_runner.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/heckle_runner.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/heckle_runner.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/lib/spec/runner/heckle_runner.rb Wed Dec 10 17:34:18 2008
@@ -25,7 +25,7 @@
def heckle_method(class_name, method_name)
verify_constant(class_name)
- heckle = @heckle_class.new(class_name, method_name, rspec_options)
+ heckle = @heckle_class.new(class_name, method_name, Spec::Runner.options)
heckle.validate
end
@@ -39,7 +39,7 @@
classes.each do |klass|
klass.instance_methods(false).each do |method_name|
- heckle = @heckle_class.new(klass.name, method_name, rspec_options)
+ heckle = @heckle_class.new(klass.name, method_name, Spec::Runner.options)
heckle.validate
end
end