class Fibre::Scope

Attributes

fiber[RW]
mocks[RW]

Public Class Methods

await() { |mock| ... } click to toggle source
# File lib/fibre/scope.rb, line 22
def await
  scope = Fiber.current[:scope]
  mock = Fibre::Mock.new(scope)
  scope.mocks << mock
  yield(mock) if block_given?
  mock
end
in_scope?() click to toggle source
# File lib/fibre/scope.rb, line 18
def in_scope?
  !!Fiber.current[:scope]
end
new(fiber) click to toggle source
# File lib/fibre/scope.rb, line 31
def initialize(fiber)
  @fiber = fiber
  @mocks = []
end
scope() { || ... } click to toggle source
# File lib/fibre/scope.rb, line 8
def scope
  raise 'nested scopes' if Fiber.current[:scope]
  scope = self.new(Fiber.current)
  Fiber.current[:scope] = scope
  yield
  Fiber.current[:scope] = nil
  Fiber.yield!
  scope.mocks
end

Public Instance Methods

check() click to toggle source
# File lib/fibre/scope.rb, line 36
def check
  fiber.resume if @mocks.all?(&:completed?)
end