Commit ed4fe0c0 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Refactor class spec.

parent 91e52870
Loading
Loading
Loading
Loading
+78 −124
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ require "jsduck/class"

describe JsDuck::Class do

  describe "#members_hash" do
  describe "#members" do

    before do
      @classes = {}
@@ -12,8 +12,15 @@ describe JsDuck::Class do
            :method => [
              {:name => "baz", :owner => "ParentClass"},
              {:name => "foo", :owner => "ParentClass"},
              {:name => "constructor", :owner => "ParentClass"},
              {:name => "frank", :owner => "ParentClass", :private => true},
            ]
          },
          :statics => {
            :method => [
              {:name => "parentA", :owner => "ParentClass"},
              {:name => "parentB", :owner => "ParentClass", :inheritable => true},
            ]
          }
        });
      @classes["ParentClass"] = @parent
@@ -26,6 +33,12 @@ describe JsDuck::Class do
              {:name => "xxx", :owner => "MixinClass"},
              {:name => "pri", :owner => "MixinClass", :private => true},
            ]
          },
          :statics => {
            :method => [
              {:name => "mixinA", :owner => "MixinClass"},
              {:name => "mixinB", :owner => "MixinClass", :inheritable => true},
            ]
          }
        });
      @classes["MixinClass"] = @mixin
@@ -41,11 +54,25 @@ describe JsDuck::Class do
              {:name => "bar", :owner => "ChildClass"},
              {:name => "zappa", :owner => "ChildClass", :private => true},
            ]
          },
          :statics => {
            :method => [
              {:name => "childA", :owner => "ChildClass"},
              {:name => "childB", :owner => "ChildClass", :inheritable => true},
            ]
          }
        });
      @classes["ChildClass"] = @child
      @child.relations = @classes
    end

    it "returns constructor as first method" do
      @members = @child.members(:method)
      @members.first[:name].should == "constructor"
    end

    describe "(:method)" do
      before do
        @members = @child.members_hash(:method)
      end

@@ -88,48 +115,8 @@ describe JsDuck::Class do
      end
    end

  describe "#members(:statics)" do

    describe "(:method, :statics)" do
      before do
      @classes = {}
      @parent = JsDuck::Class.new({
          :name => "ParentClass",
          :statics => {
            :method => [
              {:name => "parentA", :owner => "ParentClass"},
              {:name => "parentB", :owner => "ParentClass", :inheritable => true},
            ]
          }
        });
      @classes["ParentClass"] = @parent
      @parent.relations = @classes

      @mixin = JsDuck::Class.new({
          :name => "MixinClass",
          :statics => {
            :method => [
              {:name => "mixinA", :owner => "MixinClass"},
              {:name => "mixinB", :owner => "MixinClass", :inheritable => true},
            ]
          }
        });
      @classes["MixinClass"] = @mixin
      @mixin.relations = @classes

      @child = JsDuck::Class.new({
          :name => "ChildClass",
          :extends => "ParentClass",
          :mixins => ["MixinClass"],
          :statics => {
            :method => [
              {:name => "childA", :owner => "ChildClass"},
              {:name => "childB", :owner => "ChildClass", :inheritable => true},
            ]
          }
        });
      @classes["ChildClass"] = @child
      @child.relations = @classes

        @members = @child.members_hash(:method, :statics)
      end

@@ -156,39 +143,6 @@ describe JsDuck::Class do
      it "inherits inheritableStatics from mixins" do
        @members.should have_key("mixinB")
      end

  end

  describe "#members(:method)" do
    before do
      @classes = {}
      @parent = JsDuck::Class.new({
          :name => "ParentClass",
          :members => {
            :method => [
              {:name => "baz", :owner => "ParentClass"},
              {:name => "constructor", :owner => "ParentClass"},
            ]
          }
        });
      @classes["ParentClass"] = @parent
      @parent.relations = @classes
      @child = JsDuck::Class.new({
          :name => "ChildClass",
          :extends => "ParentClass",
          :members => {
            :method => [
              {:name => "foo", :owner => "ChildClass"}
            ]
          }
        });
      @classes["ChildClass"] = @child
      @child.relations = @classes
    end

    it "returns constructor as first method" do
      ms = @child.members(:method)
      ms.first[:name].should == "constructor"
    end
  end