Sha256: c04eff881d565ade59e9a8e1bbf6300821510a451e25b4d6231a1af00e20e7b7

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module Test
  module Prey
    module Mod; end
    class Base; end
    class Derived < Base
      include Mod
    end
  end
end

describe Scorpion::Prey do
  context "inheritance" do
    let( :prey ){ Scorpion::Prey.new( Test::Prey::Derived ) }

    it "matches more derived class when looking for base class" do
      expect( prey.satisfies? Test::Prey::Base ).to be_truthy
    end

    it "matches same class when looking for base class" do
      expect( prey.satisfies? Test::Prey::Derived ).to be_truthy
    end

    it "does not inherit symbols" do
      expect( Scorpion::Prey.new( :a ).satisfies? :b ).to be_falsy
    end

    it "can satisfy a module with a class" do
      expect( prey.satisfies? Test::Prey::Mod ).to be_truthy
    end

  end

  describe "traits" do

    context "symbolic" do
      let( :prey ){ Scorpion::Prey.new Test::Prey::Base, :apples }
      it "satisfies matched traits" do
        expect( prey.satisfies? Test::Prey::Base, :apples ).to be_truthy
      end

      it "doesn't satisfy mis-matched traits" do
        expect( prey.satisfies? Test::Prey::Base, :oranges ).to be_falsy
      end
    end

    context "module" do
      let( :prey ){ Scorpion::Prey.new Test::Prey::Derived }

      it "satisfies module traits" do
        expect( prey.satisfies? Test::Prey::Base, Test::Prey::Derived ).to be_truthy
      end
    end

  end

  it "can satisfy symbol contracts" do
    expect( Scorpion::Prey.new( :symbol ).satisfies? :symbol ).to be_truthy
  end

  it "satisfies ignores tail hash traits" do
    expect( Scorpion::Prey.new( Test::Prey::Base ).satisfies?( Test::Prey::Base, ) )
  end

  describe "equality" do
    let( :prey )      { Scorpion::Prey.new( Test::Prey::Derived ) }
    let( :same )      { Scorpion::Prey.new( Test::Prey::Derived ) }
    let( :different ) { Scorpion::Prey.new( Test::Prey::Base ) }

    specify{ expect( prey ).to eq same }
    specify{ expect( prey ).not_to eq different }
    specify{ expect( prey.hash ).to eq same.hash }
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
scorpion-ioc-0.3.1 spec/lib/scorpion/prey_spec.rb
scorpion-ioc-0.3.0 spec/lib/scorpion/prey_spec.rb
scorpion-ioc-0.2.0 spec/lib/scorpion/prey_spec.rb
scorpion-ioc-0.1.0 spec/lib/scorpion/prey_spec.rb