Sha256: bd30de2e694c90b2a433bf8c006fef2f15f8d611e813fadb43d4cb4a1d063ef8

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

module DescendantsTrackerSpec
  class Parent
    extend MotionSupport::DescendantsTracker
  end

  class Child1 < Parent
  end

  class Child2 < Parent
  end

  class Grandchild1 < Child1
  end

  class Grandchild2 < Child1
  end

  ALL = [Parent, Child1, Child2, Grandchild1, Grandchild2]
end

describe "DescendantsTracker" do
  describe "descendants" do
    it "should get all descendants from parent class" do
      [DescendantsTrackerSpec::Child1, DescendantsTrackerSpec::Child2, DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Parent.descendants
    end
    
    it "should get descendants from subclass" do
      [DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Child1.descendants
    end
    
    it "should return empty array for leaf class" do
      [].should == DescendantsTrackerSpec::Child2.descendants
    end
  end

  describe "direct_descendants" do
    it "should get direct descendants from parent class" do
      [DescendantsTrackerSpec::Child1, DescendantsTrackerSpec::Child2].should == DescendantsTrackerSpec::Parent.direct_descendants
    end
    
    it "should get direct descendants from subclass" do
      [DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Child1.direct_descendants
    end
    
    it "should return empty array for leaf class" do
      [].should == DescendantsTrackerSpec::Child2.direct_descendants
    end
  end

  describe "clear" do
    it "should remove all tracked descendants" do
      MotionSupport::DescendantsTracker.clear
      DescendantsTrackerSpec::ALL.each do |k|
        MotionSupport::DescendantsTracker.descendants(k).should.be.empty
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
motion-support-1.2.1 spec/motion-support/descendants_tracker_spec.rb
motion-support-1.1.1 spec/motion-support/descendants_tracker_spec.rb
motion-support-1.2.0 spec/motion-support/descendants_tracker_spec.rb