Skip to content

Commit

Permalink
Add setters for RSpec.world and RSpec.configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
soulim committed Apr 21, 2013
1 parent 20a9f9d commit 02ed4fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/rspec/core.rb
Expand Up @@ -60,6 +60,12 @@ def self.world
@world ||= RSpec::Core::World.new
end

# @private
# Used internally to set the global object
def self.world=(new_world)
@world = new_world
end

# @private
# Used internally to ensure examples get reloaded between multiple runs in
# the same process.
Expand Down Expand Up @@ -94,6 +100,12 @@ def self.configuration
@configuration ||= RSpec::Core::Configuration.new
end

# @private
# Used internally to set the global object
def self.configuration=(new_configuration)
@configuration = new_configuration
end

# Yields the global configuration to a block.
# @yield [Configuration] global configuration
#
Expand Down
20 changes: 20 additions & 0 deletions spec/rspec/core_spec.rb
Expand Up @@ -7,6 +7,16 @@
end
end

describe "::configuration=" do
it "sets the configuration object" do
configuration = RSpec::Core::Configuration.new

RSpec.configuration = configuration

expect(RSpec.configuration).to equal(configuration)
end
end

describe "::configure" do
it "yields the current configuration" do
RSpec.configure do |config|
Expand All @@ -21,6 +31,16 @@
end
end

describe "::world=" do
it "sets the world object" do
world = RSpec::Core::World.new

RSpec.world = world

expect(RSpec.world).to equal(world)
end
end

describe "::reset" do
it "resets the configuration and world objects" do
config_before_reset = RSpec.configuration
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Expand Up @@ -41,8 +41,8 @@ def self.sandboxed(&block)
@orig_world = RSpec.world
new_config = RSpec::Core::Configuration.new
new_world = RSpec::Core::World.new(new_config)
RSpec.instance_variable_set(:@configuration, new_config)
RSpec.instance_variable_set(:@world, new_world)
RSpec.configuration = new_config
RSpec.world = new_world
object = Object.new
object.extend(RSpec::Core::SharedExampleGroup)

Expand All @@ -63,8 +63,8 @@ def run(reporter=nil)
remove_method :orig_run
end

RSpec.instance_variable_set(:@configuration, @orig_config)
RSpec.instance_variable_set(:@world, @orig_world)
RSpec.configuration = @orig_config
RSpec.world = @orig_world
end
end

Expand Down

0 comments on commit 02ed4fa

Please sign in to comment.