Sha256: d0b39ec2df360ba81e6f5ced4d7d3e99d5c8d13333d1071d9543aaa303ce9e21

Contents?: true

Size: 1.47 KB

Versions: 142

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe FactoryGirl::Attribute::Dynamic do
  let(:name)  { :first_name }
  let(:block) { -> { } }

  subject { FactoryGirl::Attribute::Dynamic.new(name, false, block) }

  its(:name) { should == name }

  context "with a block returning a static value" do
    let(:block) { -> { "value" } }

    it "returns the value when executing the proc" do
      subject.to_proc.call.should == "value"
    end
  end

  context "with a block returning its block-level variable" do
    let(:block) { ->(thing) { thing } }

    it "returns self when executing the proc" do
      subject.to_proc.call.should == subject
    end
  end

  context "with a block referencing an attribute on the attribute" do
    let(:block)  { -> { attribute_defined_on_attribute } }
    let(:result) { "other attribute value" }

    before do
      subject.stubs(attribute_defined_on_attribute: result)
    end

    it "evaluates the attribute from the attribute" do
      subject.to_proc.call.should == result
    end
  end

  context "with a block returning a sequence" do
    let(:block) { -> { FactoryGirl.register_sequence(FactoryGirl::Sequence.new(:email, 1) {|n| "foo#{n}" }) } }

    it "raises a sequence abuse error" do
      expect { subject.to_proc.call }.to raise_error(FactoryGirl::SequenceAbuseError)
    end
  end
end

describe FactoryGirl::Attribute::Dynamic, "with a string name" do
  subject    { FactoryGirl::Attribute::Dynamic.new("name", false, -> { } ) }
  its(:name) { should == :name }
end

Version data entries

142 entries across 82 versions & 6 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/attribute/dynamic_spec.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/attribute/dynamic_spec.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/attribute/dynamic_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/spec/factory_girl/attribute/dynamic_spec.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.2.0/spec/factory_girl/attribute/dynamic_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/attribute/dynamic_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/spec/factory_girl/attribute/dynamic_spec.rb