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 | |
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.
22 files changed, 0 insertions, 1417 deletions
diff --git a/test/lib/spec/callback.rb b/test/lib/spec/callback.rb deleted file mode 100644 index aa7ecec0f..000000000 --- a/test/lib/spec/callback.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec/callback/callback_container' -require 'spec/callback/extensions/module' -require 'spec/callback/extensions/object' - -# Callback is a fork of Brian Takita's "callback library" (see http://callback.rubyforge.org), -# which Brian graciously contributed to RSpec in order to avoid the dependency. -# -# RSpec uses Callback internally to create hooks to Spec::Runner events. If you're interested -# in a simple, powerful API for generating callback events, check out http://callback.rubyforge.org. -module Callback -end diff --git a/test/lib/spec/callback/callback_container.rb b/test/lib/spec/callback/callback_container.rb deleted file mode 100644 index 24d4c0ced..000000000 --- a/test/lib/spec/callback/callback_container.rb +++ /dev/null @@ -1,60 +0,0 @@ -module Callback - class CallbackContainer - def initialize - @callback_registry = Hash.new do |hash, key| - hash[key] = Array.new - end - end - - # Defines the callback with the key in this container. - def define(key, callback_proc=nil, &callback_block) - callback = extract_callback(callback_block, callback_proc) do - raise "You must define the callback that accepts the call method." - end - @callback_registry[key] << callback - callback - end - - # Undefines the callback with the key in this container. - def undefine(key, callback_proc) - callback = extract_callback(callback_proc) do - raise "You may only undefine callbacks that use the call method." - end - @callback_registry[key].delete callback - callback - end - - # Notifies the callbacks for the key. Arguments may be passed. - # An error handler may be passed in as a block. If there is an error, the block is called with - # error object as an argument. - # An array of the return values of the callbacks is returned. - def notify(key, *args, &error_handler) - @callback_registry[key].collect do |callback| - begin - callback.call(*args) - rescue Exception => e - yield(e) if error_handler - end - end - end - - # Clears all of the callbacks in this container. - def clear - @callback_registry.clear - end - - protected - def extract_callback(first_choice_callback, second_choice_callback = nil) - callback = nil - if first_choice_callback - callback = first_choice_callback - elsif second_choice_callback - callback = second_choice_callback - end - unless callback.respond_to? :call - yield - end - return callback - end - end -end diff --git a/test/lib/spec/callback/extensions/module.rb b/test/lib/spec/callback/extensions/module.rb deleted file mode 100644 index 429268ed1..000000000 --- a/test/lib/spec/callback/extensions/module.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Callback - module ModuleMethods - # For each event_name submitted, defines a callback event with this name. - # Client code can then register as a callback listener using object.event_name. - def callback_events(*event_names) - event_names.each do |event_name| - define_callback_event(event_name) - end - end - - private - def define_callback_event(event_name) - module_eval <<-EOS - def #{event_name}(&block) - register_callback(:#{event_name}, &block) - end - EOS - end - end -end - -class Module - include Callback::ModuleMethods -end diff --git a/test/lib/spec/callback/extensions/object.rb b/test/lib/spec/callback/extensions/object.rb deleted file mode 100644 index c6ac6fd14..000000000 --- a/test/lib/spec/callback/extensions/object.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Callback - module InstanceMethods - # Registers a callback for the event on the object. The callback can either be a block or a proc. - # When the callbacks are notified, the return value of the proc is passed to the caller. - def register_callback(event, callback_proc=nil, &callback_block) - callbacks.define(event, callback_proc, &callback_block) - end - - # Removes the callback from the event. The callback proc must be the same - # object as the one that was passed to register_callback. - def unregister_callback(event, callback_proc) - callbacks.undefine(event, callback_proc) - end - - protected - # Notifies the callbacks registered with the event on the object. Arguments can be passed to the callbacks. - # An error handler may be passed in as a block. If there is an error, the block is called with - # error object as an argument. - # An array of the return values of the callbacks is returned. - def notify_callbacks(event, *args, &error_handler) - callbacks.notify(event, *args, &error_handler) - end - - def notify_class_callbacks(event, *args, &error_handler) - self.class.send(:notify_callbacks, event, *args, &error_handler) - end - - # The CallbackContainer for this object. - def callbacks - @callbacks ||= CallbackContainer.new - end - end -end - -class Object - include Callback::InstanceMethods -end
\ No newline at end of file diff --git a/test/lib/spec/deprecated.rb b/test/lib/spec/deprecated.rb deleted file mode 100644 index e9c1cd829..000000000 --- a/test/lib/spec/deprecated.rb +++ /dev/null @@ -1,3 +0,0 @@ -def deprecated(&block) - block.call unless ENV['RSPEC_DISABLE_DEPRECATED_FEATURES'] == 'true' -end 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 diff --git a/test/lib/spec/mocks/mock_handler.rb b/test/lib/spec/mocks/mock_handler.rb deleted file mode 100644 index ef6f97a1c..000000000 --- a/test/lib/spec/mocks/mock_handler.rb +++ /dev/null @@ -1,166 +0,0 @@ -module Spec - module Mocks - class MockHandler - DEFAULT_OPTIONS = { - :null_object => false, - :auto_verify => true - } - - def initialize(target, name, options={}) - @target = target - @name = name - @error_generator = ErrorGenerator.new target, name - @expectation_ordering = OrderGroup.new @error_generator - @expectations = [] - @messages_received = [] - @stubs = [] - @proxied_methods = [] - @options = options ? DEFAULT_OPTIONS.dup.merge(options) : DEFAULT_OPTIONS - end - - def null_object? - @options[:null_object] - end - - def add_message_expectation(expected_from, sym, opts={}, &block) - __add expected_from, sym, block - @expectations << MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts) - @expectations.last - end - - def add_negative_message_expectation(expected_from, sym, &block) - __add expected_from, sym, block - @expectations << NegativeMessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil) - @expectations.last - end - - def add_stub(expected_from, sym) - __add expected_from, sym, nil - @stubs.unshift MethodStub.new(@error_generator, @expectation_ordering, expected_from, sym, nil) - @stubs.first - end - - def verify #:nodoc: - begin - verify_expectations - ensure - reset - end - end - - def reset - clear_expectations - clear_stubs - reset_proxied_methods - clear_proxied_methods - end - - def received_message?(sym, *args, &block) - return true if @messages_received.find {|array| array == [sym, args, block]} - return false - end - - def has_negative_expectation?(sym) - @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)} - 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) - stub.invoke([], block) - elsif expectation = find_almost_matching_expectation(sym, *args) - raise_unexpected_message_args_error(expectation, *args) unless has_negative_expectation?(sym) unless null_object? - else - @target.send :method_missing, sym, *args, &block - end - end - - def raise_unexpected_message_args_error(expectation, *args) - @error_generator.raise_unexpected_message_args_error expectation, *args - end - - def raise_unexpected_message_error(sym, *args) - @error_generator.raise_unexpected_message_error sym, *args - end - - private - - def __add(expected_from, sym, block) - # TODO - this is the only reference in the 'spec/mocks' to the Runner - current_spec = Runner::Specification.current - current_spec.after_teardown {verify} if current_spec && @options[:auto_verify] - define_expected_method(sym) - end - - def define_expected_method(sym) - if target_responds_to?(sym) && !@proxied_methods.include?(sym) - @proxied_methods << sym - metaclass.__send__(:alias_method, munge(sym), sym) - end - - metaclass_eval(<<-EOF, __FILE__, __LINE__) - def #{sym}(*args, &block) - __mock_handler.message_received :#{sym}, *args, &block - end - EOF - end - - def target_responds_to?(sym) - 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) - end - - def munge(sym) - "proxied_by_rspec__#{sym.to_s}".to_sym - end - - def clear_expectations - @expectations.clear - end - - def clear_stubs - @stubs.clear - end - - def clear_proxied_methods - @proxied_methods.clear - end - - def metaclass_eval(str, filename, lineno) - metaclass.class_eval(str, filename, lineno) - end - - def metaclass - (class << @target; self; end) - end - - def verify_expectations - @expectations.each do |expectation| - expectation.verify_messages_received - end - end - - def reset_proxied_methods - @proxied_methods.each do |sym| - metaclass.__send__(:alias_method, sym, munge(sym)) - metaclass.__send__(:undef_method, munge(sym)) - end - end - - def find_matching_expectation(sym, *args) - @expectations.find {|expectation| expectation.matches(sym, args)} - end - - def find_almost_matching_expectation(sym, *args) - @expectations.find {|expectation| expectation.matches_name_but_not_args(sym, args)} - end - - def find_matching_method_stub(sym) - @stubs.find {|stub| stub.matches(sym, [])} - end - - end - end -end
\ No newline at end of file diff --git a/test/lib/spec/runner/context.rb b/test/lib/spec/runner/context.rb deleted file mode 100644 index 3155e169a..000000000 --- a/test/lib/spec/runner/context.rb +++ /dev/null @@ -1,154 +0,0 @@ -module Spec - module Runner - class ContextEvalModule < Module - end - class Context - module InstanceMethods - def initialize(description, &context_block) - @description = description - - @context_eval_module = ContextEvalModule.new - @context_eval_module.extend ContextEval::ModuleMethods - @context_eval_module.include ContextEval::InstanceMethods - before_context_eval - @context_eval_module.class_eval(&context_block) - end - - def before_context_eval - end - - def inherit_context_eval_module_from(klass) - @context_eval_module.inherit klass - end - alias :inherit :inherit_context_eval_module_from - - def include(mod) - @context_eval_module.include(mod) - end - - def run(reporter, dry_run=false) - reporter.add_context(@description) - prepare_execution_context_class - errors = run_context_setup(reporter, dry_run) - - specifications.each do |specification| - specification_execution_context = execution_context(specification) - specification_execution_context.copy_instance_variables_from(@once_only_execution_context_instance, []) unless context_setup_block.nil? - specification.run(reporter, setup_block, teardown_block, dry_run, specification_execution_context) - end unless errors.length > 0 - - run_context_teardown(reporter, dry_run) - end - - def number_of_specs - specifications.length - end - - def matches?(full_description) - matcher ||= SpecMatcher.new(@description) - specifications.each do |spec| - return true if spec.matches?(matcher, full_description) - end - return false - end - - def run_single_spec(full_description) - return if @description == full_description - matcher = SpecMatcher.new(@description) - specifications.reject! do |spec| - !spec.matches?(matcher, full_description) - end - end - - def methods - my_methods = super - my_methods |= @context_eval_module.methods - my_methods - end - - protected - - def method_missing(*args) - @context_eval_module.method_missing(*args) - end - - def context_setup_block - @context_eval_module.send :context_setup_block - end - - def context_teardown_block - @context_eval_module.send :context_teardown_block - end - - def specifications - @context_eval_module.send :specifications - end - - def setup_block - @context_eval_module.send :setup_block - end - - def teardown_block - @context_eval_module.send :teardown_block - end - - def prepare_execution_context_class - weave_in_context_modules - execution_context_class - end - - def weave_in_context_modules - mods = context_modules - context_eval_module = @context_eval_module - execution_context_class.class_eval do - include context_eval_module - mods.each do |mod| - include mod - end - end - end - - def context_modules - @context_eval_module.send :context_modules - end - - def execution_context_class - @context_eval_module.send :execution_context_class - end - - def execution_context specification - execution_context_class.new(specification) - end - - def run_context_setup(reporter, dry_run) - errors = [] - unless dry_run - begin - @once_only_execution_context_instance = execution_context(nil) - @once_only_execution_context_instance.instance_eval(&context_setup_block) - rescue => e - errors << e - location = "context_setup" - reporter.spec_finished(location, e, location) if reporter - end - end - errors - end - - def run_context_teardown(reporter, dry_run) - unless dry_run - begin - @once_only_execution_context_instance ||= execution_context(nil) - @once_only_execution_context_instance.instance_eval(&context_teardown_block) - rescue => e - location = "context_teardown" - reporter.spec_finished(location, e, location) if reporter - end - end - end - - end - include InstanceMethods - end - end -end diff --git a/test/lib/spec/runner/context_eval.rb b/test/lib/spec/runner/context_eval.rb deleted file mode 100644 index 2cee8f1cd..000000000 --- a/test/lib/spec/runner/context_eval.rb +++ /dev/null @@ -1,142 +0,0 @@ -module Spec - module Runner - module ContextEval - module ModuleMethods - def inherit(klass) - @context_superclass = klass - derive_execution_context_class_from_context_superclass - end - - def include(mod) - context_modules << mod - mod.send :included, self - end - - def context_setup(&block) - context_setup_parts << block - end - - def context_teardown(&block) - context_teardown_parts << block - end - - def setup(&block) - setup_parts << block - end - - def teardown(&block) - teardown_parts << block - end - - def specify(spec_name=:__generate_description, opts={}, &block) - specifications << Specification.new(spec_name, opts, &block) - end - - def methods - my_methods = super - my_methods |= context_superclass.methods - my_methods - end - - protected - - def method_missing(method_name, *args) - if context_superclass.respond_to?(method_name) - return execution_context_class.send(method_name, *args) - end - super - end - - private - - def context_setup_block - parts = context_setup_parts.dup - add_context_superclass_method(:context_setup, parts) - create_block_from_parts(parts) - end - - def context_teardown_block - parts = context_teardown_parts.dup - add_context_superclass_method(:context_teardown, parts) - create_block_from_parts(parts) - end - - def setup_block - parts = setup_parts.dup - add_context_superclass_method(:setup, parts) - create_block_from_parts(parts) - end - - def teardown_block - parts = teardown_parts.dup - add_context_superclass_method(:teardown, parts) - create_block_from_parts(parts) - end - - def execution_context_class - @execution_context_class ||= derive_execution_context_class_from_context_superclass - end - - def derive_execution_context_class_from_context_superclass - @execution_context_class = Class.new(context_superclass) - @execution_context_class.class_eval do - include ::Spec::Runner::ExecutionContext::InstanceMethods - end - end - - def context_superclass - @context_superclass ||= Object - end - - def context_modules - @context_modules ||= [Spec::Matchers, Spec::Mocks] - end - - def specifications - @specifications ||= [] - end - - def context_setup_parts - @context_setup_parts ||= [] - end - - def context_teardown_parts - @context_teardown_parts ||= [] - end - - def setup_parts - @setup_parts ||= [] - end - - def teardown_parts - @teardown_parts ||= [] - end - - def add_context_superclass_method sym, parts - superclass_method = begin - context_superclass.instance_method(sym) - rescue - nil - end - parts.unshift superclass_method if superclass_method - end - - def create_block_from_parts(parts) - proc do - parts.each do |part| - if part.is_a?(UnboundMethod) - part.bind(self).call - else - instance_eval(&part) - end - end - end - end - end - - module InstanceMethods - end - - end - end -end diff --git a/test/lib/spec/runner/context_runner.rb b/test/lib/spec/runner/context_runner.rb deleted file mode 100644 index 0a4d7e6e9..000000000 --- a/test/lib/spec/runner/context_runner.rb +++ /dev/null @@ -1,55 +0,0 @@ -module Spec - module Runner - class ContextRunner - - def initialize(options) - @contexts = [] - @options = options - end - - def add_context(context) - return unless spec_description.nil? || context.matches?(spec_description) - context.run_single_spec(spec_description) if context.matches?(spec_description) - @contexts << context - end - - # Runs all contexts and returns the number of failures. - def run(exit_when_done) - @options.reporter.start(number_of_specs) - begin - @contexts.each do |context| - context.run(@options.reporter, @options.dry_run) - end - rescue Interrupt - ensure - @options.reporter.end - end - failure_count = @options.reporter.dump - - if(failure_count == 0 && !@options.heckle_runner.nil?) - heckle_runner = @options.heckle_runner - @options.heckle_runner = nil - context_runner = self.class.new(@options) - context_runner.instance_variable_set(:@contexts, @contexts) - heckle_runner.heckle_with(context_runner) - end - - if(exit_when_done) - exit_code = (failure_count == 0) ? 0 : 1 - exit(exit_code) - end - failure_count - end - - def number_of_specs - @contexts.inject(0) {|sum, context| sum + context.number_of_specs} - end - - private - def spec_description - @options.spec_name - end - - end - end -end diff --git a/test/lib/spec/runner/execution_context.rb b/test/lib/spec/runner/execution_context.rb deleted file mode 100644 index 484c55830..000000000 --- a/test/lib/spec/runner/execution_context.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Spec - module Runner - class ExecutionContext - module InstanceMethods - def initialize(*args) #:nodoc: - #necessary for RSpec's own specs - end - - def violated(message="") - raise Spec::Expectations::ExpectationNotMetError.new(message) - end - - end - include InstanceMethods - end - end -end
\ No newline at end of file diff --git a/test/lib/spec/runner/heckle_runner_win.rb b/test/lib/spec/runner/heckle_runner_win.rb deleted file mode 100644 index 031386599..000000000 --- a/test/lib/spec/runner/heckle_runner_win.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Spec
- module Runner
- # Dummy implementation for Windows that just fails (Heckle is not supported on Windows)
- class HeckleRunner
- def initialize(filter)
- raise "Heckle not supported on Windows"
- end
- end
- end
-end
diff --git a/test/lib/spec/runner/spec_matcher.rb b/test/lib/spec/runner/spec_matcher.rb deleted file mode 100755 index 687fdaa00..000000000 --- a/test/lib/spec/runner/spec_matcher.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Spec - module Runner - class SpecMatcher - - attr_writer :spec_desc - def initialize(context_desc, spec_desc=nil) - @context_desc = context_desc - @spec_desc = spec_desc - end - - def matches?(desc) - desc =~ /(^#{context_regexp} #{spec_regexp}$|^#{context_regexp}$|^#{spec_regexp}$)/ - end - - private - def context_regexp - Regexp.escape(@context_desc) - end - - def spec_regexp - Regexp.escape(@spec_desc) - end - end - end -end diff --git a/test/lib/spec/runner/spec_should_raise_handler.rb b/test/lib/spec/runner/spec_should_raise_handler.rb deleted file mode 100644 index c7fa41c4e..000000000 --- a/test/lib/spec/runner/spec_should_raise_handler.rb +++ /dev/null @@ -1,74 +0,0 @@ -module Spec - module Runner - class SpecShouldRaiseHandler - def initialize(file_and_line_number, opts) - @file_and_line_number = file_and_line_number - @options = opts - @expected_error_class = determine_error_class(opts) - @expected_error_message = determine_error_message(opts) - end - - def determine_error_class(opts) - if candidate = opts[:should_raise] - if candidate.is_a?(Class) - return candidate - elsif candidate.is_a?(Array) - return candidate[0] - else - return Exception - end - end - end - - def determine_error_message(opts) - if candidate = opts[:should_raise] - if candidate.is_a?(Array) - return candidate[1] - end - end - return nil - end - - def build_message(exception=nil) - if @expected_error_message.nil? - message = "specify block expected #{@expected_error_class.to_s}" - else - message = "specify block expected #{@expected_error_class.new(@expected_error_message.to_s).inspect}" - end - message << " but raised #{exception.inspect}" if exception - message << " but nothing was raised" unless exception - message << "\n" - message << @file_and_line_number - end - - def error_matches?(error) - return false unless error.kind_of?(@expected_error_class) - unless @expected_error_message.nil? - if @expected_error_message.is_a?(Regexp) - return false unless error.message =~ @expected_error_message - else - return false unless error.message == @expected_error_message - end - end - return true - end - - def handle(errors) - if @expected_error_class - if errors.empty? - errors << Spec::Expectations::ExpectationNotMetError.new(build_message) - else - error_to_remove = errors.detect do |error| - error_matches?(error) - end - if error_to_remove.nil? - errors.insert(0,Spec::Expectations::ExpectationNotMetError.new(build_message(errors[0]))) - else - errors.delete(error_to_remove) - end - end - end - end - end - end -end diff --git a/test/lib/spec/runner/specification.rb b/test/lib/spec/runner/specification.rb deleted file mode 100644 index de8d750fd..000000000 --- a/test/lib/spec/runner/specification.rb +++ /dev/null @@ -1,114 +0,0 @@ -module Spec - module Runner - class Specification - - class << self - attr_accessor :current, :generated_description - protected :current= - - callback_events :before_setup, :after_teardown - end - - attr_reader :spec_block - callback_events :before_setup, :after_teardown - - def initialize(name, opts={}, &spec_block) - @from = caller(0)[3] - @description = name - @options = opts - @spec_block = spec_block - @description_generated_callback = lambda { |desc| @generated_description = desc } - end - - def run(reporter, setup_block, teardown_block, dry_run, execution_context) - reporter.spec_started(name) if reporter - return reporter.spec_finished(name) if dry_run - - errors = [] - begin - set_current - setup_ok = setup_spec(execution_context, errors, &setup_block) - spec_ok = execute_spec(execution_context, errors) if setup_ok - teardown_ok = teardown_spec(execution_context, errors, &teardown_block) - ensure - clear_current - end - - SpecShouldRaiseHandler.new(@from, @options).handle(errors) - reporter.spec_finished(name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) if reporter - end - - def matches?(matcher, description) - matcher.spec_desc = name - matcher.matches?(description) - end - - private - def name - @description == :__generate_description ? generated_description : @description - end - - def generated_description - @generated_description || "NAME NOT GENERATED" - end - - def setup_spec(execution_context, errors, &setup_block) - notify_before_setup(errors) - execution_context.instance_eval(&setup_block) if setup_block - return errors.empty? - rescue => e - errors << e - return false - end - - def execute_spec(execution_context, errors) - begin - execution_context.instance_eval(&spec_block) - return true - rescue Exception => e - errors << e - return false - end - end - - def teardown_spec(execution_context, errors, &teardown_block) - execution_context.instance_eval(&teardown_block) if teardown_block - notify_after_teardown(errors) - return errors.empty? - rescue => e - errors << e - return false - end - - def notify_before_setup(errors) - notify_class_callbacks(:before_setup, self, &append_errors(errors)) - notify_callbacks(:before_setup, self, &append_errors(errors)) - end - - def notify_after_teardown(errors) - notify_callbacks(:after_teardown, self, &append_errors(errors)) - notify_class_callbacks(:after_teardown, self, &append_errors(errors)) - end - - def append_errors(errors) - proc {|error| errors << error} - end - - def set_current - Spec::Matchers.description_generated(&@description_generated_callback) - self.class.send(:current=, self) - end - - def clear_current - Spec::Matchers.unregister_callback(:description_generated, @description_generated_callback) - self.class.send(:current=, nil) - end - - def failure_location(setup_ok, spec_ok, teardown_ok) - return 'setup' unless setup_ok - return name unless spec_ok - return 'teardown' unless teardown_ok - end - end - end -end |