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

Move constructor tests to separate file.

parent b6f9bd71
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
@@ -318,34 +318,6 @@ describe JsDuck::Aggregator do
    it_should_behave_like "class"
  end

  describe "class with constructor" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * Comment here.
         * @constructor
         * This constructs the class
         * @param {Number} nr
         */
      EOS
    end

    it_should_behave_like "class"
    it "has one method" do
      @doc[:members][:method].length.should == 1
    end
    it "has method with name 'constructor'" do
      @doc[:members][:method][0][:name].should == "constructor"
    end
    it "has method with needed parameters" do
      @doc[:members][:method][0][:params].length.should == 1
    end
    it "has method with default return type Object" do
      @doc[:members][:method][0][:return][:type].should == "Object"
    end
  end

  describe "member docs after class doc" do
    before do
      @classes = parse(<<-EOS)
+64 −0
Original line number Diff line number Diff line
require "jsduck/aggregator"
require "jsduck/source_file"

describe JsDuck::Aggregator do
  def parse(string)
    agr = JsDuck::Aggregator.new
    agr.aggregate(JsDuck::SourceFile.new(string))
    agr.result
  end

  shared_examples_for "constructor" do
    it "has one method" do
      methods.length.should == 1
    end

    it "has method with name 'constructor'" do
      methods[0][:name].should == "constructor"
    end

    it "has method with needed parameters" do
      methods[0][:params].length.should == 1
    end

    it "has method with default return type Object" do
      methods[0][:return][:type].should == "Object"
    end
  end

  describe "class with @constructor" do
    let(:methods) do
      parse(<<-EOS)[0][:members][:method]
        /**
         * @class MyClass
         * Comment here.
         * @constructor
         * This constructs the class
         * @param {Number} nr
         */
      EOS
    end

    it_should_behave_like "constructor"
  end

  describe "class with method named constructor" do
    let(:methods) do
      parse(<<-EOS)[0][:members][:method]
        /**
         * Comment here.
         */
        MyClass = {
            /**
             * @method constructor
             * This constructs the class
             * @param {Number} nr
             */
        };
      EOS
    end

    it_should_behave_like "constructor"
  end

end