Method: RSpec.current_example

Defined in:
lib/rspec/core.rb

.current_examplevoid

The example being executed.

The primary audience for this method is library authors who need access to the example currently being executed and also want to support all versions of RSpec 2 and 3.

Examples:


RSpec.configure do |c|
  # context.example is deprecated, but RSpec.current_example is not
  # available until RSpec 3.0.
  fetch_current_example = RSpec.respond_to?(:current_example) ?
    proc { RSpec.current_example } : proc { |context| context.example }

  c.before(:example) do
    example = fetch_current_example.call(self)

    # ...
  end
end

122
123
124
# File 'lib/rspec/core.rb', line 122

def self.current_example
  RSpec::Support.thread_local_data[:current_example]
end