diff options
| author | Luke Kanies <luke@madstop.com> | 2007-08-23 01:17:33 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-08-23 01:17:33 -0500 |
| commit | d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e (patch) | |
| tree | 8e2470f271c8c6e622f0aef3fd5a2f01502d8305 /test/lib/spec/expectations | |
| parent | 5601ecf75d3854a66d087a108e1b06885fa2be12 (diff) | |
| download | puppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.tar.gz puppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.tar.xz puppet-d59315a07a8a01ca65952d8e8fe9d2f1bb84d30e.zip | |
Adding the second half of the rspec upgrade -- apparently the "git add" thing I used did not remove the old files, only add the new ones.
Diffstat (limited to 'test/lib/spec/expectations')
| -rw-r--r-- | test/lib/spec/expectations/extensions/proc.rb | 57 | ||||
| -rw-r--r-- | test/lib/spec/expectations/should.rb | 5 | ||||
| -rwxr-xr-x | test/lib/spec/expectations/should/base.rb | 64 | ||||
| -rw-r--r-- | test/lib/spec/expectations/should/change.rb | 69 | ||||
| -rw-r--r-- | test/lib/spec/expectations/should/have.rb | 128 | ||||
| -rwxr-xr-x | test/lib/spec/expectations/should/not.rb | 74 | ||||
| -rwxr-xr-x | test/lib/spec/expectations/should/should.rb | 81 | ||||
| -rw-r--r-- | test/lib/spec/expectations/sugar.rb | 47 |
8 files changed, 0 insertions, 525 deletions
diff --git a/test/lib/spec/expectations/extensions/proc.rb b/test/lib/spec/expectations/extensions/proc.rb deleted file mode 100644 index 8286708ed..000000000 --- a/test/lib/spec/expectations/extensions/proc.rb +++ /dev/null @@ -1,57 +0,0 @@ -module Spec - module Expectations - module ProcExpectations - # Given a receiver and a message (Symbol), specifies that the result - # of sending that message that receiver should change after - # executing the proc. - # - # lambda { @team.add player }.should_change(@team.players, :size) - # lambda { @team.add player }.should_change(@team.players, :size).by(1) - # lambda { @team.add player }.should_change(@team.players, :size).to(23) - # lambda { @team.add player }.should_change(@team.players, :size).from(22).to(23) - # - # You can use a block instead of a message and receiver. - # - # lambda { @team.add player }.should_change{@team.players.size} - # lambda { @team.add player }.should_change{@team.players.size}.by(1) - # lambda { @team.add player }.should_change{@team.players.size}.to(23) - # lambda { @team.add player }.should_change{@team.players.size}.from(22).to(23) - def should_change(receiver=nil, message=nil, &block) - should.change(receiver, message, &block) - end - - # Given a receiver and a message (Symbol), specifies that the result - # of sending that message that receiver should NOT change after - # executing the proc. - # - # lambda { @team.add player }.should_not_change(@team.players, :size) - # - # You can use a block instead of a message and receiver. - # - # lambda { @team.add player }.should_not_change{@team.players.size} - def should_not_change(receiver, message) - should.not.change(receiver, message) - end - - def should_raise(exception=Exception, message=nil) - should.raise(exception, message) - end - - def should_not_raise(exception=Exception, message=nil) - should.not.raise(exception, message) - end - - def should_throw(symbol) - should.throw(symbol) - end - - def should_not_throw(symbol=:___this_is_a_symbol_that_will_likely_never_occur___) - should.not.throw(symbol) - end - end - end -end - -class Proc - include Spec::Expectations::ProcExpectations -end
\ No newline at end of file diff --git a/test/lib/spec/expectations/should.rb b/test/lib/spec/expectations/should.rb deleted file mode 100644 index f64e6ff78..000000000 --- a/test/lib/spec/expectations/should.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec/expectations/should/base' -require 'spec/expectations/should/have' -require 'spec/expectations/should/not' -require 'spec/expectations/should/should' -require 'spec/expectations/should/change' diff --git a/test/lib/spec/expectations/should/base.rb b/test/lib/spec/expectations/should/base.rb deleted file mode 100755 index 1be4677e8..000000000 --- a/test/lib/spec/expectations/should/base.rb +++ /dev/null @@ -1,64 +0,0 @@ -module Spec - module Expectations - module Should - class Base - - #== and =~ will stay after the new syntax - def ==(expected) - __delegate_method_missing_to_target "==", "==", expected - end - - def =~(expected) - __delegate_method_missing_to_target "=~", "=~", expected - end - - #<, <=, >=, > are all implemented in Spec::Matchers::Be - # and will be removed with 0.9 - deprecated do - def <(expected) - __delegate_method_missing_to_target "<", "<", expected - end - - def <=(expected) - __delegate_method_missing_to_target "<=", "<=", expected - end - - def >=(expected) - __delegate_method_missing_to_target ">=", ">=", expected - end - - def >(expected) - __delegate_method_missing_to_target ">", ">", expected - end - end - - def default_message(expectation, expected=nil) - return "expected #{expected.inspect}, got #{@target.inspect} (using #{expectation})" if expectation == '==' - "expected #{expectation} #{expected.inspect}, got #{@target.inspect}" unless expectation == '==' - end - - def fail_with_message(message, expected=nil, target=nil) - Spec::Expectations.fail_with(message, expected, target) - end - - def find_supported_sym(original_sym) - ["#{original_sym}?", "#{original_sym}s?"].each do |alternate_sym| - return alternate_sym.to_s if @target.respond_to?(alternate_sym.to_s) - end - end - - deprecated do - def method_missing(original_sym, *args, &block) - if original_sym.to_s =~ /^not_/ - return Not.new(@target).__send__(sym, *args, &block) - end - if original_sym.to_s =~ /^have_/ - return have.__send__(original_sym.to_s[5..-1].to_sym, *args, &block) - end - __delegate_method_missing_to_target original_sym, find_supported_sym(original_sym), *args - end - end - end - end - end -end diff --git a/test/lib/spec/expectations/should/change.rb b/test/lib/spec/expectations/should/change.rb deleted file mode 100644 index 98304f1b3..000000000 --- a/test/lib/spec/expectations/should/change.rb +++ /dev/null @@ -1,69 +0,0 @@ -module Spec - module Expectations - module Should - class Change < Base - - def initialize(target, receiver=nil, message=nil, &block) - @block = block - @target = target - @receiver = receiver - @message = message - execute_change - evaluate_change - end - - def execute_change - @before_change = @block.nil? ? @receiver.send(@message) : @block.call - @target.call - @after_change = @block.nil? ? @receiver.send(@message) : @block.call - end - - def message - @message.nil? ? 'result' : @message - end - - def evaluate_change - if @before_change == @after_change - fail_with_message "#{message} should have changed, but is still #{@after_change.inspect}" - end - end - - def from(value) - if @before_change != value - fail_with_message "#{message} should have initially been #{value.inspect}, but was #{@before_change.inspect}" - end - self - end - - def to(value) - if @after_change != value - fail_with_message "#{message} should have been changed to #{value.inspect}, but is now #{@after_change.inspect}" - end - self - end - - def by(expected_delta) - if actual_delta != expected_delta - fail_with_message "#{message} should have been changed by #{expected_delta}, but was changed by #{actual_delta}" - end - self - end - - private - def actual_delta - @after_change - @before_change - end - end - - class NotChange < Change - def evaluate_change - if @before_change != @after_change - fail_with_message "#{@message} should not have changed, but did change from #{@before_change.inspect} to #{@after_change.inspect}" - end - end - end - - end - end -end - diff --git a/test/lib/spec/expectations/should/have.rb b/test/lib/spec/expectations/should/have.rb deleted file mode 100644 index 47ebe81db..000000000 --- a/test/lib/spec/expectations/should/have.rb +++ /dev/null @@ -1,128 +0,0 @@ -module Spec - module Expectations - module Should - class Have - def initialize(target, relativity=:exactly, expected=nil) - @target = target - init_collection_handler(target, relativity, expected) - init_item_handler(target) - end - - def init_collection_handler(target, relativity, expected) - @collection_handler = CollectionHandler.new(target, relativity, expected) - end - - def init_item_handler(target) - @item_handler = PositiveItemHandler.new(target) - end - - def method_missing(sym, *args) - if @collection_handler.wants_to_handle(sym) - @collection_handler.handle_message(sym, *args) - elsif @item_handler.wants_to_handle(sym) - @item_handler.handle_message(sym, *args) - else - Spec::Expectations.fail_with("target does not respond to #has_#{sym}?") - end - end - end - - class NotHave < Have - def init_item_handler(target) - @item_handler = NegativeItemHandler.new(target) - end - end - - class CollectionHandler - def initialize(target, relativity=:exactly, expected=nil) - @target = target - @expected = expected == :no ? 0 : expected - @at_least = (relativity == :at_least) - @at_most = (relativity == :at_most) - end - - def at_least(expected_number=nil) - @at_least = true - @at_most = false - @expected = expected_number == :no ? 0 : expected_number - self - end - - def at_most(expected_number=nil) - @at_least = false - @at_most = true - @expected = expected_number == :no ? 0 : expected_number - self - end - - def method_missing(sym, *args) - if @target.respond_to?(sym) - handle_message(sym, *args) - end - end - - def wants_to_handle(sym) - respond_to?(sym) || @target.respond_to?(sym) - end - - def handle_message(sym, *args) - return at_least(args[0]) if sym == :at_least - return at_most(args[0]) if sym == :at_most - Spec::Expectations.fail_with(build_message(sym, args)) unless as_specified?(sym, args) - end - - def build_message(sym, args) - message = "expected" - message += " at least" if @at_least - message += " at most" if @at_most - message += " #{@expected} #{sym}, got #{actual_size_of(collection(sym, args))}" - end - - def as_specified?(sym, args) - return actual_size_of(collection(sym, args)) >= @expected if @at_least - return actual_size_of(collection(sym, args)) <= @expected if @at_most - return actual_size_of(collection(sym, args)) == @expected - end - - def collection(sym, args) - @target.send(sym, *args) - end - - def actual_size_of(collection) - return collection.length if collection.respond_to? :length - return collection.size if collection.respond_to? :size - end - end - - class ItemHandler - def wants_to_handle(sym) - @target.respond_to?("has_#{sym}?") - end - - def initialize(target) - @target = target - end - - def fail_with(message) - Spec::Expectations.fail_with(message) - end - end - - class PositiveItemHandler < ItemHandler - def handle_message(sym, *args) - fail_with( - "expected #has_#{sym}?(#{args.collect{|arg| arg.inspect}.join(', ')}) to return true, got false" - ) unless @target.send("has_#{sym}?", *args) - end - end - - class NegativeItemHandler < ItemHandler - def handle_message(sym, *args) - fail_with( - "expected #has_#{sym}?(#{args.collect{|arg| arg.inspect}.join(', ')}) to return false, got true" - ) if @target.send("has_#{sym}?", *args) - end - end - end - end -end diff --git a/test/lib/spec/expectations/should/not.rb b/test/lib/spec/expectations/should/not.rb deleted file mode 100755 index 5ad530be6..000000000 --- a/test/lib/spec/expectations/should/not.rb +++ /dev/null @@ -1,74 +0,0 @@ -module Spec - module Expectations - module Should - - class Not < Base #:nodoc: - def initialize(target) - @target = target - @be_seen = false - end - - deprecated do - #Gone for 0.9 - def be(expected = :___no_arg) - @be_seen = true - return self if (expected == :___no_arg) - fail_with_message(default_message("should not be", expected)) if (@target.equal?(expected)) - end - - #Gone for 0.9 - def have(expected_number=nil) - NotHave.new(@target, :exactly, expected_number) - end - - #Gone for 0.9 - def change(receiver, message) - NotChange.new(@target, receiver, message) - end - - #Gone for 0.9 - def raise(exception=Exception, message=nil) - begin - @target.call - rescue exception => e - return unless message.nil? || e.message == message || (message.is_a?(Regexp) && e.message =~ message) - if e.kind_of?(exception) - failure_message = "expected no " - failure_message << exception.to_s - unless message.nil? - failure_message << " with " - failure_message << "message matching " if message.is_a?(Regexp) - failure_message << message.inspect - end - failure_message << ", got " << e.inspect - fail_with_message(failure_message) - end - rescue - true - end - end - - #Gone for 0.9 - def throw(symbol=:___this_is_a_symbol_that_will_likely_never_occur___) - begin - catch symbol do - @target.call - return true - end - fail_with_message("expected #{symbol.inspect} not to be thrown, but it was") - rescue NameError - true - end - end - - def __delegate_method_missing_to_target original_sym, actual_sym, *args - ::Spec::Matchers.generated_description = "should not #{original_sym} #{args[0].inspect}" - return unless @target.__send__(actual_sym, *args) - fail_with_message(default_message("not #{original_sym}", args[0])) - end - end - end - - end - end -end diff --git a/test/lib/spec/expectations/should/should.rb b/test/lib/spec/expectations/should/should.rb deleted file mode 100755 index cb9f3c4ce..000000000 --- a/test/lib/spec/expectations/should/should.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Spec - module Expectations - module Should # :nodoc: - - class Should < Base - - def initialize(target, expectation=nil) - @target = target - @be_seen = false - end - - deprecated do - #Gone for 0.9 - def not - Not.new(@target) - end - - #Gone for 0.9 - def be(expected = :___no_arg) - @be_seen = true - return self if (expected == :___no_arg) - if Symbol === expected - fail_with_message(default_message("should be", expected)) unless (@target.equal?(expected)) - else - fail_with_message("expected #{expected}, got #{@target} (using .equal?)") unless (@target.equal?(expected)) - end - end - - #Gone for 0.9 - def have(expected_number=nil) - Have.new(@target, :exactly, expected_number) - end - - #Gone for 0.9 - def change(receiver=nil, message=nil, &block) - Change.new(@target, receiver, message, &block) - end - - #Gone for 0.9 - def raise(exception=Exception, message=nil) - begin - @target.call - rescue exception => e - unless message.nil? - if message.is_a?(Regexp) - e.message.should =~ message - else - e.message.should == message - end - end - return - rescue => e - fail_with_message("expected #{exception}#{message.nil? ? "" : " with #{message.inspect}"}, got #{e.inspect}") - end - fail_with_message("expected #{exception}#{message.nil? ? "" : " with #{message.inspect}"} but nothing was raised") - end - - #Gone for 0.9 - def throw(symbol) - begin - catch symbol do - @target.call - fail_with_message("expected #{symbol.inspect} to be thrown, but nothing was thrown") - end - rescue NameError => e - fail_with_message("expected #{symbol.inspect} to be thrown, got #{e.inspect}") - end - end - end - - private - def __delegate_method_missing_to_target(original_sym, actual_sym, *args) - ::Spec::Matchers.generated_description = "should #{original_sym} #{args[0].inspect}" - return if @target.send(actual_sym, *args) - fail_with_message(default_message(original_sym, args[0]), args[0], @target) - end - end - - end - end -end diff --git a/test/lib/spec/expectations/sugar.rb b/test/lib/spec/expectations/sugar.rb deleted file mode 100644 index 906111f0e..000000000 --- a/test/lib/spec/expectations/sugar.rb +++ /dev/null @@ -1,47 +0,0 @@ -deprecated do -module Spec - module Expectations - # This module adds syntactic sugar that allows usage of should_* instead of should.* - module UnderscoreSugar - def handle_underscores_for_rspec! # :nodoc: - original_method_missing = instance_method(:method_missing) - class_eval do - def method_missing(sym, *args, &block) - _method_missing(sym, args, block) - end - - define_method :_method_missing do |sym, args, block| - return original_method_missing.bind(self).call(sym, *args, &block) unless sym.to_s =~ /^should_/ - if sym.to_s =~ /^should_not_/ - if __matcher.respond_to?(__strip_should_not(sym)) - return should_not(__matcher.__send__(__strip_should_not(sym), *args, &block)) - else - return Spec::Expectations::Should::Not.new(self).__send__(__strip_should_not(sym), *args, &block) if sym.to_s =~ /^should_not_/ - end - else - if __matcher.respond_to?(__strip_should(sym)) - return should(__matcher.__send__(__strip_should(sym), *args, &block)) - else - return Spec::Expectations::Should::Should.new(self).__send__(__strip_should(sym), *args, &block) - end - end - end - - def __strip_should(sym) # :nodoc - sym.to_s[7..-1] - end - - def __strip_should_not(sym) # :nodoc - sym.to_s[11..-1] - end - - def __matcher - @matcher ||= Spec::Matchers::Matcher.new - end - end - end - end - end -end - -end
\ No newline at end of file |
