Sha256: 3f77a87a58ddc532623b2c8826f7bc41942b704ccc7a90d488e05a0bde699dfa

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

RSpec.configure do |c|
  c.around { |ex| Sandboxing.sandboxed { ex.run } }
end

class NullObject
  private
  def method_missing(method, *args, &block)
    # ignore
  end
end

module Sandboxing
  def self.sandboxed(&block)
    orig_load_path = $LOAD_PATH.dup
    orig_config = RSpec.configuration
    orig_world  = RSpec.world
    orig_example = RSpec.current_example
    new_config = RSpec::Core::Configuration.new
    new_config.expose_dsl_globally = false
    new_config.expecting_with_rspec = true
    new_world  = RSpec::Core::World.new(new_config)
    RSpec.configuration = new_config
    RSpec.world = new_world
    object = Object.new
    object.extend(RSpec::Core::SharedExampleGroup)

    (class << RSpec::Core::ExampleGroup; self; end).class_exec do
      alias_method :orig_run, :run
      def run(reporter=nil)
        RSpec.current_example = nil
        orig_run(reporter || NullObject.new)
      end
    end

    RSpec::Mocks.with_temporary_scope do
      object.instance_exec(&block)
    end
  ensure
    (class << RSpec::Core::ExampleGroup; self; end).class_exec do
      remove_method :run
      alias_method :run, :orig_run
      remove_method :orig_run
    end

    RSpec.configuration = orig_config
    RSpec.world = orig_world
    RSpec.current_example = orig_example
    $LOAD_PATH.replace(orig_load_path)
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
opal-rspec-0.6.2 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.6.1 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.6.0 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.6.0.beta1 rspec-core/spec/support/sandboxing.rb
opal-connect-rspec-0.5.0 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.5.0 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.5.0.beta3 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.5.0.beta2 rspec-core/spec/support/sandboxing.rb
opal-rspec-0.5.0.beta1 rspec-core/spec/support/sandboxing.rb