Sha256: b7346102ebc7f652f9b3951d0f305bf9e624e1e1c3f11332196725d658fba14f

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require File.instance_eval { expand_path join(dirname(__FILE__), 'test_helper') }
require 'freighthopper'

class ArrayTest < Test::Unit::TestCase
  context 'symbols' do
    should 'map to sym' do
      assert_equal [:a, :b, :c, :d, :e], %w( a b c d e ).symbols
    end
  end
  
  context 'singular' do
    should 'return the singular object if there is indeed only one' do
      assert_singular 5, [5]
    end
    
    should 'return nil if the array is empty' do
      assert_singular nil, []
    end
    
    should 'return nil if the array has > 1 item' do
      assert_singular nil, [1, 2]
    end
  end
  
  context 'singular questionmark' do
    should 'return true if the array has only one member' do
      assert_singular [5]
    end
    
    should 'return false if the array is empty' do
      assert_not_singular []
    end
    
    should 'return false if the array has more than one member' do
      assert_not_singular [1, 2]
    end
  end
  
  context 'singular bang' do
    should 'return the item if there is just one' do
      assert_equal 5, [5].singular!
    end
    
    should 'raise if there are no items' do
      e = assert_raise(RuntimeError){ [].singular! }
      assert_message 'not singular', e
    end

    should 'raise if there are more than one item' do
      e = assert_raise(RuntimeError){ [1, 2].singular! }
      assert_message 'not singular', e
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
freighthopper-0.1.6 test/array_test.rb