mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Ensure that iterating over each registered factory returns them uniquely
This commit is contained in:
parent
2f41dc729e
commit
d7feb60bf5
2 changed files with 14 additions and 1 deletions
|
@ -16,7 +16,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def each(&block)
|
||||
@items.values.each(&block)
|
||||
@items.values.uniq.each(&block)
|
||||
end
|
||||
|
||||
def [](name)
|
||||
|
|
|
@ -50,6 +50,19 @@ describe FactoryGirl::Registry do
|
|||
result.should =~ [factory, other_factory]
|
||||
end
|
||||
|
||||
it "iterates registered factories uniquely with aliases" do
|
||||
other_factory = FactoryGirl::Factory.new(:string, :aliases => [:awesome])
|
||||
subject.add(factory)
|
||||
subject.add(other_factory)
|
||||
result = []
|
||||
|
||||
subject.each do |value|
|
||||
result << value
|
||||
end
|
||||
|
||||
result.should =~ [factory, other_factory]
|
||||
end
|
||||
|
||||
it "registers an sequence" do
|
||||
sequence = FactoryGirl::Sequence.new(:email) { |n| "somebody#{n}@example.com" }
|
||||
subject.add(sequence)
|
||||
|
|
Loading…
Reference in a new issue