Sha256: 9613b948efbbd6ee07326e9ee41500562528dbe6692672e56aa6e75da534cc57

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe "sequences" do
  include FactoryGirl::Syntax::Methods

  it "generates several values in the correct format" do
    FactoryGirl.define do
      sequence :email do |n|
        "somebody#{n}@example.com"
      end
    end

    first_value = generate(:email)
    another_value = generate(:email)

    expect(first_value).to match /^somebody\d+@example\.com$/
    expect(another_value).to match /^somebody\d+@example\.com$/
    expect(first_value).not_to eq another_value
  end

  it "generates sequential numbers if no block is given" do
    FactoryGirl.define do
      sequence :order
    end

    first_value = generate(:order)
    another_value = generate(:order)

    expect(first_value).to eq 1
    expect(another_value).to eq 2
    expect(first_value).not_to eq another_value
  end

  it "generates aliases for the sequence that reference the same block" do
    FactoryGirl.define do
      sequence(:size, aliases: [:count, :length]) {|n| "called-#{n}" }
    end

    first_value  = generate(:size)
    second_value = generate(:count)
    third_value  = generate(:length)

    expect(first_value).to eq "called-1"
    expect(second_value).to eq "called-2"
    expect(third_value).to eq "called-3"
  end

  it "generates aliases for the sequence that reference the same block and retains value" do
    FactoryGirl.define do
      sequence(:size, "a", aliases: [:count, :length]) {|n| "called-#{n}" }
    end

    first_value  = generate(:size)
    second_value = generate(:count)
    third_value  = generate(:length)

    expect(first_value).to eq "called-a"
    expect(second_value).to eq "called-b"
    expect(third_value).to eq "called-c"
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
factory_girl-4.3.0 spec/acceptance/sequence_spec.rb
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/sequence_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/sequence_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/sequence_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/spec/acceptance/sequence_spec.rb
factory_girl-4.2.0 spec/acceptance/sequence_spec.rb