Skip to content

Commit

Permalink
Spec->Rspec. Refactoring complete
Browse files Browse the repository at this point in the history
  • Loading branch information
spicycode committed Jun 29, 2009
1 parent 6785d2b commit 4c37c38
Show file tree
Hide file tree
Showing 37 changed files with 289 additions and 289 deletions.
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -16,13 +16,13 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end end


require 'lib/spec/core/rake_task' require 'lib/rspec/core/rake_task'
Spec::Core::RakeTask.new :spec do |t| Rspec::Core::RakeTask.new :spec do |t|
t.pattern = "spec/**/*_spec.rb" t.pattern = "spec/**/*_spec.rb"
end end


desc "Run all examples using rcov" 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.pattern = "spec/**/*_spec.rb"
t.rcov = true 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] t.rcov_opts = %[--exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
Expand Down
4 changes: 2 additions & 2 deletions bin/rspec
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
require 'spec/core' require 'rspec/core'
Spec::Core.configuration.autorun! Rspec::Core.configuration.autorun!
26 changes: 26 additions & 0 deletions 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
28 changes: 14 additions & 14 deletions lib/spec/core/behaviour.rb → lib/rspec/core/behaviour.rb
@@ -1,13 +1,13 @@
module Spec module Rspec
module Core module Core
class Behaviour class Behaviour


attr_accessor :running_example, :reporter attr_accessor :running_example, :reporter


def self.inherited(klass) def self.inherited(klass)
super super
Spec::Core.configuration.autorun! Rspec::Core.configuration.autorun!
Spec::Core.world.behaviours << klass Rspec::Core.world.behaviours << klass
end end


def self.extended_modules #:nodoc: def self.extended_modules #:nodoc:
Expand Down Expand Up @@ -48,7 +48,7 @@ def self.after(type=:each, &block)
end end


def self.example(desc=nil, options={}, &block) 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 end


def self.alias_example_to(new_alias, extra_options={}) def self.alias_example_to(new_alias, extra_options={})
Expand All @@ -57,7 +57,7 @@ def self.#{new_alias}(desc=nil, options={}, &block)
updated_options = options.update(:caller => caller[0]) updated_options = options.update(:caller => caller[0])
updated_options.update(#{extra_options.inspect}) updated_options.update(#{extra_options.inspect})
block = nil if updated_options[:pending] == true || updated_options[:disabled] == true 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
END_RUBY END_RUBY
module_eval(new_alias, __FILE__, __LINE__) module_eval(new_alias, __FILE__, __LINE__)
Expand Down Expand Up @@ -94,12 +94,12 @@ def self.set_it_up(*args)


@metadata.update(extra_metadata) @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 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) send(:extend, mod) unless extended_modules.include?(mod)
else 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) send(:include, mod) unless included_modules.include?(mod)
end end
end end
Expand Down Expand Up @@ -141,7 +141,7 @@ def self.ancestors(superclass_last=false)
classes = [] classes = []
current_class = self current_class = self


while current_class < Spec::Core::Behaviour while current_class < Rspec::Core::Behaviour
superclass_last ? classes << current_class : classes.unshift(current_class) superclass_last ? classes << current_class : classes.unshift(current_class)
current_class = current_class.superclass current_class = current_class.superclass
end end
Expand All @@ -163,26 +163,26 @@ def self.before_all_ivars


def self.eval_before_alls(running_behaviour) def self.eval_before_alls(running_behaviour)
superclass.before_all_ivars.each { |ivar, val| running_behaviour.instance_variable_set(ivar, val) } 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) } 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) } running_behaviour.instance_variables.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
end end


def self.eval_before_eachs(running_behaviour) 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) } } before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_behaviour.instance_eval(&blk) } }
end end


def self.eval_after_alls(running_behaviour) def self.eval_after_alls(running_behaviour)
after_alls.each { |blk| running_behaviour.instance_eval(&blk) } 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) } before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
end end


