Sha256: 1097cb272ff8681e673d3eef8a21a5310225906fee1a7fd293ff74c222512f75

Contents?: true

Size: 1.59 KB

Versions: 34

Compression:

Stored size: 1.59 KB

Contents

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

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

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

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

class MockIndifferentRole < ::Inch::Evaluation::Role
  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 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

34 entries across 34 versions & 1 rubygems

Version Path
inch-0.5.7 test/unit/evaluation/role_test.rb
inch-0.5.6 test/unit/evaluation/role_test.rb
inch-0.5.5 test/unit/evaluation/role_test.rb
inch-0.5.4 test/unit/evaluation/role_test.rb
inch-0.5.3 test/unit/evaluation/role_test.rb
inch-0.5.2 test/unit/evaluation/role_test.rb
inch-0.5.1 test/unit/evaluation/role_test.rb
inch-0.5.0 test/unit/evaluation/role_test.rb
inch-0.5.0.rc11 test/unit/evaluation/role_test.rb
inch-0.5.0.rc10 test/unit/evaluation/role_test.rb
inch-0.5.0.rc9 test/unit/evaluation/role_test.rb
inch-0.5.0.rc8 test/unit/evaluation/role_test.rb
inch-0.5.0.rc7 test/unit/evaluation/role_test.rb
inch-0.5.0.rc6 test/unit/evaluation/role_test.rb