Class CoreEx::Module::TestMixInWithArgs
In: lib/core_ex/module/mix_in_with_args.rb
Parent: ::Test::Unit::TestCase

Methods

Included Modules

Mocks::Assertions MixInWithArgs::Assertions

Classes and Modules

Module CoreEx::Module::TestMixInWithArgs::Cleanable
Module CoreEx::Module::TestMixInWithArgs::SetupFixedArgs
Module CoreEx::Module::TestMixInWithArgs::SetupWithoutArgs
Module CoreEx::Module::TestMixInWithArgs::Taggable
Module CoreEx::Module::TestMixInWithArgs::WithClassMethods
Class CoreEx::Module::TestMixInWithArgs::WithTag

Constants

MOCK_OBJECT = Mocks::Object.new

Public Instance methods

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 162
        def setup
          @module = Class.new
          @mock_object = MOCK_OBJECT
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 167
        def teardown
          @mock_object.mock_clear
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 245
        def test_already_tagged
          @module = WithTag
          assert_nothing_raised { @module.new.tag }
          assert_mixin Taggable
          assert_nothing_raised { @module.new.tag }
          assert_mock_calls [[:old_tag], [:setup],
                             [:tag_defined, true],
                             [:tag_defined, false],
                             [:self_is=, @module],
                             [:teardown],
                             [:tag_defined, true],
                             [:tag]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 171
        def test_cleanable
          assert_mixin Cleanable
          assert_empty_mock
          assert_nothing_raised { @module.new.clean(:foo, 42) }
          assert_mock_calls [[:clean, [:foo, 42]]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 196
        def test_setup_fixed_args
          assert_mixin SetupFixedArgs, [1, 2, 3]
          assert_nothing_raised { @module.new }
          assert_mock_calls [[:setup, [1, 2, 3]], [:self_is=, @module]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 190
        def test_setup_without_args
          assert_mixin SetupWithoutArgs
          assert_nothing_raised { @module.new }
          assert_mock_calls [[:self_is=, @module]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 178
        def test_taggable
          assert_mixin Taggable, [:foo => :bar]
          assert_nothing_raised { @module.new.tag(:foo, 42) }
          assert_mock_calls [[:setup, {:foo => :bar}],
                             [:tag_defined, false],
                             [:tag_defined, false],
                             [:self_is=, @module],
                             [:teardown, {:foo => :bar}],
                             [:tag_defined, true],
                             [:tag, [:foo, 42]]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 235
        def test_with_class_methods
          assert_mixin WithClassMethods
          assert_nothing_raised do
            @object = @module.new
            @object.i
            @module.m
          end
          assert_mock_calls [[:setup, @module], [:i, @object], [:m, @module]]
        end

[Source]

# File lib/core_ex/module/mix_in_with_args.rb, line 202
        def test_with_include
          m = ::Module.new
          m.module_eval "
            class A
              include Taggable
            end
            class B
              include Cleanable
            end
            class C
              mixin SetupFixedArgs, 1, 2, 3
              include SetupWithoutArgs
            end
          "
          assert_nothing_raised do
            @a, @b, @c = m::A.new, m::B.new, m::C.new
            @a.tag
            @b.clean
          end
          assert_mock_calls [
            [:setup],
            [:tag_defined, false],
            [:tag_defined, false],
            [:self_is=, m::A],
            [:teardown],
            [:tag_defined, true],
            [:setup, [1, 2, 3]],
            [:self_is=, m::C],
            [:self_is=, m::C],
            [:tag], [:clean]
          ]
        end

[Validate]