| 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 | ||
| define_example_method | -> | alias_example_to |
| define_nested_shared_group_method | -> | alias_it_should_behave_like_to |
| describe | -> | context |
| example | [RW] | @attr_reader Returns the [Example](Example) object that wraps this instance of `ExampleGroup` |
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
@private @return [Metadata] belonging to the parent of a nested [ExampleGroup](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