def self.eval_after_eachs(running_behaviour) def self.eval_after_eachs(running_behaviour)
after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_behaviour.instance_eval(&blk) } } 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 end


def self.run(reporter) def self.run(reporter)
Expand Down Expand Up @@ -211,7 +211,7 @@ def self.subclass(base_name, &body) # :nodoc:
end end


def self.to_s def self.to_s
self == Spec::Core::Behaviour ? 'Spec::Core::Behaviour' : name self == Rspec::Core::Behaviour ? 'Rspec::Core::Behaviour' : name
end end


end end
Expand Down
36 changes: 18 additions & 18 deletions lib/spec/core/configuration.rb → lib/rspec/core/configuration.rb
@@ -1,4 +1,4 @@
module Spec module Rspec
module Core module Core
class Configuration class Configuration
# Regex patterns to scrub backtrace with # Regex patterns to scrub backtrace with
Expand Down Expand Up @@ -35,15 +35,15 @@ def initialize
@color_enabled = false @color_enabled = false
@before_and_afters = { :before => { :each => [], :all => [] }, :after => { :each => [], :all => [] } } @before_and_afters = { :before => { :each => [], :all => [] }, :after => { :each => [], :all => [] } }
@include_or_extend_modules = [] @include_or_extend_modules = []
@formatter_to_use = Spec::Core::Formatters::ProgressFormatter @formatter_to_use = Rspec::Core::Formatters::ProgressFormatter
@filter, @exclusion_filter = nil, nil @filter, @exclusion_filter = nil, nil
mock_with nil unless @mock_framework_established mock_with nil unless @mock_framework_established
end end


# E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines # E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines
# crazy_slow as an example variant that has the crazy_slow speed option # crazy_slow as an example variant that has the crazy_slow speed option
def alias_example_to(new_name, extra_options={}) 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 end


def cleaned_from_backtrace?(line) def cleaned_from_backtrace?(line)
Expand All @@ -55,24 +55,24 @@ def mock_with(make_a_mockery_with=nil)
@mock_framework = make_a_mockery_with @mock_framework = make_a_mockery_with
mock_framework_class = case make_a_mockery_with.to_s mock_framework_class = case make_a_mockery_with.to_s
when /mocha/i when /mocha/i
require 'spec/core/mocking/with_mocha' require 'rspec/core/mocking/with_mocha'
Spec::Core::Mocking::WithMocha Rspec::Core::Mocking::WithMocha
when /rr/i when /rr/i
require 'spec/core/mocking/with_rr' require 'rspec/core/mocking/with_rr'
Spec::Core::Mocking::WithRR Rspec::Core::Mocking::WithRR
when /rspec/i when /rspec/i
require 'spec/core/mocking/with_rspec' require 'rspec/core/mocking/with_rspec'
Spec::Core::Mocking::WithRspec Rspec::Core::Mocking::WithRspec
else else
require 'spec/core/mocking/with_absolutely_nothing' require 'rspec/core/mocking/with_absolutely_nothing'
Spec::Core::Mocking::WithAbsolutelyNothing Rspec::Core::Mocking::WithAbsolutelyNothing
end end


Spec::Core::Behaviour.send(:include, mock_framework_class) Rspec::Core::Behaviour.send(:include, mock_framework_class)
end end


def autorun! def autorun!
Spec::Core::Runner.autorun Rspec::Core::Runner.autorun
end end


# Turn ANSI on with 'true', or off with 'false' # Turn ANSI on with 'true', or off with 'false'
Expand All @@ -95,8 +95,8 @@ def run_all_when_everything_filtered?


