Sha256: c6b97a7435f3efb2f1eada5eaeb6ee826da9907694ca8b18d0be2161b61c5738

Contents?: true

Size: 1.52 KB

Versions: 22

Compression:

Stored size: 1.52 KB

Contents

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

class SequenceTest < Test::Unit::TestCase

  context "a sequence" do

    setup do
      @sequence = Factory::Sequence.new {|n| "=#{n}" }
    end

    should "start with a value of 1" do
      assert_equal "=1", @sequence.next
    end

    context "after being called" do

      setup do
        @sequence.next
      end

      should "use the next value" do
        assert_equal "=2", @sequence.next
      end

    end

  end

  context "defining a sequence" do

    setup do
      @sequence = mock('sequence')
      @name     = :count
      Factory::Sequence.stubs(:new).returns(@sequence)
    end

    should "create a new sequence" do
      Factory::Sequence.expects(:new).with().returns(@sequence)
      Factory.sequence(@name)
    end

    should "use the supplied block as the sequence generator" do
      Factory::Sequence.stubs(:new).yields(1)
      yielded = false
      Factory.sequence(@name) {|n| yielded = true }
      assert yielded
    end

  end

  context "after defining a sequence" do

    setup do
      @sequence = mock('sequence')
      @name     = :test
      @value    = '1 2 5'

      @sequence.        stubs(:next).returns(@value)
      Factory::Sequence.stubs(:new). returns(@sequence)

      Factory.sequence(@name) {}
    end

    should "call next on the sequence when sent next" do
      @sequence.expects(:next)

      Factory.next(@name)
    end

    should "return the value from the sequence" do
      assert_equal @value, Factory.next(@name)
    end

  end

end

Version data entries

22 entries across 22 versions & 10 rubygems

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