Testing Dynamic Declaration Equality Comparison in FactoryBot
This test suite examines the equality comparison functionality of Dynamic Declarations in FactoryBot. It verifies various scenarios where Dynamic declarations should or should not be considered equal based on their attributes, blocks, and ignored status. The tests ensure robust object comparison behavior essential for factory definitions.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/factory_bot
spec/factory_bot/declaration/dynamic_spec.rb
describe FactoryBot::Declaration::Dynamic do
describe "#==" do
context "when the attributes are equal" do
it "the objects are equal" do
block = -> {}
declaration = described_class.new(:name, false, block)
other_declaration = described_class.new(:name, false, block)
expect(declaration).to eq(other_declaration)
end
end
context "when the names are different" do
it "the objects are NOT equal" do
block = -> {}
declaration = described_class.new(:name, false, block)
other_declaration = described_class.new(:other_name, false, block)
expect(declaration).not_to eq(other_declaration)
end
end
context "when the blocks are different" do
it "the objects are NOT equal" do
declaration = described_class.new(:name, false, -> {})
other_declaration = described_class.new(:name, false, -> {})
expect(declaration).not_to eq(other_declaration)
end
end
context "when one is ignored and the other isn't" do
it "the objects are NOT equal" do
block = -> {}
declaration = described_class.new(:name, false, block)
other_declaration = described_class.new(:name, true, block)
expect(declaration).not_to eq(other_declaration)
end
end
context "when comparing against another type of object" do
it "the objects are NOT equal" do
declaration = described_class.new(:name, false, -> {})
expect(declaration).not_to eq(:not_a_declaration)
end
end
end
end