def formatter=(formatter_to_use) def formatter=(formatter_to_use)
@formatter_to_use = case formatter_to_use.to_s @formatter_to_use = case formatter_to_use.to_s
when 'documentation' then Spec::Core::Formatters::DocumentationFormatter when 'documentation' then Rspec::Core::Formatters::DocumentationFormatter
when 'progress' then Spec::Core::Formatters::ProgressFormatter when 'progress' then Rspec::Core::Formatters::ProgressFormatter
else raise(ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.") else raise(ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
end end
end end
Expand Down Expand Up @@ -124,7 +124,7 @@ def puts(msg)
output.puts(msg) output.puts(msg)
end 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. # Can be turned on at the global (configuration) level or at the individual behaviour (describe) level.
def trace? def trace?
@trace == true @trace == true
Expand All @@ -141,7 +141,7 @@ def extend(mod, options={})
def find_modules(group) def find_modules(group)
include_or_extend_modules.select do |include_or_extend, mod, options| include_or_extend_modules.select do |include_or_extend, mod, options|
options.all? do |filter_on, filter| 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 end
end end
Expand All @@ -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) 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| before_and_afters[desired_before_or_after][desired_each_or_all].select do |options, block|
options.all? do |filter_on, filter| 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.map { |options, block| block } end.map { |options, block| block }
end end
Expand Down
4 changes: 2 additions & 2 deletions lib/spec/core/example.rb → lib/rspec/core/example.rb
@@ -1,4 +1,4 @@
module Spec module Rspec
module Core module Core
class Example class Example


Expand Down Expand Up @@ -49,7 +49,7 @@ def run_finished(status, results={})
record_results results.update(:status => status) record_results results.update(:status => status)
finish_time = Time.now finish_time = Time.now
record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at]) 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 end


def run_before_each def run_before_each
Expand Down
16 changes: 16 additions & 0 deletions 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
@@ -1,4 +1,4 @@
module Spec module Rspec


module Core module Core


Expand All @@ -15,15 +15,15 @@ def initialize
end end


def configuration def configuration
Spec::Core.configuration Rspec::Core.configuration
end end


def output def output
Spec::Core.configuration.output Rspec::Core.configuration.output
end end


def trace(&blk) def trace(&blk)
Spec::Core.configuration.trace(trace_override_flag, &blk) Rspec::Core.configuration.trace(trace_override_flag, &blk)
end end


# Allow setting trace at the behaviour level as well globally # Allow setting trace at the behaviour level as well globally
Expand All @@ -32,19 +32,19 @@ def trace_override_flag
end end


def profile_examples? def profile_examples?
Spec::Core.configuration.profile_examples Rspec::Core.configuration.profile_examples
end end


def color_enabled? def color_enabled?
configuration.color_enabled? configuration.color_enabled?
end end


def pending_examples 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 end


def failed_examples 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 end


# This method is invoked before any examples are run, right after # This method is invoked before any examples are run, right after
Expand Down
@@ -1,4 +1,4 @@
module Spec module Rspec


module Core module Core


Expand Down
@@ -1,4 +1,4 @@
module Spec module Rspec


module Core module Core


Expand Down
@@ -1,4 +1,4 @@
module Spec module Rspec


module Core module Core


Expand Down
@@ -1,9 +1,9 @@
module Spec module Rspec
module Core module Core
module KernelExtensions module KernelExtensions


def describe(*args, &behaviour_block) def describe(*args, &behaviour_block)
Spec::Core::Behaviour.describe(*args, &behaviour_block) Rspec::Core::Behaviour.describe(*args, &behaviour_block)
end end


alias :context :describe alias :context :describe
Expand All @@ -12,4 +12,4 @@ def describe(*args, &behaviour_block)
end end
end end


include Spec::Core::KernelExtensions include Rspec::Core::KernelExtensions
@@ -1,4 +1,4 @@
module Spec module Rspec
module Core module Core
module Mocking module Mocking
module WithAbsolutelyNothing module WithAbsolutelyNothing
Expand Down
@@ -1,7 +1,7 @@
require 'mocha/standalone' require 'mocha/standalone'
require 'mocha/object' require 'mocha/object'


module Spec module Rspec
module Core module Core
module Mocking module Mocking
module WithMocha module WithMocha
Expand Down
@@ -1,8 +1,8 @@
require 'rr' 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 Core
module Mocking module Mocking
module WithRR module WithRR
Expand Down

0 comments on commit 4c37c38

Please sign in to comment.