模块: RSpec::Core::Sandbox
- 定义于
- lib/rspec/core/sandbox.rb
概述
注意
此模块通常不可用。您必须需要 rspec/core/sandbox
来加载它。
沙盒将封闭代码隔离到一个看起来“新”的环境中,这意味着全局访问的对象在沙盒持续时间内将被重置。
类方法摘要 折叠
-
.sandboxed ⇒ void
使用重置的 RSpec 全局对象(配置、世界)执行提供的块。
类方法详情
.sandboxed ⇒void
使用重置的 RSpec 全局对象(配置、世界)执行提供的块。这用于使用 RSpec 测试 RSpec。
调用此方法时,配置将传递到提供的块中。使用它为您的沙盒示例设置自定义配置。
Sandbox.sandboxed do |config|
config.before(:context) { RSpec.current_example = nil }
end
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/core/sandbox.rb', line 21 def self.sandboxed orig_config = RSpec.configuration orig_world = RSpec.world orig_example = RSpec.current_example RSpec.configuration = RSpec::Core::Configuration.new RSpec.world = RSpec::Core::World.new(RSpec.configuration) yield RSpec.configuration ensure RSpec.configuration = orig_config RSpec.world = orig_world RSpec.current_example = orig_example end |