Sha256: 9cf09b51950b3f1cb789831eb865c284a8e98b4b4de307ed389611af1985e103

Contents?: true

Size: 1.62 KB

Versions: 36

Compression:

Stored size: 1.62 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')

class MockPrivateRole < ::Inch::Evaluation::Role::Base
  applicable_if :private?
end

class MockNotPrivateRole < ::Inch::Evaluation::Role::Base
  applicable_unless :private?
end

class MockPublicRole < ::Inch::Evaluation::Role::Base
  applicable_if { |o| o.public? }
end

class MockIndifferentRole < ::Inch::Evaluation::Role::Base
  def self.applicable?(object)
    true
  end
end

class MockPrivateObject
  def private?
    true
  end

  def public?
    false
  end
end

class MockPublicObject
  def private?
    false
  end

  def public?
    true
  end
end

describe ::Inch::Evaluation::Role::Base do
  describe ".applicable" do
    let(:private_object) { MockPrivateObject.new }
    let(:public_object) { MockPublicObject.new }

    describe ".applicable_if" do
      it "should work with a symbol" do
        assert MockPrivateRole.applicable?(private_object)
        assert !MockPrivateRole.applicable?(public_object)
      end

      it "should work with a block" do
        assert MockPublicRole.applicable?(public_object)
        assert MockNotPrivateRole.applicable?(public_object)
        assert !MockPublicRole.applicable?(private_object)
      end
    end

    describe ".applicable_unless" do
      it "should work with a block" do
        assert MockNotPrivateRole.applicable?(public_object)
        assert !MockNotPrivateRole.applicable?(private_object)
      end
    end

    it "should work by implementing a class method" do
      assert MockIndifferentRole.applicable?(private_object)
      assert MockIndifferentRole.applicable?(public_object)
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
inch-0.5.0.rc3 test/unit/evaluation/role/base_test.rb
inch-0.5.0.rc2 test/unit/evaluation/role/base_test.rb
inch-0.5.0.rc1 test/unit/evaluation/role/base_test.rb
inch-0.4.6 test/unit/evaluation/role/base_test.rb
inch-0.4.5 test/unit/evaluation/role/base_test.rb
inch-0.4.4 test/unit/evaluation/role/base_test.rb
inch-0.4.4.rc4 test/unit/evaluation/role/base_test.rb
inch-0.4.4.rc3 test/unit/evaluation/role/base_test.rb
inch-0.4.4.rc2 test/unit/evaluation/role/base_test.rb
inch-0.4.4.rc1 test/unit/evaluation/role/base_test.rb
inch-0.4.3 test/unit/evaluation/role/base_test.rb
inch-0.4.3.rc2 test/unit/evaluation/role/base_test.rb
inch-0.4.3.rc1 test/unit/evaluation/role/base_test.rb
inch-0.4.2 test/unit/evaluation/role/base_test.rb
inch-0.4.1 test/unit/evaluation/role/base_test.rb
inch-0.4.0 test/unit/evaluation/role/base_test.rb
inch-0.4.0.rc3 test/unit/evaluation/role/base_test.rb
inch-0.4.0.rc2 test/unit/evaluation/role/base_test.rb
inch-0.4.0.rc1 test/unit/evaluation/role/base_test.rb
inch-0.3.4.rc1 test/unit/evaluation/role/base_test.rb