class RSpec::Core::Example::Procsy

Wraps both a ‘Proc` and an {Example} for use in {Hooks#around around} hooks. In around hooks we need to yield this special kind of object (rather than the raw {Example}) because when there are multiple `around` hooks we have to wrap them recursively.

@example

RSpec.configure do |c|
  c.around do |ex| # Procsy which wraps the example
    if ex.metadata[:key] == :some_value && some_global_condition
      raise "some message"
    end
    ex.run         # run delegates to ex.call.
  end
end

@note This class also exposes the instance methods of {Example},

proxying them through to the wrapped {Example} instance.

Attributes

The {Example} instance.

Public Class Methods

# File rspec-core/lib/rspec/core/example.rb, line 362
def initialize(example, &block)
  @example  = example
  @proc     = block
  @executed = false
end

Public Instance Methods

Calls the proc and notes that the example has been executed.

# File rspec-core/lib/rspec/core/example.rb, line 350
def call(*args, &block)
  @executed = true
  @proc.call(*args, &block)
end
Also aliased as: run

Indicates whether or not the around hook has executed the example.

# File rspec-core/lib/rspec/core/example.rb, line 374
def executed?
  @executed
end

@private

# File rspec-core/lib/rspec/core/example.rb, line 379
def inspect
  @example.inspect.gsub('Example', 'Example::Procsy')
end

Provides a wrapped proc that will update our ‘executed?` state when executed.

# File rspec-core/lib/rspec/core/example.rb, line 358
def to_proc
  method(:call).to_proc
end

@private

# File rspec-core/lib/rspec/core/example.rb, line 369
def wrap(&block)
  self.class.new(example, &block)
end