mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
method for generating list of values in sequence (#967)
This commit is contained in:
parent
ed196bad77
commit
e7e128d15c
2 changed files with 29 additions and 0 deletions
|
@ -90,6 +90,22 @@ module FactoryGirl
|
|||
def generate(name)
|
||||
FactoryGirl.sequence_by_name(name).next
|
||||
end
|
||||
|
||||
# Generates and returns the list of values in a sequence.
|
||||
#
|
||||
# Arguments:
|
||||
# name: (Symbol)
|
||||
# The name of the sequence that a value should be generated for.
|
||||
# count: (Fixnum)
|
||||
# Count of values
|
||||
#
|
||||
# Returns:
|
||||
# The next value in the sequence. (Object)
|
||||
def generate_list(name, count)
|
||||
(1..count).map do
|
||||
FactoryGirl.sequence_by_name(name).next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,4 +58,17 @@ describe "sequences" do
|
|||
expect(second_value).to eq "called-b"
|
||||
expect(third_value).to eq "called-c"
|
||||
end
|
||||
|
||||
it "generates few values of the sequence" do
|
||||
FactoryGirl.define do
|
||||
sequence :email do |n|
|
||||
"somebody#{n}@example.com"
|
||||
end
|
||||
end
|
||||
|
||||
values = generate_list(:email, 2)
|
||||
|
||||
expect(values.first).to eq("somebody1@example.com")
|
||||
expect(values.second).to eq("somebody2@example.com")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue