diff --git a/lib/factory_girl/syntax/methods.rb b/lib/factory_girl/syntax/methods.rb index 566387d..0b40102 100644 --- a/lib/factory_girl/syntax/methods.rb +++ b/lib/factory_girl/syntax/methods.rb @@ -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 diff --git a/spec/acceptance/sequence_spec.rb b/spec/acceptance/sequence_spec.rb index 243a11d..d671660 100644 --- a/spec/acceptance/sequence_spec.rb +++ b/spec/acceptance/sequence_spec.rb @@ -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