Sha256: b56b0b09b1fbf0e4c70121798bcec280dde3cf1b26ef799d71342d713eef0d5e

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

class SequenceTest < Test::Unit::TestCase
  
  def setup
    Machine.sequences.clear
  end

  should 'allow definition of sequences' do
    Machine.sequence :thing do
    end
    assert_equal 1, Machine.sequences.size
  end
  
  should 'increment the sequence value' do
    Machine.sequence :thing do |n|
      n
    end
    assert_equal 1, Machine.sequences[:thing].next
    assert_equal 2, Machine.sequences[:thing].next
  end
  
  should 'be able to output strings' do
    Machine.sequence :thing do |n|
      "article-#{n}"
    end
    assert_equal 'article-1', Machine.sequences[:thing].next
    assert_equal 'article-2', Machine.sequences[:thing].next
  end  
  
  should 'be callable through the machine' do
    Machine.sequence :thing do |n|
      "article-#{n}"
    end
    assert_equal 'article-1', Machine.next(:thing)
  end
  
  should 'raise an exception when calling a nonexistent sequence' do
    assert_raises MachineNotFoundError do
      Machine.next(:who)
    end
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aub-machine-1.0.2 test/sequence_test.rb
aub-machine-1.0.3 test/sequence_test.rb