File: disallows_duplicates_registry_spec.rb

package info (click to toggle)
ruby-factory-bot 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: ruby: 7,827; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
describe FactoryBot::Decorator::DisallowsDuplicatesRegistry do
  it "delegates #register to the registry when not registered" do
    registry = double("registry", name: "Great thing", register: true)
    decorator = FactoryBot::Decorator::DisallowsDuplicatesRegistry.new(registry)
    allow(registry).to receive(:registered?).and_return false
    decorator.register(:awesome, {})

    expect(registry).to have_received(:register).with(:awesome, {})
  end

  it "raises when attempting to #register a previously registered strategy" do
    registry = double("registry", name: "Great thing", register: true)
    decorator = FactoryBot::Decorator::DisallowsDuplicatesRegistry.new(registry)
    allow(registry).to receive(:registered?).and_return true

    expect { decorator.register(:same_name, {}) }
      .to raise_error(FactoryBot::DuplicateDefinitionError, "Great thing already registered: same_name")
  end
end