Class: RSpec::Core::Example::Procsy

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/example.rb

Overview

Note:

This class also exposes the instance methods of RSpec::Core::Example, proxying them through to the wrapped RSpec::Core::Example instance.

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

Examples:


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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, &block) ⇒ Procsy

Returns a new instance of Procsy



246
247
248
249
250
# File 'lib/rspec/core/example.rb', line 246

def initialize(example, &block)
  @example  = example
  @proc     = block
  @executed = false
end

Instance Attribute Details

#examplevoid (readonly)

The RSpec::Core::Example instance.



219
220
221
# File 'lib/rspec/core/example.rb', line 219

def example
  @example
end

Instance Method Details

#call(*args, &block) ⇒ void Also known as: run

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



234
235
236
237
# File 'lib/rspec/core/example.rb', line 234

def call(*args, &block)
  @executed = true
  @proc.call(*args, &block)
end

#executed?Boolean

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

Returns:

  • (Boolean)


258
259
260
# File 'lib/rspec/core/example.rb', line 258

def executed?
  @executed
end

#to_procvoid

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



242
243
244
# File 'lib/rspec/core/example.rb', line 242

def to_proc
  method(:call).to_proc
end