Sha256: 7642c8333d26feded49e2f38700bee7d7f4705afbe598c2f5c499346bd4e1b29

Contents?: true

Size: 1.57 KB

Versions: 21

Compression:

Stored size: 1.57 KB

Contents

require(File.join(File.dirname(__FILE__), 'test_helper'))

class AttributeTest < Test::Unit::TestCase

  def setup
    @proxy = mock('attribute-proxy')
  end

  context "an attribute" do

    setup do
      @name  = :user
      @attr  = Factory::Attribute.new(@name, 'test', nil)
    end

    should "have a name" do
      assert_equal @name, @attr.name
    end

  end

  context "an attribute with a static value" do

    setup do
      @value = 'test'
      @attr  = Factory::Attribute.new(:user, @value, nil)
    end

    should "return the value" do
      assert_equal @value, @attr.value(@proxy)
    end

  end

  context "an attribute with a lazy value" do

    setup do
      @block = lambda { 'value' }
      @attr  = Factory::Attribute.new(:user, nil, @block)
    end

    should "call the block to return a value" do
      assert_equal 'value', @attr.value(@proxy)
    end

    should "yield the attribute proxy to the block" do
      @block = lambda {|a| a }
      @attr  = Factory::Attribute.new(:user, nil, @block)
      assert_equal @proxy, @attr.value(@proxy)
    end

  end

  should "raise an error when defining an attribute writer" do
    assert_raise Factory::AttributeDefinitionError do
      Factory::Attribute.new('test=', nil, nil)
    end
  end

  should "not allow attributes to be added with both a value parameter and a block" do
    assert_raise(Factory::AttributeDefinitionError) do
      Factory::Attribute.new(:name, 'value', lambda {})
    end
  end

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

end

Version data entries

21 entries across 21 versions & 9 rubygems

Version Path
dima-exe-factory_girl-1.1.5.0 test/attribute_test.rb
dima-exe-factory_girl-1.1.5.1 test/attribute_test.rb
gabrielg-factory_girl-1.1.6 test/attribute_test.rb
gabrielg-factory_girl-1.1.7 test/attribute_test.rb
gabrielg-factory_girl-1.1.8 test/attribute_test.rb
gabrielg-factory_girl-1.1.9 test/attribute_test.rb
gabrielg-factory_girl-1.2.0 test/attribute_test.rb
gabrielg-factory_girl-1.2.1 test/attribute_test.rb
gabrielg-factory_girl-1.2.2 test/attribute_test.rb
gsterndale-warrant-0.2.0 test/rails_root/vendor/gems/thoughtbot-factory_girl-1.1.5/test/attribute_test.rb
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/thoughtbot-factory_girl-1.1.5/test/attribute_test.rb
handcrafted-factory_girl-1.1.14 test/attribute_test.rb
jrun-factory_girl-1.1.3.9999 test/attribute_test.rb
multiplay-factory_girl-1.1.5 test/attribute_test.rb
thoughtbot-factory_girl-1.1.3 test/attribute_test.rb
thoughtbot-factory_girl-1.1.4 test/attribute_test.rb
thoughtbot-factory_girl-1.1.5 test/attribute_test.rb
threedaymonk-factory_girl-1.1.4 test/attribute_test.rb
factory_girl-1.1.3 test/attribute_test.rb
factory_girl-1.1.4 test/attribute_test.rb