Sha256: 9b62ec660ccaeacbc9c4378fd9f5c9981b273be8f5d59ce022550c1e457817f7

Contents?: true

Size: 1.43 KB

Versions: 26

Compression:

Stored size: 1.43 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

describe Factory::Attribute::Dynamic do
  before do
    @name  = :first_name
    @block = lambda { 'value' }
    @attr  = Factory::Attribute::Dynamic.new(@name, @block)
  end

  it "should have a name" do
    @attr.name.should == @name
  end

  it "should call the block to set a value" do
    @proxy = "proxy"
    stub(@proxy).set
    @attr.add_to(@proxy)
    @proxy.should have_received.set(@name, 'value')
  end

  it "should yield the proxy to the block when adding its value to a proxy" do
    @block = lambda {|a| a }
    @attr  = Factory::Attribute::Dynamic.new(:user, @block)
    @proxy = "proxy"
    stub(@proxy).set
    @attr.add_to(@proxy)
    @proxy.should have_received.set(:user, @proxy)
  end

  it "should raise an error when defining an attribute writer" do
    lambda {
      Factory::Attribute::Dynamic.new('test=', nil)
    }.should raise_error(Factory::AttributeDefinitionError)
  end

  it "should raise an error when returning a sequence" do
    stub(Factory).sequence { Factory::Sequence.new }
    block = lambda { Factory.sequence(:email) }
    attr = Factory::Attribute::Dynamic.new(:email, block)
    proxy = stub!.set.subject
    lambda {
      attr.add_to(proxy)
    }.should raise_error(Factory::SequenceAbuseError)
  end

  it "should convert names to symbols" do
    Factory::Attribute::Dynamic.new('name', nil).name.should == :name
  end
end

Version data entries

26 entries across 26 versions & 14 rubygems

Version Path
BrettRasmussen-factory_girl-1.2.2 spec/factory_girl/attribute/dynamic_spec.rb
BrettRasmussen-factory_girl-1.2.3 spec/factory_girl/attribute/dynamic_spec.rb
agibralter-factory_girl-1.2.1 spec/factory_girl/attribute/dynamic_spec.rb
lacomartincik-factory_girl-1.2.1.1 spec/factory_girl/attribute/dynamic_spec.rb
qrush-factory_girl-1.2.1.1 spec/factory_girl/attribute/dynamic_spec.rb
thoughtbot-factory_girl-1.2.2 spec/factory_girl/attribute/dynamic_spec.rb
ttilley-factory_girl-1.2.2.1 spec/factory_girl/attribute/dynamic_spec.rb
ttilley-factory_girl-1.2.2.2 spec/factory_girl/attribute/dynamic_spec.rb
ttilley-factory_girl-1.2.2 spec/factory_girl/attribute/dynamic_spec.rb
vitalish-factory_girl-1.2.10 spec/factory_girl/attribute/dynamic_spec.rb
vitalish-factory_girl-1.2.9 spec/factory_girl/attribute/dynamic_spec.rb
vitalish-factory_girl-1.2.8 spec/factory_girl/attribute/dynamic_spec.rb
vitalish-factory_girl-1.2.7 spec/factory_girl/attribute/dynamic_spec.rb
vitalish-factory_girl-1.2.6 spec/factory_girl/attribute/dynamic_spec.rb
lockbox_middleware-1.2.1 vendor/gems/factory_girl-1.2.3/spec/factory_girl/attribute/dynamic_spec.rb
malvestuto_factory_girl-1.2.5 spec/factory_girl/attribute/dynamic_spec.rb
factory_girl-1.2.4 spec/factory_girl/attribute/dynamic_spec.rb
jeffrafter-factory_girl-1.2.3 spec/factory_girl/attribute/dynamic_spec.rb
masa-iwasaki-factory_girl-1.2.3.2 spec/factory_girl/attribute/dynamic_spec.rb
masa-iwasaki-factory_girl-1.2.3.1 spec/factory_girl/attribute/dynamic_spec.rb