File: disallows_duplicates_registry_spec.rb

package info (click to toggle)
ruby-factory-bot 6.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,492 kB
  • sloc: ruby: 9,242; makefile: 6; sh: 4
file content (19 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (3)
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