Sha256: 91bed615166e0d9f07f910d11ceff8c0ae92ed67ef1b5870b59ee6f126c3ec9c

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ConstantHandler" do
  before(:all) { parse_file :constant_handler_001, __FILE__ }
  
  it "should not parse constants inside methods" do
    Registry.at("A::B::SOMECONSTANT").source.should == "SOMECONSTANT= \"hello\""
  end
  
  it "should only parse valid constants" do
    Registry.at("A::B::notaconstant").should be_nil
  end
  
  it "should maintain newlines" do
    Registry.at("A::B::MYCONSTANT").value.should == "A +\nB +\nC +\nD"
  end
  
  it "should turn Const = Struct.new(:sym) into class Const with attr :sym" do
    obj = Registry.at("MyClass")
    obj.should be_kind_of(CodeObjects::ClassObject)
    attrs = obj.attributes[:instance]
    [:a, :b, :c].each do |key|
      attrs.should have_key(key)
      attrs[key][:read].should_not be_nil
      attrs[key][:write].should_not be_nil
    end
  end

  it "should turn Const = Struct.new('Name', :sym) into class Const with attr :sym" do
    obj = Registry.at("NotMyClass")
    obj.should be_kind_of(CodeObjects::ClassObject)
    attrs = obj.attributes[:instance]
    [:b, :c].each do |key|
      attrs.should have_key(key)
      attrs[key][:read].should_not be_nil
      attrs[key][:write].should_not be_nil
    end

    Registry.at("NotMyClass2").should be_nil
  end
  
  it "should turn Const = Struct.new into empty struct" do
    obj = Registry.at("MyEmptyStruct")
    obj.should_not be_nil
    obj.attributes[:instance].should be_empty
  end
  
  it "should raise undocumentable error in 1.9 parser for Struct.new assignment to non-const" do
    undoc_error "nonconst = Struct.new"
  end if RUBY19
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
yard-0.6.1 spec/handlers/constant_handler_spec.rb
yard-0.6.0 spec/handlers/constant_handler_spec.rb
yard-0.5.8 spec/handlers/constant_handler_spec.rb
yard-0.5.7 spec/handlers/constant_handler_spec.rb
yard-0.5.6 spec/handlers/constant_handler_spec.rb
yard-0.5.5 spec/handlers/constant_handler_spec.rb
yard-0.5.4 spec/handlers/constant_handler_spec.rb
yard-0.5.3 spec/handlers/constant_handler_spec.rb
yard-0.5.2 spec/handlers/constant_handler_spec.rb
yard-0.5.1p1 spec/handlers/constant_handler_spec.rb
yard-0.5.1 spec/handlers/constant_handler_spec.rb
yard-0.5.0 spec/handlers/constant_handler_spec.rb
yard-0.4.0 spec/handlers/constant_handler_spec.rb