Sha256: d0539173f085da12b987d1f9d0f8187dcc80fafe9f8dcc8ca5277c5d93816d68

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

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

class ArrayTest < Test::Unit::TestCase
  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

8 entries across 8 versions & 2 rubygems

Version Path
freighthopper-0.1.5 test/array_test.rb
freighthopper-0.1.4 test/array_test.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/freighthopper-0.1.2/test/array_test.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/freighthopper-0.1.2/test/array_test.rb
freighthopper-0.1.3 test/array_test.rb
freighthopper-0.1.2 test/array_test.rb
freighthopper-0.1.1 test/array_test.rb
freighthopper-0.1.0 test/array_test.rb