Sha256: bd1ed03be4c4b52ac4b8e9f7b14b554b2bc3d7013d86d43b195c67779a586926

Contents?: true

Size: 1.61 KB

Versions: 110

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'
require 'tins'

module Tins
  class ImplementTest < Test::Unit::TestCase
    require 'tins/xt/implement'

    class A
      implement :foo

      implement :bar, in: :subclass

      implement :baz, in: :submodule

      implement :qux, 'blub %{method_name} blob %{module}'

      implement :quux, 'blab'

      implement def foobar(arg1, arg2: :baz)
      end, in: :subclass
    end

    def test_implement_default
      assert_equal(
        'method foo not implemented in module Tins::ImplementTest::A',
        error_message { A.new.foo }
      )
    end

    def test_implement_subclass
      assert_equal(
        'method bar has to be implemented in subclasses of '\
        'Tins::ImplementTest::A',
        error_message { A.new.bar }
      )
    end

    def test_implement_submodule
      assert_equal(
        'method baz has to be implemented in submodules of '\
        'Tins::ImplementTest::A',
        error_message { A.new.baz }
      )
    end

    def test_implement_custom_with_vars
      assert_equal(
        'blub qux blob Tins::ImplementTest::A',
        error_message { A.new.qux }
      )
    end

    def test_implement_custom_without_vars
      assert_equal('blab', error_message { A.new.quux })
    end

    if RUBY_VERSION >= "2.1"
      def test_implement_def_subclass
        assert_equal(
          'method foobar(arg1,arg2:?) has to be '\
          'implemented in subclasses of Tins::ImplementTest::A',
          error_message { A.new.foobar }
        )
      end
    end

    private

    def error_message
      yield
    rescue NotImplementedError => e
      e.message
    end
  end
end

Version data entries

110 entries across 96 versions & 8 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/implement_test.rb
tins-1.29.1 tests/implement_test.rb
tins-1.29.0 tests/implement_test.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/tests/implement_test.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tins-1.26.0/tests/implement_test.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/tests/implement_test.rb
tins-1.28.0 tests/implement_test.rb
tins-1.27.1 tests/implement_test.rb
tins-1.27.0 tests/implement_test.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/tins-1.26.0/tests/implement_test.rb
tins-1.26.0 tests/implement_test.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/tins-1.25.0/tests/implement_test.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/tins-1.25.0/tests/implement_test.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/tins-1.25.0/tests/implement_test.rb
tins-1.25.0 tests/implement_test.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/tins-1.24.1/tests/implement_test.rb
tins-1.24.1 tests/implement_test.rb
tins-1.24.0 tests/implement_test.rb
tins-1.23.0 tests/implement_test.rb
tdiary-5.1.0 vendor/bundle/gems/tins-1.22.2/tests/implement_test.rb