Class | RSpec::Core::Example |
In: |
lib/rspec/core/example.rb
|
Parent: | Object |
Wrapper for an instance of a subclass of {ExampleGroup}. An instance of `Example` is returned by the {ExampleGroup#example example} method exposed to examples, {Hooks#before before} and {Hooks#after after} hooks, and yielded to {Hooks#around around} hooks.
Useful for configuring logging and/or taking some action based on the state of an example‘s metadata.
@example
RSpec.configure do |config| config.before do log example.description end config.after do log example.description end config.around do |ex| log example.description ex.run end end shared_examples "auditable" do it "does something" do log "#{example.full_description}: #{auditable.inspect}" auditable.should do_something end end
@see ExampleGroup
pending | -> | pending? |
example_group_instance | [R] |
@attr_reader @private
Returns the example_group_instance that provides the context for running this example. |
exception | [R] |
@attr_reader
Returns the first exception raised in the context of running this example (nil if no exception is raised) |
metadata | [R] |
@attr_reader
Returns the metadata object associated with this example. |
Creates a new instance of Example. @param example_group_class the subclass of ExampleGroup in which this Example is declared @param description the String passed to the `it` method (or alias) @param metadata additional args passed to `it` to be used as metadata @param example_block the block of code that represents the example
@api private
Wraps the example block in a Proc so it can invoked using `run` or `call` in [around](../Hooks#around-instance_method) hooks.
Returns the string submitted to `example` or its aliases (e.g. `specify`, `it`, etc). If no string is submitted (e.g. `it { should do_something }`) it returns the message generated by the matcher if there is one, otherwise returns a message including the location of the example.
@private
Used internally to set an exception and fail without actually executing the example when an exception is raised in before(:all).
@api private instance_evals the block passed to the constructor in the context of the instance of {ExampleGroup}. @param example_group_instance the instance of an ExampleGroup subclass