Sha256: a2fcf6f1a8cfc76ce6a5ab6e441208922904c810b796a2ca4f5b1a090ece7e43

Contents?: true

Size: 999 Bytes

Versions: 2

Compression:

Stored size: 999 Bytes

Contents

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

class SequenceTest < Test::Unit::TestCase
  
  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.0 test/sequence_test.rb
aub-machine-1.0.1 test/sequence_test.rb