summaryrefslogtreecommitdiffstats
path: root/test/lib/spec/runner
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-23 01:17:33 -0500
committerLuke Kanies <luke@madstop.com>2007-08-23 01:17:33 -0500
commitd59315a07a8a01ca65952d8e8fe9d2f1bb84d30e (patch)
tree8e2470f271c8c6e622f0aef3fd5a2f01502d8305 /test/lib/spec/runner
parent5601ecf75d3854a66d087a108e1b06885fa2be12 (diff)
downloadpuppet-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/runner')
-rw-r--r--test/lib/spec/runner/context.rb154
-rw-r--r--test/lib/spec/runner/context_eval.rb142
-rw-r--r--test/lib/spec/runner/context_runner.rb55
-rw-r--r--test/lib/spec/runner/execution_context.rb17
-rw-r--r--test/lib/spec/runner/heckle_runner_win.rb10
-rwxr-xr-xtest/lib/spec/runner/spec_matcher.rb25
-rw-r--r--test/lib/spec/runner/spec_should_raise_handler.rb74
-rw-r--r--test/lib/spec/runner/specification.rb114
8 files changed, 0 insertions, 591 deletions
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