Sha256: dca32915d10ab0cf05c1830c2f5ad3275dac2d2d729cf325daee2552f13abb73

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe 'sequences are evaluated in the correct context' do
  before do
    define_class("User") do
      attr_accessor :id

      def awesome
        'aw yeah'
      end
    end
  end

  it 'builds a sequence calling sprintf correctly' do
    FactoryGirl.define do
      factory :sequence_with_sprintf, class: User do
        sequence(:id) { |n| sprintf("foo%d", n) }
      end
    end

    expect(FactoryGirl.build(:sequence_with_sprintf).id).to eq 'foo1'
  end

  it 'invokes the correct method on the instance' do
    FactoryGirl.define do
      factory :sequence_with_public_method, class: User do
        sequence(:id) { |n| public_method(:awesome).call }
      end
    end

    expect(FactoryGirl.build(:sequence_with_public_method).id).to eq 'aw yeah'
  end

  it 'invokes a method with no arguments on the instance' do
    FactoryGirl.define do
      factory :sequence_with_frozen, class: User do
        sequence(:id) { |n| frozen? }
      end
    end

    expect(FactoryGirl.build(:sequence_with_frozen).id).to be_false
  end

  it 'allows direct reference of a method in a sequence' do
    FactoryGirl.define do
      factory :sequence_referencing_attribute_directly, class: User do
        sequence(:id) { |n| "#{awesome}#{n}" }
      end
    end
    expect(FactoryGirl.build(:sequence_referencing_attribute_directly).id).to eq 'aw yeah1'
  end
end

Version data entries

10 entries across 7 versions & 4 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/factory_girl-4.5.0/spec/acceptance/sequence_context_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/sequence_context_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/sequence_context_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/factory_girl-4.5.0/spec/acceptance/sequence_context_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/sequence_context_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/sequence_context_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/spec/acceptance/sequence_context_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/spec/acceptance/sequence_context_spec.rb
factory_girl-4.5.0 spec/acceptance/sequence_context_spec.rb
factory_girl-4.4.0 spec/acceptance/sequence_context_spec.rb