Skip to content

Commit

Permalink
move world from Rspec::Core to Rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 10, 2010
1 parent 5d95ab9 commit b028806
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 29 deletions.
7 changes: 6 additions & 1 deletion lib/rspec/core.rb
Expand Up @@ -40,11 +40,16 @@ def self.configure
end

def self.world
@world ||= Rspec::Core::World.new
Rspec.deprecate('Rspec::Core.world', 'Rspec.world', '2.0.0')
Rspec.world
end

end

def self.world
@world ||= Rspec::Core::World.new
end

def self.configuration
@configuration ||= Rspec::Core::Configuration.new
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/example_group.rb
Expand Up @@ -10,7 +10,7 @@ class ExampleGroup

def self.inherited(klass)
Rspec::Core::Runner.autorun
Rspec::Core.world.example_groups << klass if klass.superclass == ExampleGroup
Rspec.world.example_groups << klass if klass.superclass == ExampleGroup
end

class << self
Expand Down Expand Up @@ -56,7 +56,7 @@ class << self
def self.it_should_behave_like(*names)
names.each do |name|
begin
module_eval &Rspec::Core.world.shared_example_groups[name]
module_eval &Rspec.world.shared_example_groups[name]
rescue ArgumentError
raise "Could not find shared example group named #{name.inspect}"
end
Expand All @@ -75,7 +75,7 @@ def self.filtered_examples(fresh = false)
end

def self.world
Rspec::Core.world
Rspec.world
end

def self.superclass_metadata
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/core/formatters/base_formatter.rb
Expand Up @@ -18,11 +18,11 @@ def output
end

def pending_examples
@pending_examples ||= ::Rspec::Core.world.find(examples, :execution_result => { :status => 'pending' })
@pending_examples ||= ::Rspec.world.find(examples, :execution_result => { :status => 'pending' })
end

def failed_examples
@failed_examples ||= ::Rspec::Core.world.find(examples, :execution_result => { :status => 'failed' })
@failed_examples ||= ::Rspec.world.find(examples, :execution_result => { :status => 'failed' })
end

def report(count)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/metadata.rb
Expand Up @@ -119,7 +119,7 @@ def apply_condition(filter_on, filter, metadata=nil)
private

def world
Rspec::Core.world
Rspec.world
end

def superclass_metadata
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/runner.rb
Expand Up @@ -39,7 +39,7 @@ def run(args = [])

def announce_inclusion_filter
if inclusion_filter
if Rspec.configuration.run_all_when_everything_filtered? && Rspec::Core.world.example_count == 0
if Rspec.configuration.run_all_when_everything_filtered? && Rspec.world.example_count == 0
Rspec.configuration.puts "No examples were matched by #{inclusion_filter.inspect}, running all"
Rspec.configuration.clear_inclusion_filter
else
Expand All @@ -55,11 +55,11 @@ def configure(args)
end

def example_count
Rspec::Core.world.example_count
Rspec.world.example_count
end

def example_groups
Rspec::Core.world.example_groups.extend(ExampleGroups)
Rspec.world.example_groups.extend(ExampleGroups)
end

module ExampleGroups
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/core/shared_example_group.rb
Expand Up @@ -4,7 +4,7 @@ module SharedExampleGroup

def share_examples_for(name, &block)
ensure_shared_example_group_name_not_taken(name)
Rspec::Core.world.shared_example_groups[name] = block
Rspec.world.shared_example_groups[name] = block
end

def share_as(name, &block)
Expand All @@ -27,7 +27,7 @@ def self.included(kls)
end

shared_const = Object.const_set(name, mod)
Rspec::Core.world.shared_example_groups[shared_const] = block
Rspec.world.shared_example_groups[shared_const] = block
end

alias :shared_examples_for :share_examples_for
Expand All @@ -39,7 +39,7 @@ def raise_name_error
end

def ensure_shared_example_group_name_not_taken(name)
if Rspec::Core.world.shared_example_groups.has_key?(name)
if Rspec.world.shared_example_groups.has_key?(name)
raise ArgumentError.new("Shared example group '#{name}' already exists")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/configuration_spec.rb
Expand Up @@ -7,7 +7,7 @@ module Rspec::Core
let(:config) { subject }

before(:each) do
Rspec::Core.world.stub(:configuration).and_return(config)
Rspec.world.stub(:configuration).and_return(config)
end

