Class | RSpec::Core::ExampleGroup |
In: |
lib/rspec/core/example_group.rb
|
Parent: | Object |
ExampleGroup and {Example} are the main structural elements of rspec-core. Consider this example:
describe Thing do it "does something" do end end
The object returned by `describe Thing` is a subclass of ExampleGroup. The object returned by `it "does something"` is an instance of Example, which serves as a wrapper for an instance of the ExampleGroup in which it is declared.
description | -> | display_name |
described_class | -> | describes |
@private | ||
describe | -> | context |
example | [RW] | @attr_reader Returns the {Example} object that wraps this instance of `ExampleGroup` |
Works like `alias_method :name, :example` with the added benefit of assigning default metadata to the generated example.
@note Use with caution. This extends the language used in your
specs, but does not add any additional documentation. We use this in rspec to define methods like `focus` and `xit`, but we also add docs for those methods.
Works like `alias_method :name, :it_behaves_like` with the added benefit of assigning default metadata to the generated example.
@note Use with caution. This extends the language used in your
specs, but does not add any additional documentation. We use this in rspec to define `it_should_behave_like` (for backward compatibility), but we also add docs for that method.
@private @macro [attach] define_example_method
@param [String] name @param [Hash] extra_options @param [Block] implementation
@private @macro [attach] define_nested_shared_group_method
@see SharedExampleGroup
Generates a subclass of this example group which inherits everything except the examples themselves.
## Examples
describe "something" do # << This describe method is defined in # << RSpec::Core::DSL, included in the # << global namespace before do do_something_before end let(:thing) { Thing.new } describe "attribute (of something)" do # examples in the group get the before hook # declared above, and can access `thing` end end
@see DSL#describe
Includes shared content mapped to `name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval‘d in the current context.
@see SharedExampleGroup
Includes shared content mapped to `name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval‘d in the current context.
@see SharedExampleGroup
@private @return [Metadata] belonging to the parent of a nested {ExampleGroup}
Returns the class or module passed to the `describe` method (or alias). Returns nil if the subject is not a class or module. @example
describe Thing do it "does something" do described_class == Thing end end