@overload #shared_examples(name,
&block)
@param name [String, Symbol, Module] identifer to use when looking up this shared group
@param block The block to be eval'd
@overload #shared_examples(name,
metadata, &block)
@param name [String, Symbol, Module] identifer to use when looking up this shared group
@param metadata [Array<Symbol>, Hash] metadata to attach to this group; any example group
with matching metadata will automatically include this shared example group.
@param block The block to be eval'd
@overload #shared_examples(metadata,
&block)
@param metadata [Array<Symbol>, Hash] metadata to attach to this group; any example group
with matching metadata will automatically include this shared example group.
@param block The block to be eval'd
Stores the block for later use. The block will be evaluated in the context
of an example group via `include_examples`, `include_context`, or
`it_behaves_like`.
@example
shared_examples "auditable" do
it "stores an audit record on save!" do
expect { auditable.save! }.to change(Audit, :count).by(1)
end
end
describe Account do
it_behaves_like "auditable" do
let(:auditable) { Account.new }
end
end
@see ExampleGroup.it_behaves_like @see RSpec::Core::ExampleGroup.include_examples
@see RSpec::Core::ExampleGroup.include_context
def shared_examples(name, *args, &block)
top_level = self == ExampleGroup
if top_level && RSpec.thread_local_metadata[:in_example_group]
raise "Creating isolated shared examples from within a context is " +
"not allowed. Remove `RSpec.` prefix or move this to a " +
"top-level scope."
end
RSpec.world.shared_example_group_registry.add(self, name, *args, &block)
end