describe "#mock_framework_class" do
Expand Down
12 changes: 6 additions & 6 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -52,13 +52,13 @@ module Rspec::Core
it "is not registered in world" do
parent = ExampleGroup.describe
child = parent.describe
Rspec::Core.world.example_groups.should == [parent]
Rspec.world.example_groups.should == [parent]
end
end

describe "filtering" do
it "includes all examples in an explicitly included group" do
Rspec::Core.world.stub(:inclusion_filter).and_return({ :awesome => true })
Rspec.world.stub(:inclusion_filter).and_return({ :awesome => true })
group = ExampleGroup.describe("does something", :awesome => true)
examples = [
group.example("first"),
Expand All @@ -68,15 +68,15 @@ module Rspec::Core
end

it "includes explicitly included examples" do
Rspec::Core.world.stub(:inclusion_filter).and_return({ :awesome => true })
Rspec.world.stub(:inclusion_filter).and_return({ :awesome => true })
group = ExampleGroup.describe
example = group.example("does something", :awesome => true)
group.example("don't run me")
group.filtered_examples.should == [example]
end

it "excludes all examples in an excluded group" do
Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
Rspec.world.stub(:exclusion_filter).and_return({ :awesome => false })
group = ExampleGroup.describe("does something", :awesome => false)
examples = [
group.example("first"),
Expand All @@ -86,7 +86,7 @@ module Rspec::Core
end

it "filters out excluded examples" do
Rspec::Core.world.stub(:exclusion_filter).and_return({ :awesome => false })
Rspec.world.stub(:exclusion_filter).and_return({ :awesome => false })
group = ExampleGroup.describe("does something")
examples = [
group.example("first", :awesome => false),
Expand All @@ -105,7 +105,7 @@ module Rspec::Core

context "with no examples or groups that match filters" do
it "returns none" do
Rspec::Core.world.stub(:inclusion_filter).and_return({ :awesome => false })
Rspec.world.stub(:inclusion_filter).and_return({ :awesome => false })
group = ExampleGroup.describe
example = group.example("does something")
group.filtered_examples.should == []
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/metadata_spec.rb
Expand Up @@ -190,7 +190,7 @@ module Core
let(:example_line_number) { __LINE__ -1 }
let(:next_example_metadata) {group_metadata.for_example('next_example',
:caller => ["foo_spec.rb:#{example_line_number + 2}"])}
let(:world) { Rspec::Core.world }
let(:world) { Rspec.world }

it "matches the group when the line_number is the example group line number" do
world.should_receive(:preceding_declaration_line).and_return(group_line_number)
Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/core/shared_example_group_spec.rb
Expand Up @@ -27,7 +27,7 @@ module Rspec::Core
describe "share_examples_for" do

it "should capture the given name and block in the Worlds collection of shared example groups" do
Rspec::Core.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
Rspec.world.shared_example_groups.should_receive(:[]=).with(:foo, anything)
share_examples_for(:foo) { }
end

Expand All @@ -41,7 +41,7 @@ module Rspec::Core
def self.class_helper; end
def extra_helper; end
}
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
Rspec.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
group.it_should_behave_like :shared_example_group
group.instance_methods.should include('extra_helper')
group.singleton_methods.should include('class_helper')
Expand Down
3 changes: 1 addition & 2 deletions spec/rspec/core/world_spec.rb
Expand Up @@ -8,8 +8,7 @@ module Rspec::Core
describe World do

before do
@world = Rspec::Core::World.new
Rspec::Core.stub(:world).and_return(@world)
@world = Rspec.world
end

describe "example_groups" do
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core_spec.rb
Expand Up @@ -31,7 +31,7 @@
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)
Rspec.world.should be_instance_of(Rspec::Core::World)
end

end
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -46,10 +46,10 @@ def in_editor?
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
}}
c.before(:each) do
@real_world = Rspec::Core.world
Rspec::Core.instance_variable_set(:@world, Rspec::Core::World.new)
@real_world = Rspec.world
Rspec.instance_variable_set(:@world, Rspec::Core::World.new)
end
c.after(:each) do
Rspec::Core.instance_variable_set(:@world, @real_world)
Rspec.instance_variable_set(:@world, @real_world)
end
end

0 comments on commit b028806

Please sign in to comment.