Module: RSpec::Core::SharedExampleGroup

Included in:
ExampleGroup, ExampleGroup
Defined in:
lib/rspec/core/shared_example_group.rb,
lib/rspec/core/shared_example_group/collection.rb

Defined Under Namespace

Modules: TopLevelDSL Classes: Collection

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registryObject



70
71
72
# File 'lib/rspec/core/shared_example_group.rb', line 70

def self.registry
  @registry ||= Registry.new
end

Instance Method Details

#share_as(name, &block) ⇒ Object

Deprecated.


40
41
42
43
44
# File 'lib/rspec/core/shared_example_group.rb', line 40

def share_as(name, &block)
  RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
                  :replacement => "RSpec::SharedContext or shared_examples")
  SharedExampleGroup.registry.add_const(self, name, &block)
end

#shared_example_groupsObject



46
47
48
# File 'lib/rspec/core/shared_example_group.rb', line 46

def shared_example_groups
  SharedExampleGroup.registry.shared_example_groups_for('main', *ancestors[0..-1])
end

#shared_examples(name, &block) ⇒ Object #shared_examples(name, tags, &block) ⇒ Object Also known as: shared_context, share_examples_for, shared_examples_for

Wraps the block in a module which can then be included in example groups using include_examples, include_context, or it_behaves_like.

Examples:


shared_examples "auditable" do
  it "stores an audit record on save!" do
    lambda { auditable.save! }.should change(Audit, :count).by(1)
  end
end

class Account do
  it_behaves_like "auditable" do
    def auditable; Account.new; end
  end
end

Parameters:

  • name (String)

    to match when looking up this shared group

  • block

    to be eval'd in a nested example group generated by it_behaves_like

See Also:



31
32
33
# File 'lib/rspec/core/shared_example_group.rb', line 31

def shared_examples(*args, &block)
  SharedExampleGroup.registry.add_group(self, *args, &block)
end