Module: FixtureKit::RSpec::ClassMethods
- Defined in:
- lib/fixture_kit/rspec.rb
Overview
Class methods (extended via config.extend)
Instance Method Summary collapse
-
#fixture(name = nil, extends: nil, &block) ⇒ Object
Declare which fixture to use for this example group.
Instance Method Details
#fixture(name = nil, extends: nil, &block) ⇒ Object
Declare which fixture to use for this example group. Can be overridden in nested groups (like ‘let`).
Example:
RSpec.describe User do
fixture "basic_users"
it "has users" do
expect(fixture.alice).to be_present
end
context "with admins" do
fixture "admin_users" # Override
it "has admin" do
expect(fixture.admin).to be_present
end
end
end
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fixture_kit/rspec.rb', line 30 def fixture(name = nil, extends: nil, &block) definition = Definition.new(extends: extends, &block) if block_given? declaration = ::RSpec.configuration.fixture_kit.register(name || definition, self) # Use update_inherited_metadata to set the declaration on this group # AND propagate to any child groups already created (e.g., shared # example groups auto-included via `config.include_context` during # RSpec configuration). (DECLARATION_METADATA_KEY => declaration) prepend_before(:context) do self.class.[DECLARATION_METADATA_KEY].generate end append_after(:context) do self.class.[DECLARATION_METADATA_KEY].finish end end |