Sha256: f9881382895a2a43af57a1040f6e65b9745ea04371fcc957a060e7d39f81150a

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

require 'test_helper'
require 'tins/xt/deep_const_get'

module Tins
  class DeepConstGetTest < Test::Unit::TestCase
    module A
      module B
      end
    end

    module C
      module NotB
      end

      def self.const_missing(c)
        NotB
      end
    end

    def test_deep_const_get_with_start_module
      assert_raise(ArgumentError) { deep_const_get '::B', A }
      assert_equal A::B, deep_const_get('B', A)
    end

    def test_deep_const_get_without_start_module
      assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('::Tins::DeepConstGetTest::A::B')
      assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('Tins::DeepConstGetTest::A::B')
      assert_equal Array, deep_const_get('::Array')
      assert_equal Array, deep_const_get('Array')
    end

    def test_deep_const_get_with_const_missing
      assert_raise(ArgumentError) { deep_const_get '::Tins::DeepConstGetTest::A::NIXDA' }
      assert_equal Tins::DeepConstGetTest::C::NotB, deep_const_get('::Tins::DeepConstGetTest::C::B')
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tins-1.37.0 tests/deep_const_get_test.rb
tins-1.36.1 tests/deep_const_get_test.rb
tins-1.36.0 tests/deep_const_get_test.rb
tins-1.35.0 tests/deep_const_get_test.rb
tins-1.34.0 tests/deep_const_get_test.rb
tins-1.33.0 tests/deep_const_get_test.rb
tins-1.32.1 tests/deep_const_get_test.rb
tins-1.32.0 tests/deep_const_get_test.rb