Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fixture_kit/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.configure!(config)
FixtureKit.runner.configuration.adapter(FixtureKit::RSpecAdapter)

config.extend ClassMethods
config.include InstanceMethods, DECLARATION_METADATA_KEY
config.include InstanceMethods

# Load declared fixtures at the beginning of each example.
# Runs inside transactional fixtures and before user-defined before hooks.
Expand Down
13 changes: 13 additions & 0 deletions spec/dummy/spec/integration/fixture_kit_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,17 @@ module FixtureKitIntegrationTimeHelpers
puts "FKIT_ASSERT:ANONYMOUS_DUPLICATE_DECLARATION"
end
end

describe "fixture instance reader without declaration" do
it "raises a helpful error message" do
expect do
fixture
end.to raise_error(
RuntimeError,
"No fixture declared for this example group. Use `fixture \"name\"` in your describe/context block."
)

puts "FKIT_ASSERT:UNDECLARED_FIXTURE_READER"
end
end
end
12 changes: 12 additions & 0 deletions spec/dummy/test/integration/fixture_kit_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ class FixtureKitAnonymousDuplicateDeclarationIntegrationTest < ActiveSupport::Te
puts "FKIT_ASSERT:ANONYMOUS_DUPLICATE_DECLARATION"
end
end

class FixtureKitUndeclaredFixtureReaderIntegrationTest < ActiveSupport::TestCase
test "raises a helpful error message when fixture is called without declaration" do
error = assert_raises(RuntimeError) { fixture }

assert_equal(
"No fixture declared for this test class. Use `fixture \"name\"` in your test class.",
error.message
)
puts "FKIT_ASSERT:UNDECLARED_FIXTURE_READER"
end
end
3 changes: 2 additions & 1 deletion spec/integration/dummy_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def run_dummy_tests
"FKIT_ASSERT:ANONYMOUS_CACHE_PATH",
"FKIT_ASSERT:ANONYMOUS_HELPER_METHODS",
"FKIT_ASSERT:ANONYMOUS_NESTED_OVERRIDE",
"FKIT_ASSERT:ANONYMOUS_DUPLICATE_DECLARATION"
"FKIT_ASSERT:ANONYMOUS_DUPLICATE_DECLARATION",
"FKIT_ASSERT:UNDECLARED_FIXTURE_READER"
]

expected_markers.each do |marker|
Expand Down