Testing AttributeHash Decorator Implementation in factory_bot
This test suite examines the AttributeHash decorator in FactoryBot, focusing on attribute handling and hash generation functionality. The tests verify proper attribute extraction and handling of edge cases, particularly when dealing with nested attribute structures.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/factory_bot
spec/factory_bot/decorator/attribute_hash_spec.rb
describe FactoryBot::Decorator::AttributeHash do
describe "#attributes" do
it "returns a hash of attributes" do
attributes = {attribute_1: :value, attribute_2: :value}
component = double(:component, attributes)
decorator = described_class.new(component, [:attribute_1, :attribute_2])
expect(decorator.attributes).to eq(attributes)
end
context "with an attribute called 'attributes'" do
it "does not call itself recursively" do
attributes = {attributes: :value}
component = double(:component, attributes)
decorator = described_class.new(component, [:attributes])
expect(decorator.attributes).to eq(attributes)
end
end
end
end