method for generating list of values in sequence (#967)

This commit is contained in:
rutaka 2016-12-16 14:18:31 +04:00 committed by Josh Clayton
parent ed196bad77
commit e7e128d15c
2 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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