From 4c37c385f6d821d5fea5c0635838987011eabc04 Mon Sep 17 00:00:00 2001 From: Chad Humphries Date: Mon, 29 Jun 2009 16:50:19 -0400 Subject: [PATCH] Spec->Rspec. Refactoring complete --- Rakefile | 6 +- bin/rspec | 4 +- lib/rspec/core.rb | 26 +++++++ lib/{spec => rspec}/core/behaviour.rb | 28 ++++---- lib/{spec => rspec}/core/configuration.rb | 36 +++++----- lib/{spec => rspec}/core/example.rb | 4 +- lib/rspec/core/formatters.rb | 16 +++++ .../core/formatters/base_formatter.rb | 14 ++-- .../core/formatters/base_text_formatter.rb | 2 +- .../formatters/documentation_formatter.rb | 2 +- .../core/formatters/progress_formatter.rb | 2 +- lib/{spec => rspec}/core/kernel_extensions.rb | 6 +- .../core/mocking/with_absolutely_nothing.rb | 2 +- .../core/mocking/with_mocha.rb | 2 +- lib/{spec => rspec}/core/mocking/with_rr.rb | 4 +- .../core/mocking/with_rspec.rb | 2 +- lib/{spec => rspec}/core/rake_task.rb | 2 +- lib/{spec => rspec}/core/runner.rb | 12 ++-- lib/{spec => rspec}/core/world.rb | 10 +-- lib/spec/core.rb | 26 ------- lib/spec/core/formatters.rb | 16 ----- script/console | 2 +- .../{spec => rspec}/core/behaviour_spec.rb | 72 +++++++++---------- .../core/configuration_spec.rb | 46 ++++++------ spec/lib/{spec => rspec}/core/example_spec.rb | 4 +- .../core/formatters/base_formatter_spec.rb | 4 +- .../documentation_formatter_spec.rb | 2 +- .../formatters/progress_formatter_spec.rb | 4 +- .../core/kernel_extensions_spec.rb | 4 +- spec/lib/{spec => rspec}/core/mocha_spec.rb | 6 +- spec/lib/rspec/core/runner_spec.rb | 41 +++++++++++ spec/lib/{spec => rspec}/core/world_spec.rb | 40 +++++------ spec/lib/rspec/core_spec.rb | 35 +++++++++ spec/lib/spec/core/runner_spec.rb | 41 ----------- spec/lib/spec/core_spec.rb | 35 --------- spec/resources/example_classes.rb | 2 +- spec/spec_helper.rb | 18 ++--- 37 files changed, 289 insertions(+), 289 deletions(-) create mode 100644 lib/rspec/core.rb rename lib/{spec => rspec}/core/behaviour.rb (86%) rename lib/{spec => rspec}/core/configuration.rb (82%) rename lib/{spec => rspec}/core/example.rb (97%) create mode 100644 lib/rspec/core/formatters.rb rename lib/{spec => rspec}/core/formatters/base_formatter.rb (88%) rename lib/{spec => rspec}/core/formatters/base_text_formatter.rb (99%) rename lib/{spec => rspec}/core/formatters/documentation_formatter.rb (99%) rename lib/{spec => rspec}/core/formatters/progress_formatter.rb (97%) rename lib/{spec => rspec}/core/kernel_extensions.rb (57%) rename lib/{spec => rspec}/core/mocking/with_absolutely_nothing.rb (92%) rename lib/{spec => rspec}/core/mocking/with_mocha.rb (94%) rename lib/{spec => rspec}/core/mocking/with_rr.rb (77%) rename lib/{spec => rspec}/core/mocking/with_rspec.rb (97%) rename lib/{spec => rspec}/core/rake_task.rb (99%) rename lib/{spec => rspec}/core/runner.rb (79%) rename lib/{spec => rspec}/core/world.rb (89%) delete mode 100644 lib/spec/core.rb delete mode 100644 lib/spec/core/formatters.rb rename spec/lib/{spec => rspec}/core/behaviour_spec.rb (72%) rename spec/lib/{spec => rspec}/core/configuration_spec.rb (64%) rename spec/lib/{spec => rspec}/core/example_spec.rb (91%) rename spec/lib/{spec => rspec}/core/formatters/base_formatter_spec.rb (96%) rename spec/lib/{spec => rspec}/core/formatters/documentation_formatter_spec.rb (56%) rename spec/lib/{spec => rspec}/core/formatters/progress_formatter_spec.rb (85%) rename spec/lib/{spec => rspec}/core/kernel_extensions_spec.rb (66%) rename spec/lib/{spec => rspec}/core/mocha_spec.rb (80%) create mode 100644 spec/lib/rspec/core/runner_spec.rb rename spec/lib/{spec => rspec}/core/world_spec.rb (80%) create mode 100644 spec/lib/rspec/core_spec.rb delete mode 100644 spec/lib/spec/core/runner_spec.rb delete mode 100644 spec/lib/spec/core_spec.rb diff --git a/Rakefile b/Rakefile index 500799734b..fb400862d5 100644 --- a/Rakefile +++ b/Rakefile @@ -16,13 +16,13 @@ rescue LoadError puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" end -require 'lib/spec/core/rake_task' -Spec::Core::RakeTask.new :spec do |t| +require 'lib/rspec/core/rake_task' +Rspec::Core::RakeTask.new :spec do |t| t.pattern = "spec/**/*_spec.rb" end desc "Run all examples using rcov" -Spec::Core::RakeTask.new :coverage do |t| +Rspec::Core::RakeTask.new :coverage do |t| t.pattern = "spec/**/*_spec.rb" t.rcov = true t.rcov_opts = %[--exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*" --text-summary --sort coverage] diff --git a/bin/rspec b/bin/rspec index f33ae57960..3c40fbddaa 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,4 +1,4 @@ #!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) -require 'spec/core' -Spec::Core.configuration.autorun! \ No newline at end of file +require 'rspec/core' +Rspec::Core.configuration.autorun! \ No newline at end of file diff --git a/lib/rspec/core.rb b/lib/rspec/core.rb new file mode 100644 index 0000000000..2589e8a746 --- /dev/null +++ b/lib/rspec/core.rb @@ -0,0 +1,26 @@ +require 'rspec/core/mocking/with_absolutely_nothing' +require 'rspec/core/world' +require 'rspec/core/configuration' +require 'rspec/core/runner' +require 'rspec/core/example' +require 'rspec/core/behaviour' +require 'rspec/core/kernel_extensions' +require 'rspec/core/formatters' + +module Rspec + module Core + + def self.configuration + @configuration ||= Rspec::Core::Configuration.new + end + + def self.configure + yield configuration if block_given? + end + + def self.world + @world ||= Rspec::Core::World.new + end + + end +end diff --git a/lib/spec/core/behaviour.rb b/lib/rspec/core/behaviour.rb similarity index 86% rename from lib/spec/core/behaviour.rb rename to lib/rspec/core/behaviour.rb index b05e493442..4e40552070 100644 --- a/lib/spec/core/behaviour.rb +++ b/lib/rspec/core/behaviour.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core class Behaviour @@ -6,8 +6,8 @@ class Behaviour def self.inherited(klass) super - Spec::Core.configuration.autorun! - Spec::Core.world.behaviours << klass + Rspec::Core.configuration.autorun! + Rspec::Core.world.behaviours << klass end def self.extended_modules #:nodoc: @@ -48,7 +48,7 @@ def self.after(type=:each, &block) end def self.example(desc=nil, options={}, &block) - examples << Spec::Core::Example.new(self, desc, options.update(:caller => caller[0]), block) + examples << Rspec::Core::Example.new(self, desc, options.update(:caller => caller[0]), block) end def self.alias_example_to(new_alias, extra_options={}) @@ -57,7 +57,7 @@ def self.#{new_alias}(desc=nil, options={}, &block) updated_options = options.update(:caller => caller[0]) updated_options.update(#{extra_options.inspect}) block = nil if updated_options[:pending] == true || updated_options[:disabled] == true - examples << Spec::Core::Example.new(self, desc, updated_options, block) + examples << Rspec::Core::Example.new(self, desc, updated_options, block) end END_RUBY module_eval(new_alias, __FILE__, __LINE__) @@ -94,12 +94,12 @@ def self.set_it_up(*args) @metadata.update(extra_metadata) - Spec::Core.configuration.find_modules(self).each do |include_or_extend, mod, opts| + Rspec::Core.configuration.find_modules(self).each do |include_or_extend, mod, opts| if include_or_extend == :extend - Spec::Core.configuration.trace { "Extending module #{mod} on #{self}" } + Rspec::Core.configuration.trace { "Extending module #{mod} on #{self}" } send(:extend, mod) unless extended_modules.include?(mod) else - Spec::Core.configuration.trace { "Including module #{mod} on #{self}" } + Rspec::Core.configuration.trace { "Including module #{mod} on #{self}" } send(:include, mod) unless included_modules.include?(mod) end end @@ -141,7 +141,7 @@ def self.ancestors(superclass_last=false) classes = [] current_class = self - while current_class < Spec::Core::Behaviour + while current_class < Rspec::Core::Behaviour superclass_last ? classes << current_class : classes.unshift(current_class) current_class = current_class.superclass end @@ -163,26 +163,26 @@ def self.before_all_ivars def self.eval_before_alls(running_behaviour) superclass.before_all_ivars.each { |ivar, val| running_behaviour.instance_variable_set(ivar, val) } - Spec::Core.configuration.find_before_or_after(:before, :all, self).each { |blk| running_behaviour.instance_eval(&blk) } + Rspec::Core.configuration.find_before_or_after(:before, :all, self).each { |blk| running_behaviour.instance_eval(&blk) } before_alls.each { |blk| running_behaviour.instance_eval(&blk) } running_behaviour.instance_variables.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) } end def self.eval_before_eachs(running_behaviour) - Spec::Core.configuration.find_before_or_after(:before, :each, self).each { |blk| running_behaviour.instance_eval(&blk) } + Rspec::Core.configuration.find_before_or_after(:before, :each, self).each { |blk| running_behaviour.instance_eval(&blk) } before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_behaviour.instance_eval(&blk) } } end def self.eval_after_alls(running_behaviour) after_alls.each { |blk| running_behaviour.instance_eval(&blk) } - Spec::Core.configuration.find_before_or_after(:after, :all, self).each { |blk| running_behaviour.instance_eval(&blk) } + Rspec::Core.configuration.find_before_or_after(:after, :all, self).each { |blk| running_behaviour.instance_eval(&blk) } before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) } end def self.eval_after_eachs(running_behaviour) after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_behaviour.instance_eval(&blk) } } - Spec::Core.configuration.find_before_or_after(:after, :each, self).each { |blk| running_behaviour.instance_eval(&blk) } + Rspec::Core.configuration.find_before_or_after(:after, :each, self).each { |blk| running_behaviour.instance_eval(&blk) } end def self.run(reporter) @@ -211,7 +211,7 @@ def self.subclass(base_name, &body) # :nodoc: end def self.to_s - self == Spec::Core::Behaviour ? 'Spec::Core::Behaviour' : name + self == Rspec::Core::Behaviour ? 'Rspec::Core::Behaviour' : name end end diff --git a/lib/spec/core/configuration.rb b/lib/rspec/core/configuration.rb similarity index 82% rename from lib/spec/core/configuration.rb rename to lib/rspec/core/configuration.rb index eb0fc67bb7..87c0eb1309 100644 --- a/lib/spec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core class Configuration # Regex patterns to scrub backtrace with @@ -35,7 +35,7 @@ def initialize @color_enabled = false @before_and_afters = { :before => { :each => [], :all => [] }, :after => { :each => [], :all => [] } } @include_or_extend_modules = [] - @formatter_to_use = Spec::Core::Formatters::ProgressFormatter + @formatter_to_use = Rspec::Core::Formatters::ProgressFormatter @filter, @exclusion_filter = nil, nil mock_with nil unless @mock_framework_established end @@ -43,7 +43,7 @@ def initialize # E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines # crazy_slow as an example variant that has the crazy_slow speed option def alias_example_to(new_name, extra_options={}) - Spec::Core::Behaviour.alias_example_to(new_name, extra_options) + Rspec::Core::Behaviour.alias_example_to(new_name, extra_options) end def cleaned_from_backtrace?(line) @@ -55,24 +55,24 @@ def mock_with(make_a_mockery_with=nil) @mock_framework = make_a_mockery_with mock_framework_class = case make_a_mockery_with.to_s when /mocha/i - require 'spec/core/mocking/with_mocha' - Spec::Core::Mocking::WithMocha + require 'rspec/core/mocking/with_mocha' + Rspec::Core::Mocking::WithMocha when /rr/i - require 'spec/core/mocking/with_rr' - Spec::Core::Mocking::WithRR + require 'rspec/core/mocking/with_rr' + Rspec::Core::Mocking::WithRR when /rspec/i - require 'spec/core/mocking/with_rspec' - Spec::Core::Mocking::WithRspec + require 'rspec/core/mocking/with_rspec' + Rspec::Core::Mocking::WithRspec else - require 'spec/core/mocking/with_absolutely_nothing' - Spec::Core::Mocking::WithAbsolutelyNothing + require 'rspec/core/mocking/with_absolutely_nothing' + Rspec::Core::Mocking::WithAbsolutelyNothing end - Spec::Core::Behaviour.send(:include, mock_framework_class) + Rspec::Core::Behaviour.send(:include, mock_framework_class) end def autorun! - Spec::Core::Runner.autorun + Rspec::Core::Runner.autorun end # Turn ANSI on with 'true', or off with 'false' @@ -95,8 +95,8 @@ def run_all_when_everything_filtered? def formatter=(formatter_to_use) @formatter_to_use = case formatter_to_use.to_s - when 'documentation' then Spec::Core::Formatters::DocumentationFormatter - when 'progress' then Spec::Core::Formatters::ProgressFormatter + when 'documentation' then Rspec::Core::Formatters::DocumentationFormatter + when 'progress' then Rspec::Core::Formatters::ProgressFormatter else raise(ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.") end end @@ -124,7 +124,7 @@ def puts(msg) output.puts(msg) end - # If true, Spec will provide detailed trace output of its self as it runs. + # If true, Rspec will provide detailed trace output of its self as it runs. # Can be turned on at the global (configuration) level or at the individual behaviour (describe) level. def trace? @trace == true @@ -141,7 +141,7 @@ def extend(mod, options={}) def find_modules(group) include_or_extend_modules.select do |include_or_extend, mod, options| options.all? do |filter_on, filter| - Spec::Core.world.apply_condition(filter_on, filter, group.metadata) + Rspec::Core.world.apply_condition(filter_on, filter, group.metadata) end end end @@ -157,7 +157,7 @@ def after(each_or_all=:each, options={}, &block) def find_before_or_after(desired_before_or_after, desired_each_or_all, group) before_and_afters[desired_before_or_after][desired_each_or_all].select do |options, block| options.all? do |filter_on, filter| - Spec::Core.world.apply_condition(filter_on, filter, group.metadata) + Rspec::Core.world.apply_condition(filter_on, filter, group.metadata) end end.map { |options, block| block } end diff --git a/lib/spec/core/example.rb b/lib/rspec/core/example.rb similarity index 97% rename from lib/spec/core/example.rb rename to lib/rspec/core/example.rb index 699be98424..583a7841ac 100644 --- a/lib/spec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core class Example @@ -49,7 +49,7 @@ def run_finished(status, results={}) record_results results.update(:status => status) finish_time = Time.now record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at]) - Spec::Core.configuration.formatter.example_finished(self) + Rspec::Core.configuration.formatter.example_finished(self) end def run_before_each diff --git a/lib/rspec/core/formatters.rb b/lib/rspec/core/formatters.rb new file mode 100644 index 0000000000..183634b10c --- /dev/null +++ b/lib/rspec/core/formatters.rb @@ -0,0 +1,16 @@ +require 'rspec/core/formatters/base_formatter' +require 'rspec/core/formatters/base_text_formatter' +require 'rspec/core/formatters/documentation_formatter' +require 'rspec/core/formatters/progress_formatter' + +module Rspec + + module Core + + module Formatters + + end + + end + +end \ No newline at end of file diff --git a/lib/spec/core/formatters/base_formatter.rb b/lib/rspec/core/formatters/base_formatter.rb similarity index 88% rename from lib/spec/core/formatters/base_formatter.rb rename to lib/rspec/core/formatters/base_formatter.rb index c250605fb4..a730cd2ac1 100644 --- a/lib/spec/core/formatters/base_formatter.rb +++ b/lib/rspec/core/formatters/base_formatter.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core @@ -15,15 +15,15 @@ def initialize end def configuration - Spec::Core.configuration + Rspec::Core.configuration end def output - Spec::Core.configuration.output + Rspec::Core.configuration.output end def trace(&blk) - Spec::Core.configuration.trace(trace_override_flag, &blk) + Rspec::Core.configuration.trace(trace_override_flag, &blk) end # Allow setting trace at the behaviour level as well globally @@ -32,7 +32,7 @@ def trace_override_flag end def profile_examples? - Spec::Core.configuration.profile_examples + Rspec::Core.configuration.profile_examples end def color_enabled? @@ -40,11 +40,11 @@ def color_enabled? end def pending_examples - @pending_examples ||= ::Spec::Core.world.find(examples, :positive, :execution_result => { :status => 'pending' }) + @pending_examples ||= ::Rspec::Core.world.find(examples, :positive, :execution_result => { :status => 'pending' }) end def failed_examples - @failed_examples ||= ::Spec::Core.world.find(examples, :positive, :execution_result => { :status => 'failed' }) + @failed_examples ||= ::Rspec::Core.world.find(examples, :positive, :execution_result => { :status => 'failed' }) end # This method is invoked before any examples are run, right after diff --git a/lib/spec/core/formatters/base_text_formatter.rb b/lib/rspec/core/formatters/base_text_formatter.rb similarity index 99% rename from lib/spec/core/formatters/base_text_formatter.rb rename to lib/rspec/core/formatters/base_text_formatter.rb index 7f38a603d5..a29730cfda 100644 --- a/lib/spec/core/formatters/base_text_formatter.rb +++ b/lib/rspec/core/formatters/base_text_formatter.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core diff --git a/lib/spec/core/formatters/documentation_formatter.rb b/lib/rspec/core/formatters/documentation_formatter.rb similarity index 99% rename from lib/spec/core/formatters/documentation_formatter.rb rename to lib/rspec/core/formatters/documentation_formatter.rb index b030bbfc41..eec635876c 100644 --- a/lib/spec/core/formatters/documentation_formatter.rb +++ b/lib/rspec/core/formatters/documentation_formatter.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core diff --git a/lib/spec/core/formatters/progress_formatter.rb b/lib/rspec/core/formatters/progress_formatter.rb similarity index 97% rename from lib/spec/core/formatters/progress_formatter.rb rename to lib/rspec/core/formatters/progress_formatter.rb index 8f23cb7b9c..cacba90621 100644 --- a/lib/spec/core/formatters/progress_formatter.rb +++ b/lib/rspec/core/formatters/progress_formatter.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core diff --git a/lib/spec/core/kernel_extensions.rb b/lib/rspec/core/kernel_extensions.rb similarity index 57% rename from lib/spec/core/kernel_extensions.rb rename to lib/rspec/core/kernel_extensions.rb index 0df8d9fe6f..96490064ab 100644 --- a/lib/spec/core/kernel_extensions.rb +++ b/lib/rspec/core/kernel_extensions.rb @@ -1,9 +1,9 @@ -module Spec +module Rspec module Core module KernelExtensions def describe(*args, &behaviour_block) - Spec::Core::Behaviour.describe(*args, &behaviour_block) + Rspec::Core::Behaviour.describe(*args, &behaviour_block) end alias :context :describe @@ -12,4 +12,4 @@ def describe(*args, &behaviour_block) end end -include Spec::Core::KernelExtensions \ No newline at end of file +include Rspec::Core::KernelExtensions \ No newline at end of file diff --git a/lib/spec/core/mocking/with_absolutely_nothing.rb b/lib/rspec/core/mocking/with_absolutely_nothing.rb similarity index 92% rename from lib/spec/core/mocking/with_absolutely_nothing.rb rename to lib/rspec/core/mocking/with_absolutely_nothing.rb index 3603a517d7..775b5f3e05 100644 --- a/lib/spec/core/mocking/with_absolutely_nothing.rb +++ b/lib/rspec/core/mocking/with_absolutely_nothing.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core module Mocking module WithAbsolutelyNothing diff --git a/lib/spec/core/mocking/with_mocha.rb b/lib/rspec/core/mocking/with_mocha.rb similarity index 94% rename from lib/spec/core/mocking/with_mocha.rb rename to lib/rspec/core/mocking/with_mocha.rb index 78029c3b62..50c9341631 100644 --- a/lib/spec/core/mocking/with_mocha.rb +++ b/lib/rspec/core/mocking/with_mocha.rb @@ -1,7 +1,7 @@ require 'mocha/standalone' require 'mocha/object' -module Spec +module Rspec module Core module Mocking module WithMocha diff --git a/lib/spec/core/mocking/with_rr.rb b/lib/rspec/core/mocking/with_rr.rb similarity index 77% rename from lib/spec/core/mocking/with_rr.rb rename to lib/rspec/core/mocking/with_rr.rb index 30280848d0..586d4fe865 100644 --- a/lib/spec/core/mocking/with_rr.rb +++ b/lib/rspec/core/mocking/with_rr.rb @@ -1,8 +1,8 @@ require 'rr' -Spec::Core.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER) +Rspec::Core.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER) -module Spec +module Rspec module Core module Mocking module WithRR diff --git a/lib/spec/core/mocking/with_rspec.rb b/lib/rspec/core/mocking/with_rspec.rb similarity index 97% rename from lib/spec/core/mocking/with_rspec.rb rename to lib/rspec/core/mocking/with_rspec.rb index 3bf7320f15..8288048591 100644 --- a/lib/spec/core/mocking/with_rspec.rb +++ b/lib/rspec/core/mocking/with_rspec.rb @@ -1,7 +1,7 @@ require 'spec/mocks/framework' require 'spec/mocks/extensions' -module Spec +module Rspec module Core module Mocking module WithRspec diff --git a/lib/spec/core/rake_task.rb b/lib/rspec/core/rake_task.rb similarity index 99% rename from lib/spec/core/rake_task.rb rename to lib/rspec/core/rake_task.rb index 7764a459ab..d3809b6fdf 100644 --- a/lib/spec/core/rake_task.rb +++ b/lib/rspec/core/rake_task.rb @@ -3,7 +3,7 @@ require 'rake' require 'rake/tasklib' -module Spec +module Rspec module Core class RakeTask < ::Rake::TaskLib diff --git a/lib/spec/core/runner.rb b/lib/rspec/core/runner.rb similarity index 79% rename from lib/spec/core/runner.rb rename to lib/rspec/core/runner.rb index 8b28bff713..5736cc30bb 100644 --- a/lib/spec/core/runner.rb +++ b/lib/rspec/core/runner.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core class Runner @@ -10,15 +10,15 @@ def self.installed_at_exit? def self.autorun return if installed_at_exit? @installed_at_exit = true - at_exit { Spec::Core::Runner.new.run(ARGV) ? exit(0) : exit(1) } + at_exit { Rspec::Core::Runner.new.run(ARGV) ? exit(0) : exit(1) } end def configuration - Spec::Core.configuration + Rspec::Core.configuration end def formatter - Spec::Core.configuration.formatter + Rspec::Core.configuration.formatter end def require_all_behaviours(files_from_args=[]) @@ -28,7 +28,7 @@ def require_all_behaviours(files_from_args=[]) def run(args = []) require_all_behaviours(args) - total_examples_to_run = Spec::Core.world.total_examples_to_run + total_examples_to_run = Rspec::Core.world.total_examples_to_run old_sync, formatter.output.sync = formatter.output.sync, true if formatter.output.respond_to?(:sync=) @@ -40,7 +40,7 @@ def run(args = []) formatter.start(total_examples_to_run) # start the clock start = Time.now - Spec::Core.world.behaviours_to_run.each do |behaviour| + Rspec::Core.world.behaviours_to_run.each do |behaviour| suite_success &= behaviour.run(formatter) end diff --git a/lib/spec/core/world.rb b/lib/rspec/core/world.rb similarity index 89% rename from lib/spec/core/world.rb rename to lib/rspec/core/world.rb index 7ad4540109..c6f514cbcb 100644 --- a/lib/spec/core/world.rb +++ b/lib/rspec/core/world.rb @@ -1,4 +1,4 @@ -module Spec +module Rspec module Core @@ -11,11 +11,11 @@ def initialize end def filter - Spec::Core.configuration.filter + Rspec::Core.configuration.filter end def exclusion_filter - Spec::Core.configuration.exclusion_filter + Rspec::Core.configuration.exclusion_filter end def behaviours_to_run @@ -24,13 +24,13 @@ def behaviours_to_run if filter || exclusion_filter @behaviours_to_run = filter_behaviours - if @behaviours_to_run.size == 0 && Spec::Core.configuration.run_all_when_everything_filtered? + if @behaviours_to_run.size == 0 && Rspec::Core.configuration.run_all_when_everything_filtered? puts "No examples were matched by #{filter.inspect}, running all" # reset the behaviour list to all behaviours, and add back all examples @behaviours_to_run = @behaviours @behaviours.each { |b| b.examples_to_run.replace(b.examples) } else - Spec::Core.configuration.output.puts "Run filtered using #{filter.inspect}" + Rspec::Core.configuration.output.puts "Run filtered using #{filter.inspect}" end else @behaviours_to_run = @behaviours diff --git a/lib/spec/core.rb b/lib/spec/core.rb deleted file mode 100644 index 2a0250be76..0000000000 --- a/lib/spec/core.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec/core/mocking/with_absolutely_nothing' -require 'spec/core/world' -require 'spec/core/configuration' -require 'spec/core/runner' -require 'spec/core/example' -require 'spec/core/behaviour' -require 'spec/core/kernel_extensions' -require 'spec/core/formatters' - -module Spec - module Core - - def self.configuration - @configuration ||= Spec::Core::Configuration.new - end - - def self.configure - yield configuration if block_given? - end - - def self.world - @world ||= Spec::Core::World.new - end - - end -end diff --git a/lib/spec/core/formatters.rb b/lib/spec/core/formatters.rb deleted file mode 100644 index ff034c07d0..0000000000 --- a/lib/spec/core/formatters.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec/core/formatters/base_formatter' -require 'spec/core/formatters/base_text_formatter' -require 'spec/core/formatters/documentation_formatter' -require 'spec/core/formatters/progress_formatter' - -module Spec - - module Core - - module Formatters - - end - - end - -end \ No newline at end of file diff --git a/script/console b/script/console index b8e248ac3e..cfab9841e3 100755 --- a/script/console +++ b/script/console @@ -3,6 +3,6 @@ require "irb" lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib") $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path) -require 'spec/core' +require 'rspec/core' IRB.start(__FILE__) diff --git a/spec/lib/spec/core/behaviour_spec.rb b/spec/lib/rspec/core/behaviour_spec.rb similarity index 72% rename from spec/lib/spec/core/behaviour_spec.rb rename to spec/lib/rspec/core/behaviour_spec.rb index ca8cca4837..845d2210a9 100644 --- a/spec/lib/spec/core/behaviour_spec.rb +++ b/spec/lib/rspec/core/behaviour_spec.rb @@ -1,33 +1,33 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe Spec::Core::Behaviour do +describe Rspec::Core::Behaviour do def empty_behaviour_group - group = Spec::Core::Behaviour.describe(Object, 'Empty Behaviour Group') { } + group = Rspec::Core::Behaviour.describe(Object, 'Empty Behaviour Group') { } remove_last_describe_from_world end describe "describing behaviour with #describe" do example "an ArgumentError is raised if no type or description is given" do - lambda { Spec::Core::Behaviour.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description") + lambda { Rspec::Core::Behaviour.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description") end example "an ArgumentError is raised if no block is given" do - lambda { Spec::Core::Behaviour.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe") + lambda { Rspec::Core::Behaviour.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe") end describe '#name' do it "should expose the first parameter as name" do isolate_behaviour do - Spec::Core::Behaviour.describe("my favorite pony") { }.name.should == 'my favorite pony' + Rspec::Core::Behaviour.describe("my favorite pony") { }.name.should == 'my favorite pony' end end it "should call to_s on the first parameter in case it is a constant" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.name.should == 'Object' + Rspec::Core::Behaviour.describe(Object) { }.name.should == 'Object' end end @@ -35,14 +35,14 @@ def empty_behaviour_group behaviour_to_test = nil isolate_behaviour do - Spec::Core::Behaviour.describe(Spec::Core, "test") do - Spec::Core::Behaviour.describe("nested one") do - behaviour_to_test = Spec::Core::Behaviour.describe("nested two") { } + Rspec::Core::Behaviour.describe(Rspec::Core, "test") do + Rspec::Core::Behaviour.describe("nested one") do + behaviour_to_test = Rspec::Core::Behaviour.describe("nested two") { } end end end - behaviour_to_test.name.should == 'Spec::Core - test - nested one - nested two' + behaviour_to_test.name.should == 'Rspec::Core - test - nested one - nested two' end end @@ -51,13 +51,13 @@ def empty_behaviour_group it "should be the first parameter when it is a constant" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.describes.should == Object + Rspec::Core::Behaviour.describe(Object) { }.describes.should == Object end end it "should be nil when the first parameter is a string" do isolate_behaviour do - Spec::Core::Behaviour.describe("i'm a computer") { }.describes.should be_nil + Rspec::Core::Behaviour.describe("i'm a computer") { }.describes.should be_nil end end @@ -67,13 +67,13 @@ def empty_behaviour_group it "should expose the second parameter as description" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc' + Rspec::Core::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc' end end it "should allow the second parameter to be nil" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object, nil) { }.description.size.should == 0 + Rspec::Core::Behaviour.describe(Object, nil) { }.description.size.should == 0 end end @@ -83,39 +83,39 @@ def empty_behaviour_group it "should add the third parameter to the metadata" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' }) + Rspec::Core::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' }) end end it "should add the caller to metadata" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/ + Rspec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/ end end it "should add the the file_path to metadata" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__ + Rspec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__ end end it "should have a reader for file_path" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.file_path.should == __FILE__ + Rspec::Core::Behaviour.describe(Object) { }.file_path.should == __FILE__ end end it "should add the line_number to metadata" do isolate_behaviour do - Spec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__ + Rspec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__ end end it "should add file path and line number metadata for arbitrarily nested describes" do - Spec::Core::Behaviour.describe(Object) do - Spec::Core::Behaviour.describe("foo") do - Spec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__ - Spec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__ + Rspec::Core::Behaviour.describe(Object) do + Rspec::Core::Behaviour.describe("foo") do + Rspec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__ + Rspec::Core::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__ end end @@ -253,7 +253,7 @@ def empty_behaviour_group describe "#run_examples" do before do - @fake_formatter = Spec::Core::Formatters::BaseFormatter.new + @fake_formatter = Rspec::Core::Formatters::BaseFormatter.new end def stub_behaviour @@ -262,33 +262,33 @@ def stub_behaviour it "should return true if all examples pass" do use_formatter(@fake_formatter) do - passing_example1 = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) - passing_example2 = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) - Spec::Core::Behaviour.stubs(:examples_to_run).returns([passing_example1, passing_example2]) + passing_example1 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) + passing_example2 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) + Rspec::Core::Behaviour.stubs(:examples_to_run).returns([passing_example1, passing_example2]) - Spec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_true + Rspec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_true end end it "should return false if any of the examples return false" do use_formatter(@fake_formatter) do - failing_example = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 })) - passing_example = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) - Spec::Core::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example]) + failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 })) + passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) + Rspec::Core::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example]) - Spec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_false + Rspec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_false end end it "should run all examples, regardless of any of them failing" do use_formatter(@fake_formatter) do - failing_example = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 })) - passing_example = Spec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) - Spec::Core::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example]) + failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 })) + passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 })) + Rspec::Core::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example]) passing_example.expects(:run) - Spec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')) + Rspec::Core::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')) end end diff --git a/spec/lib/spec/core/configuration_spec.rb b/spec/lib/rspec/core/configuration_spec.rb similarity index 64% rename from spec/lib/spec/core/configuration_spec.rb rename to spec/lib/rspec/core/configuration_spec.rb index 0c75bd711f..2b40757501 100644 --- a/spec/lib/spec/core/configuration_spec.rb +++ b/spec/lib/rspec/core/configuration_spec.rb @@ -1,25 +1,25 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe Spec::Core::Configuration do +describe Rspec::Core::Configuration do describe "#mock_with" do it "should require and include the mocha adapter when called with :mocha" do - Spec::Core.configuration.expects(:require).with('spec/core/mocking/with_mocha') - Spec::Core::Behaviour.expects(:send) - Spec::Core.configuration.mock_with :mocha + Rspec::Core.configuration.expects(:require).with('rspec/core/mocking/with_mocha') + Rspec::Core::Behaviour.expects(:send) + Rspec::Core.configuration.mock_with :mocha end it "should include the null adapter for nil" do - Spec::Core::Behaviour.expects(:send).with(:include, Spec::Core::Mocking::WithAbsolutelyNothing) - Spec::Core.configuration.mock_with nil + Rspec::Core::Behaviour.expects(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing) + Rspec::Core.configuration.mock_with nil end # if the below example doesn't pass, @behaviour_instance._setup_mocks and similiar calls fail without a mock library specified # this is really a case where cucumber would be a better fit to catch these type of regressions it "should include the null adapter by default, if no mocking library is specified" do - Spec::Core::Behaviour.expects(:send).with(:include, Spec::Core::Mocking::WithAbsolutelyNothing) - config = Spec::Core::Configuration.new + Rspec::Core::Behaviour.expects(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing) + config = Rspec::Core::Configuration.new end end @@ -33,8 +33,8 @@ def you_call_this_a_blt? end it "should include the given module into each matching behaviour" do - Spec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include) - group = Spec::Core::Behaviour.describe(Object, 'does like, stuff and junk', :magic_key => :include) { } + Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include) + group = Rspec::Core::Behaviour.describe(Object, 'does like, stuff and junk', :magic_key => :include) { } group.should_not respond_to(:you_call_this_a_blt?) remove_last_describe_from_world @@ -53,8 +53,8 @@ def that_thing end it "should extend the given module into each matching behaviour" do - Spec::Core.configuration.extend(ThatThingISentYou, :magic_key => :extend) - group = Spec::Core::Behaviour.describe(ThatThingISentYou, :magic_key => :extend) { } + Rspec::Core.configuration.extend(ThatThingISentYou, :magic_key => :extend) + group = Rspec::Core::Behaviour.describe(ThatThingISentYou, :magic_key => :extend) { } group.should respond_to(:that_thing) remove_last_describe_from_world @@ -65,11 +65,11 @@ def that_thing describe "#run_all_when_everything_filtered" do it "defaults to true" do - Spec::Core::Configuration.new.run_all_when_everything_filtered.should == true + Rspec::Core::Configuration.new.run_all_when_everything_filtered.should == true end it "can be queried with question method" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.run_all_when_everything_filtered = false config.run_all_when_everything_filtered?.should == false end @@ -78,11 +78,11 @@ def that_thing describe '#trace?' do it "is false by default" do - Spec::Core::Configuration.new.trace?.should == false + Rspec::Core::Configuration.new.trace?.should == false end it "is true if configuration.trace is true" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.trace = true config.trace?.should == true end @@ -92,20 +92,20 @@ def that_thing describe '#trace' do it "requires a block" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.trace = true lambda { config.trace(true) }.should raise_error(ArgumentError) end it "does nothing if trace is false" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.trace = false config.expects(:puts).with("my trace string is awesome").never config.trace { "my trace string is awesome" } end it "allows overriding tracing an optional param" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.trace = false config.expects(:puts).with(includes("my trace string is awesome")) config.trace(true) { "my trace string is awesome" } @@ -116,15 +116,15 @@ def that_thing describe '#formatter' do it "sets formatter_to_use based on name" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new config.formatter = :documentation - config.instance_eval { @formatter_to_use.should == Spec::Core::Formatters::DocumentationFormatter } + config.instance_eval { @formatter_to_use.should == Rspec::Core::Formatters::DocumentationFormatter } config.formatter = 'documentation' - config.instance_eval { @formatter_to_use.should == Spec::Core::Formatters::DocumentationFormatter } + config.instance_eval { @formatter_to_use.should == Rspec::Core::Formatters::DocumentationFormatter } end it "raises ArgumentError if formatter is unknown" do - config = Spec::Core::Configuration.new + config = Rspec::Core::Configuration.new lambda { config.formatter = :progresss }.should raise_error(ArgumentError) end diff --git a/spec/lib/spec/core/example_spec.rb b/spec/lib/rspec/core/example_spec.rb similarity index 91% rename from spec/lib/spec/core/example_spec.rb rename to spec/lib/rspec/core/example_spec.rb index ca40777487..f58dd99508 100644 --- a/spec/lib/spec/core/example_spec.rb +++ b/spec/lib/rspec/core/example_spec.rb @@ -1,10 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe Spec::Core::Example, :parent_metadata => 'sample' do +describe Rspec::Core::Example, :parent_metadata => 'sample' do before do behaviour = stub('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }}) - @example = Spec::Core::Example.new(behaviour, 'description', {}, (lambda {})) + @example = Rspec::Core::Example.new(behaviour, 'description', {}, (lambda {})) end describe "attr readers" do diff --git a/spec/lib/spec/core/formatters/base_formatter_spec.rb b/spec/lib/rspec/core/formatters/base_formatter_spec.rb similarity index 96% rename from spec/lib/spec/core/formatters/base_formatter_spec.rb rename to spec/lib/rspec/core/formatters/base_formatter_spec.rb index 12e262b787..d1acb9e8d2 100644 --- a/spec/lib/spec/core/formatters/base_formatter_spec.rb +++ b/spec/lib/rspec/core/formatters/base_formatter_spec.rb @@ -1,9 +1,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper") -describe Spec::Core::Formatters::BaseFormatter do +describe Rspec::Core::Formatters::BaseFormatter do before do - @formatter = Spec::Core::Formatters::BaseFormatter.new + @formatter = Rspec::Core::Formatters::BaseFormatter.new end class HaveInterfaceMatcher diff --git a/spec/lib/spec/core/formatters/documentation_formatter_spec.rb b/spec/lib/rspec/core/formatters/documentation_formatter_spec.rb similarity index 56% rename from spec/lib/spec/core/formatters/documentation_formatter_spec.rb rename to spec/lib/rspec/core/formatters/documentation_formatter_spec.rb index 338051da4c..5c33ad4f37 100644 --- a/spec/lib/spec/core/formatters/documentation_formatter_spec.rb +++ b/spec/lib/rspec/core/formatters/documentation_formatter_spec.rb @@ -1,5 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper") -describe Spec::Core::Formatters::DocumentationFormatter do +describe Rspec::Core::Formatters::DocumentationFormatter do end \ No newline at end of file diff --git a/spec/lib/spec/core/formatters/progress_formatter_spec.rb b/spec/lib/rspec/core/formatters/progress_formatter_spec.rb similarity index 85% rename from spec/lib/spec/core/formatters/progress_formatter_spec.rb rename to spec/lib/rspec/core/formatters/progress_formatter_spec.rb index 3d1c1fd0b9..8a9ba15ce8 100644 --- a/spec/lib/spec/core/formatters/progress_formatter_spec.rb +++ b/spec/lib/rspec/core/formatters/progress_formatter_spec.rb @@ -1,10 +1,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../../spec_helper") -describe Spec::Core::Formatters::ProgressFormatter do +describe Rspec::Core::Formatters::ProgressFormatter do before do @output = StringIO.new - @formatter = Spec::Core::Formatters::ProgressFormatter.new + @formatter = Rspec::Core::Formatters::ProgressFormatter.new @formatter.start(2) @formatter.stubs(:color_enabled?).returns(false) @formatter.stubs(:output).returns(@output) diff --git a/spec/lib/spec/core/kernel_extensions_spec.rb b/spec/lib/rspec/core/kernel_extensions_spec.rb similarity index 66% rename from spec/lib/spec/core/kernel_extensions_spec.rb rename to spec/lib/rspec/core/kernel_extensions_spec.rb index b102f066c3..289e87f9e7 100644 --- a/spec/lib/spec/core/kernel_extensions_spec.rb +++ b/spec/lib/rspec/core/kernel_extensions_spec.rb @@ -1,9 +1,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") -describe Spec::Core::KernelExtensions do +describe Rspec::Core::KernelExtensions do it "should be included in Object" do - Object.included_modules.should include(Spec::Core::KernelExtensions) + Object.included_modules.should include(Rspec::Core::KernelExtensions) end it "should add a describe method to Object" do diff --git a/spec/lib/spec/core/mocha_spec.rb b/spec/lib/rspec/core/mocha_spec.rb similarity index 80% rename from spec/lib/spec/core/mocha_spec.rb rename to spec/lib/rspec/core/mocha_spec.rb index 881eaa197f..8be96f1e9c 100644 --- a/spec/lib/spec/core/mocha_spec.rb +++ b/spec/lib/rspec/core/mocha_spec.rb @@ -5,13 +5,13 @@ it "should not double report mocha errors" do # The below example should have one error, not two # I'm also not sure how to test this regression without having the failure counting by - # the running Spec::Core instance - formatter = Spec::Core::Formatters::BaseFormatter.new + # the running Rspec::Core instance + formatter = Rspec::Core::Formatters::BaseFormatter.new use_formatter(formatter) do isolate_behaviour do - desc = Spec::Core::Behaviour.describe("my favorite pony") do + desc = Rspec::Core::Behaviour.describe("my favorite pony") do example("showing a double fail") do foo = "string" foo.expects(:something) diff --git a/spec/lib/rspec/core/runner_spec.rb b/spec/lib/rspec/core/runner_spec.rb new file mode 100644 index 0000000000..08b22a62fd --- /dev/null +++ b/spec/lib/rspec/core/runner_spec.rb @@ -0,0 +1,41 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") + +describe Rspec::Core::Runner do + + before do + @runner = Rspec::Core::Runner.new + end + + describe '#configuration' do + + it "should return Rspec::Core.configuration" do + @runner.configuration.should == Rspec::Core.configuration + end + + end + + describe '#formatter' do + + it 'should return the configured formatter' do + @runner.formatter.should == Rspec::Core.configuration.formatter + end + + end + + describe 'Rspec::Core::Runner.at_exit' do + + it 'should set an at_exit hook if none is already set' do + Rspec::Core::Runner.stubs(:installed_at_exit?).returns(false) + Rspec::Core::Runner.expects(:at_exit) + Rspec::Core::Runner.autorun + end + + it 'should not set the at_exit hook if it is already set' do + Rspec::Core::Runner.stubs(:installed_at_exit?).returns(true) + Rspec::Core::Runner.expects(:at_exit).never + Rspec::Core::Runner.autorun + end + + end + +end \ No newline at end of file diff --git a/spec/lib/spec/core/world_spec.rb b/spec/lib/rspec/core/world_spec.rb similarity index 80% rename from spec/lib/spec/core/world_spec.rb rename to spec/lib/rspec/core/world_spec.rb index a1ac4c0bde..8ee0824f71 100644 --- a/spec/lib/spec/core/world_spec.rb +++ b/spec/lib/rspec/core/world_spec.rb @@ -3,17 +3,17 @@ class Bar; end class Foo; end -describe Spec::Core::World do +describe Rspec::Core::World do before do - @world = Spec::Core::World.new - Spec::Core.stubs(:world).returns(@world) + @world = Rspec::Core::World.new + Rspec::Core.stubs(:world).returns(@world) end describe "behaviour groups" do it "should contain all defined behaviour groups" do - behaviour_group = Spec::Core::Behaviour.describe(Bar, 'Empty Behaviour Group') { } + behaviour_group = Rspec::Core::Behaviour.describe(Bar, 'Empty Behaviour Group') { } @world.behaviours.should include(behaviour_group) end @@ -25,10 +25,10 @@ class Foo; end options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' } options_2 = { :pending => true, :feature => 'reporting' } options_3 = { :array => [1,2,3,4], :color => 'blue', :feature => 'weather status' } - @bg1 = Spec::Core::Behaviour.describe(Bar, "find group-1", options_1) { } - @bg2 = Spec::Core::Behaviour.describe(Bar, "find group-2", options_2) { } - @bg3 = Spec::Core::Behaviour.describe(Bar, "find group-3", options_3) { } - @bg4 = Spec::Core::Behaviour.describe(Foo, "find these examples") do + @bg1 = Rspec::Core::Behaviour.describe(Bar, "find group-1", options_1) { } + @bg2 = Rspec::Core::Behaviour.describe(Bar, "find group-2", options_2) { } + @bg3 = Rspec::Core::Behaviour.describe(Bar, "find group-3", options_3) { } + @bg4 = Rspec::Core::Behaviour.describe(Foo, "find these examples") do it('I have no options') {} it("this is awesome", :awesome => true) {} it("this is too", :awesome => true) {} @@ -39,10 +39,10 @@ class Foo; end end after(:all) do - Spec::Core.world.behaviours.delete(@bg1) - Spec::Core.world.behaviours.delete(@bg2) - Spec::Core.world.behaviours.delete(@bg3) - Spec::Core.world.behaviours.delete(@bg4) + Rspec::Core.world.behaviours.delete(@bg1) + Rspec::Core.world.behaviours.delete(@bg2) + Rspec::Core.world.behaviours.delete(@bg3) + Rspec::Core.world.behaviours.delete(@bg4) end it "should find awesome examples" do @@ -101,7 +101,7 @@ class Foo; end options = { :network_access => true } isolate_behaviour do - group1 = Spec::Core::Behaviour.describe(Bar, "find group-1", options) do + group1 = Rspec::Core::Behaviour.describe(Bar, "find group-1", options) do it("foo") {} it("bar") {} end @@ -110,7 +110,7 @@ class Foo; end end isolate_behaviour do - group2 = Spec::Core::Behaviour.describe(Bar, "find group-1") do + group2 = Rspec::Core::Behaviour.describe(Bar, "find group-1") do it("foo", :network_access => true) {} it("bar") {} end @@ -122,7 +122,7 @@ class Foo; end it "should find nothing if a regexp matches the exclusion filter" do isolate_behaviour do - group = Spec::Core::Behaviour.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do + group = Rspec::Core::Behaviour.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do it("foo") {} it("bar") {} end @@ -142,7 +142,7 @@ class Foo; end describe "filtering behaviours" do before(:all) do - @group1 = Spec::Core::Behaviour.describe(Bar, "find these examples") do + @group1 = Rspec::Core::Behaviour.describe(Bar, "find these examples") do it('I have no options', :color => :red, :awesome => true) {} it("I also have no options", :color => :red, :awesome => true) {} it("not so awesome", :color => :red, :awesome => false) {} @@ -150,13 +150,13 @@ class Foo; end end after(:all) do - Spec::Core.world.behaviours.delete(@group1) + Rspec::Core.world.behaviours.delete(@group1) end it "should run matches" do - Spec::Core.world.stubs(:exclusion_filter).returns({ :awesome => false }) - Spec::Core.world.stubs(:filter).returns({ :color => :red }) - Spec::Core.world.stubs(:behaviours).returns([@group1]) + Rspec::Core.world.stubs(:exclusion_filter).returns({ :awesome => false }) + Rspec::Core.world.stubs(:filter).returns({ :color => :red }) + Rspec::Core.world.stubs(:behaviours).returns([@group1]) filtered_behaviours = @world.filter_behaviours filtered_behaviours.should == [@group1] @group1.examples_to_run.should == @group1.examples[0..1] diff --git a/spec/lib/rspec/core_spec.rb b/spec/lib/rspec/core_spec.rb new file mode 100644 index 0000000000..530e4b47f6 --- /dev/null +++ b/spec/lib/rspec/core_spec.rb @@ -0,0 +1,35 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") + +describe Rspec::Core do + + describe "#configuration" do + + it "should return an instance of Rspec::Core::Configuration" do + Rspec::Core.configuration.should be_an_instance_of(Rspec::Core::Configuration) + end + + end + + describe "#configure" do + + it "should yield the current configuration" do + Rspec::Core.configure do |config| + config.should == Rspec::Core.configuration + end + end + + it "should be callable without a block" do + Rspec::Core.configure + end + + end + + describe "#world" do + + it "should return the Rspec::Core::World instance the current run is using" do + Rspec::Core.world.should be_instance_of(Rspec::Core::World) + end + + end + +end diff --git a/spec/lib/spec/core/runner_spec.rb b/spec/lib/spec/core/runner_spec.rb deleted file mode 100644 index cbee3458b4..0000000000 --- a/spec/lib/spec/core/runner_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper") - -describe Spec::Core::Runner do - - before do - @runner = Spec::Core::Runner.new - end - - describe '#configuration' do - - it "should return Spec::Core.configuration" do - @runner.configuration.should == Spec::Core.configuration - end - - end - - describe '#formatter' do - - it 'should return the configured formatter' do - @runner.formatter.should == Spec::Core.configuration.formatter - end - - end - - describe 'Spec::Core::Runner.at_exit' do - - it 'should set an at_exit hook if none is already set' do - Spec::Core::Runner.stubs(:installed_at_exit?).returns(false) - Spec::Core::Runner.expects(:at_exit) - Spec::Core::Runner.autorun - end - - it 'should not set the at_exit hook if it is already set' do - Spec::Core::Runner.stubs(:installed_at_exit?).returns(true) - Spec::Core::Runner.expects(:at_exit).never - Spec::Core::Runner.autorun - end - - end - -end \ No newline at end of file diff --git a/spec/lib/spec/core_spec.rb b/spec/lib/spec/core_spec.rb deleted file mode 100644 index af93d91fb8..0000000000 --- a/spec/lib/spec/core_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") - -describe Spec::Core do - - describe "#configuration" do - - it "should return an instance of Spec::Core::Configuration" do - Spec::Core.configuration.should be_an_instance_of(Spec::Core::Configuration) - end - - end - - describe "#configure" do - - it "should yield the current configuration" do - Spec::Core.configure do |config| - config.should == Spec::Core.configuration - end - end - - it "should be callable without a block" do - Spec::Core.configure - end - - end - - describe "#world" do - - it "should return the Spec::Core::World instance the current run is using" do - Spec::Core.world.should be_instance_of(Spec::Core::World) - end - - end - -end diff --git a/spec/resources/example_classes.rb b/spec/resources/example_classes.rb index 250e9a0aad..a63548e41d 100644 --- a/spec/resources/example_classes.rb +++ b/spec/resources/example_classes.rb @@ -1,5 +1,5 @@ # This file contains various classes used by the specs. -module Spec::Core +module Rspec::Core module Expectations class Person attr_reader :name diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6b13b359c9..56f620d6ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,9 +5,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../mocks/lib')) require 'spec/mocks' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require 'spec/core' +require 'rspec/core' -Spec::Core::Behaviour.send(:include, Spec::Matchers) +Rspec::Core::Behaviour.send(:include, Spec::Matchers) def with_ruby(version) yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}") @@ -18,7 +18,7 @@ def with_ruby(version) require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes") -module Spec +module Rspec module Core module Matchers def fail @@ -33,29 +33,29 @@ def fail_with(message) end def remove_last_describe_from_world - Spec::Core.world.behaviours.pop + Rspec::Core.world.behaviours.pop end def isolate_behaviour if block_given? yield - Spec::Core.world.behaviours.pop + Rspec::Core.world.behaviours.pop end end def use_formatter(new_formatter) - original_formatter = Spec::Core.configuration.formatter - Spec::Core.configuration.instance_variable_set(:@formatter, new_formatter) + original_formatter = Rspec::Core.configuration.formatter + Rspec::Core.configuration.instance_variable_set(:@formatter, new_formatter) yield ensure - Spec::Core.configuration.instance_variable_set(:@formatter, original_formatter) + Rspec::Core.configuration.instance_variable_set(:@formatter, original_formatter) end def not_in_editor? !(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')) end -Spec::Core.configure do |c| +Rspec::Core.configure do |c| c.mock_with :mocha c.color_enabled = not_in_editor? c.filter_run :focused => true