Module: RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
- Included in:
- Examples::PropertyExamples, Examples::PropertyExamples::ClassProperties, Examples::PropertyExamples::Constants, Examples::PropertyExamples::Predicates, Examples::PropertyExamples::PrivateProperties, Examples::PropertyExamples::Properties, Examples::RSpecMatcherExamples
- Defined in:
- lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb
Overview
Methods for creating reusable shared example groups and shared contexts in a module that can be mixed into multiple RSpec example groups.
Instance Method Summary collapse
-
#alias_shared_examples(new_name, old_name) ⇒ Object
(also: #alias_shared_context)
Aliases a defined shared example group, allowing it to be accessed using a new name.
-
#included(other) ⇒ Object
private
Hook to merge defined example groups when included in another module.
-
#shared_examples(name, *metadata_args, &block) ⇒ Object
(also: #shared_context)
Defines a shared example group within the context of the current module.
Instance Method Details
#alias_shared_examples(new_name, old_name) ⇒ Object Also known as:
Aliases a defined shared example group, allowing it to be accessed using a new name. The example group must be defined in the current context using ‘shared_examples`. The aliases must be defined before including the module into an example group, or they will not be available in the example group.
37 38 39 40 41 42 43 44 |
# File 'lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb', line 37 def alias_shared_examples new_name, old_name example_group = shared_example_groups[self][old_name] definition = example_group_definition(example_group) raise ArgumentError.new(%{Could not find shared examples "#{old_name}"}) if definition.nil? self.shared_examples new_name, &definition end |
#included(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hook to merge defined example groups when included in another module.
50 51 52 53 54 |
# File 'lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb', line 50 def included other super merge_shared_example_groups other end |
#shared_examples(name, &block) ⇒ Object #shared_examples(name, metadata, &block) ⇒ Object Also known as:
Defines a shared example group within the context of the current module. Unlike a top-level example group defined using RSpec#shared_examples, these examples are not globally available, and must be mixed into an example group by including the module. The shared examples must be defined before including the module, or they will not be available in the example group.
72 73 74 |
# File 'lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb', line 72 def shared_examples name, *, &block RSpec.world.shared_example_group_registry.add(self, name, *, &block) end |