2019-04-19 16:01:32 -04:00
|
|
|
describe FactoryBot::Internal do
|
|
|
|
describe ".register_trait" do
|
|
|
|
it "registers the provided trait" do
|
|
|
|
trait = FactoryBot::Trait.new(:admin)
|
|
|
|
configuration = FactoryBot::Internal.configuration
|
2019-04-26 15:48:37 -04:00
|
|
|
|
2020-06-05 15:15:18 -04:00
|
|
|
expect { FactoryBot::Internal.register_trait(trait) }
|
|
|
|
.to change { configuration.traits.count }
|
|
|
|
.from(0)
|
|
|
|
.to(1)
|
2019-04-19 16:01:32 -04:00
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
it "returns the registered trait" do
|
|
|
|
trait = FactoryBot::Trait.new(:admin)
|
|
|
|
|
|
|
|
expect(FactoryBot::Internal.register_trait(trait)).to eq trait
|
|
|
|
end
|
2019-04-19 16:01:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".trait_by_name" do
|
|
|
|
it "finds a previously registered trait" do
|
|
|
|
trait = FactoryBot::Trait.new(:admin)
|
|
|
|
FactoryBot::Internal.register_trait(trait)
|
2019-04-26 15:48:37 -04:00
|
|
|
|
2019-04-19 16:01:32 -04:00
|
|
|
expect(FactoryBot::Internal.trait_by_name(trait.name)).to eq trait
|
|
|
|
end
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
describe ".register_sequence" do
|
|
|
|
it "registers the provided sequence" do
|
|
|
|
sequence = FactoryBot::Sequence.new(:email)
|
|
|
|
configuration = FactoryBot::Internal.configuration
|
2019-04-26 15:48:37 -04:00
|
|
|
|
2020-06-05 15:15:18 -04:00
|
|
|
expect { FactoryBot::Internal.register_sequence(sequence) }
|
|
|
|
.to change { configuration.sequences.count }
|
|
|
|
.from(0)
|
|
|
|
.to(1)
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
it "returns the registered sequence" do
|
|
|
|
sequence = FactoryBot::Sequence.new(:email)
|
|
|
|
|
|
|
|
expect(FactoryBot::Internal.register_sequence(sequence)).to eq sequence
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".sequence_by_name" do
|
|
|
|
it "finds a registered sequence" do
|
|
|
|
sequence = FactoryBot::Sequence.new(:email)
|
|
|
|
FactoryBot::Internal.register_sequence(sequence)
|
2019-04-26 15:48:37 -04:00
|
|
|
|
2019-04-26 15:48:37 -04:00
|
|
|
expect(FactoryBot::Internal.sequence_by_name(sequence.name)).to eq sequence
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".rewind_sequences" do
|
|
|
|
it "rewinds the sequences and the internal sequences" do
|
|
|
|
sequence = instance_double(FactoryBot::Sequence, names: ["email"])
|
|
|
|
allow(sequence).to receive(:rewind)
|
|
|
|
FactoryBot::Internal.register_sequence(sequence)
|
|
|
|
|
|
|
|
inline_sequence = instance_double(FactoryBot::Sequence)
|
|
|
|
allow(inline_sequence).to receive(:rewind)
|
|
|
|
FactoryBot::Internal.register_inline_sequence(inline_sequence)
|
|
|
|
|
|
|
|
FactoryBot::Internal.rewind_sequences
|
|
|
|
|
|
|
|
expect(sequence).to have_received(:rewind).exactly(:once)
|
|
|
|
expect(inline_sequence).to have_received(:rewind).exactly(:once)
|
|
|
|
end
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
describe ".register_factory" do
|
|
|
|
it "registers the provided factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
configuration = FactoryBot::Internal.configuration
|
|
|
|
|
2020-06-05 15:15:18 -04:00
|
|
|
expect { FactoryBot::Internal.register_factory(factory) }
|
|
|
|
.to change { configuration.factories.count }
|
|
|
|
.from(0)
|
|
|
|
.to(1)
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the registered factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
|
|
|
|
expect(FactoryBot::Internal.register_factory(factory)).to eq factory
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".factory_by_name" do
|
|
|
|
it "finds a registered factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
FactoryBot::Internal.register_factory(factory)
|
|
|
|
|
|
|
|
expect(FactoryBot::Internal.factory_by_name(factory.name)).to eq factory
|
|
|
|
end
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
describe ".register_factory" do
|
|
|
|
it "registers the provided factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
configuration = FactoryBot::Internal.configuration
|
2020-06-05 15:15:18 -04:00
|
|
|
expect { FactoryBot::Internal.register_factory(factory) }
|
|
|
|
.to change { configuration.factories.count }
|
|
|
|
.from(0)
|
|
|
|
.to(1)
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the registered factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
expect(FactoryBot::Internal.register_factory(factory)).to eq factory
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".factory_by_name" do
|
|
|
|
it "finds a registered factory" do
|
|
|
|
factory = FactoryBot::Factory.new(:object)
|
|
|
|
FactoryBot::Internal.register_factory(factory)
|
|
|
|
expect(FactoryBot::Internal.factory_by_name(factory.name)).to eq factory
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".register_strategy" do
|
|
|
|
it "register the provided strategy name with the class" do
|
|
|
|
configuration = FactoryBot::Internal.configuration
|
|
|
|
initial_strategies_count = configuration.strategies.count
|
2020-06-05 15:15:18 -04:00
|
|
|
expect {
|
2019-04-26 15:48:37 -04:00
|
|
|
FactoryBot::Internal.register_strategy(:strategy_name, :strategy_class)
|
2020-06-05 15:15:18 -04:00
|
|
|
}.to change { configuration.strategies.count }
|
|
|
|
.from(initial_strategies_count)
|
|
|
|
.to(initial_strategies_count + 1)
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".strategy_by_name" do
|
|
|
|
it "finds a registered strategy" do
|
|
|
|
FactoryBot::Internal.register_strategy(:strategy_name, :strategy_class)
|
2020-06-05 15:15:18 -04:00
|
|
|
expect(FactoryBot::Internal.strategy_by_name(:strategy_name))
|
|
|
|
.to eq :strategy_class
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-19 16:01:32 -04:00
|
|
|
end
|