Sha256: c7e0ba403d13102f067c5e32d83f688a2976c9b7a50bd31b4b186b741410fdb7

Contents?: true

Size: 842 Bytes

Versions: 25

Compression:

Stored size: 842 Bytes

Contents

require 'test_helper'

class ConstantEnumTest < ActiveSupport::TestCase
  
  class MyEnum < ::Incline::ConstantEnum
    
    ALPHA = 1
    BRAVO = 2
    CHARLIE = 3
    DELTA = 4
    
  end
  
  test 'should allow initialization' do
    item = MyEnum.new(2)
    assert item
    assert_equal 2, item.value
    assert_equal 'BRAVO', item.name
    assert_equal item.name, item.to_s
  end
  
  test 'should not allow invalid values' do
    assert_raises ArgumentError do
      MyEnum.new(0)
    end
    assert_raises ArgumentError do
      MyEnum.new(5)
    end
  end
  
  test 'should be able to identify named values' do
    assert MyEnum.named?(3)
    assert_not MyEnum.named?(42)
  end
  
  test 'should always return a non-nil name' do
    assert_equal 'DELTA', MyEnum.name_for(4)
    assert_equal '', MyEnum.name_for(100)
  end
  
  
  
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
incline-0.3.14 test/lib/constant_enum_test.rb
incline-0.3.13 test/lib/constant_enum_test.rb
incline-0.3.12 test/lib/constant_enum_test.rb
incline-0.3.11 test/lib/constant_enum_test.rb
incline-0.3.10 test/lib/constant_enum_test.rb
incline-0.3.9 test/lib/constant_enum_test.rb
incline-0.3.8 test/lib/constant_enum_test.rb
incline-0.3.7 test/lib/constant_enum_test.rb
incline-0.3.6 test/lib/constant_enum_test.rb
incline-0.3.5 test/lib/constant_enum_test.rb
incline-0.3.4 test/lib/constant_enum_test.rb
incline-0.3.3 test/lib/constant_enum_test.rb
incline-0.3.2 test/lib/constant_enum_test.rb
incline-0.3.1 test/lib/constant_enum_test.rb
incline-0.3.0 test/lib/constant_enum_test.rb
incline-0.2.36 test/lib/constant_enum_test.rb
incline-0.2.35 test/lib/constant_enum_test.rb
incline-0.2.34 test/lib/constant_enum_test.rb
incline-0.2.28 test/lib/constant_enum_test.rb
incline-0.2.27 test/lib/constant_enum_test.rb