Loading spec/aggregator_spec.rb +76 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,82 @@ describe JsDuck::Aggregator do end end shared_examples_for "event documentation" do it "creates event" do @doc[:tagname].should == :event end it "takes documentation from doc-comment" do @doc[:doc].should == "Fires when needed." end it "detects event name" do @doc[:name].should == "mousedown" end end describe "explicit event with name and @params" do before do @doc = parse(<<-EOS)[0] /** * @event mousedown * Fires when needed. * @param {String} x First parameter * @param {Number} y Second parameter */ EOS end it_should_behave_like "event documentation" it_should_behave_like "two parameters" it_should_behave_like "parameter types" it_should_behave_like "parameter docs" end describe "event with @event after @params" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. * @param {String} x First parameter * @param {Number} y Second parameter * @event mousedown */ EOS end it_should_behave_like "event documentation" it_should_behave_like "two parameters" it_should_behave_like "parameter types" it_should_behave_like "parameter docs" end describe "implicit event name as string" do before do @doc = parse(<<-EOS)[0] /** * @event * Fires when needed. */ "mousedown" EOS end it_should_behave_like "event documentation" it_should_behave_like "no parameters" end describe "implicit event name as object property" do before do @doc = parse(<<-EOS)[0] /** * @event * Fires when needed. */ mousedown: true, EOS end it_should_behave_like "event documentation" it_should_behave_like "no parameters" end describe "@member" do it "defines the class where item belongs" do Loading test/tc_jsduck.rb +0 −39 Original line number Diff line number Diff line Loading @@ -3,45 +3,6 @@ require "test/unit" class TestJsDuck < Test::Unit::TestCase def test_event docs = JsDuck.parse("/** * @event mousedown * Fires when the mouse button is depressed. * @param {String} foo Comment 1 * @param {Number} bar Comment 2 */") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) assert_equal("Fires when the mouse button is depressed.", docs[0][:doc]) params = docs[0][:params] assert_equal("foo", params[0][:name]) assert_equal("String", params[0][:type]) assert_equal("Comment 1", params[0][:doc]) assert_equal("bar", params[1][:name]) assert_equal("Number", params[1][:type]) assert_equal("Comment 2", params[1][:doc]) end def test_implicit_event_name_as_string docs = JsDuck.parse("/** * @event */ 'mousedown', ") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) end def test_implicit_event_name_as_property docs = JsDuck.parse("/** * @event */ mousedown: true, ") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) end def test_explicit_class docs = JsDuck.parse("/** * @class My.nice.Class Loading Loading
spec/aggregator_spec.rb +76 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,82 @@ describe JsDuck::Aggregator do end end shared_examples_for "event documentation" do it "creates event" do @doc[:tagname].should == :event end it "takes documentation from doc-comment" do @doc[:doc].should == "Fires when needed." end it "detects event name" do @doc[:name].should == "mousedown" end end describe "explicit event with name and @params" do before do @doc = parse(<<-EOS)[0] /** * @event mousedown * Fires when needed. * @param {String} x First parameter * @param {Number} y Second parameter */ EOS end it_should_behave_like "event documentation" it_should_behave_like "two parameters" it_should_behave_like "parameter types" it_should_behave_like "parameter docs" end describe "event with @event after @params" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. * @param {String} x First parameter * @param {Number} y Second parameter * @event mousedown */ EOS end it_should_behave_like "event documentation" it_should_behave_like "two parameters" it_should_behave_like "parameter types" it_should_behave_like "parameter docs" end describe "implicit event name as string" do before do @doc = parse(<<-EOS)[0] /** * @event * Fires when needed. */ "mousedown" EOS end it_should_behave_like "event documentation" it_should_behave_like "no parameters" end describe "implicit event name as object property" do before do @doc = parse(<<-EOS)[0] /** * @event * Fires when needed. */ mousedown: true, EOS end it_should_behave_like "event documentation" it_should_behave_like "no parameters" end describe "@member" do it "defines the class where item belongs" do Loading
test/tc_jsduck.rb +0 −39 Original line number Diff line number Diff line Loading @@ -3,45 +3,6 @@ require "test/unit" class TestJsDuck < Test::Unit::TestCase def test_event docs = JsDuck.parse("/** * @event mousedown * Fires when the mouse button is depressed. * @param {String} foo Comment 1 * @param {Number} bar Comment 2 */") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) assert_equal("Fires when the mouse button is depressed.", docs[0][:doc]) params = docs[0][:params] assert_equal("foo", params[0][:name]) assert_equal("String", params[0][:type]) assert_equal("Comment 1", params[0][:doc]) assert_equal("bar", params[1][:name]) assert_equal("Number", params[1][:type]) assert_equal("Comment 2", params[1][:doc]) end def test_implicit_event_name_as_string docs = JsDuck.parse("/** * @event */ 'mousedown', ") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) end def test_implicit_event_name_as_property docs = JsDuck.parse("/** * @event */ mousedown: true, ") assert_equal(:event, docs[0][:tagname]) assert_equal("mousedown", docs[0][:name]) end def test_explicit_class docs = JsDuck.parse("/** * @class My.nice.Class Loading