mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
2b524b060d
Closes #970 In this code we are passing an implicit declaration `user`, rather than the symbol `:user`: ```rb factory :post do author factory: user end ``` This will raise a confusing error: `undefined method 'name' for :comment:Symbol`. This is coming from the implicit declaration `#==` method, called on lib/factory_bot/attribute_list.rb#56. The method wasn't ever designed to compare against objects of different classes. I added some tests for all the declaration classes to handle being compared against other kinds of objects. Co-authored-by: Dusan Orlovic <duleorlovic@gmail.com>
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
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
|