spec/handlers/constant_handler_spec.rb in yard-0.9.5 vs spec/handlers/constant_handler_spec.rb in yard-0.9.6
- old
+ new
@@ -1,8 +1,9 @@
+# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'
-describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ConstantHandler" do
+RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ConstantHandler" do
before(:all) { parse_file :constant_handler_001, __FILE__ }
it "does not parse constants inside methods" do
expect(Registry.at("A::B::SOMECONSTANT").source).to eq "SOMECONSTANT= \"hello\""
end
@@ -10,11 +11,11 @@
it "only parses valid constants" do
expect(Registry.at("A::B::notaconstant")).to be nil
end
it "maintains newlines" do
- expect(Registry.at("A::B::MYCONSTANT").value.gsub("\r", "")).to eq "A +\nB +\nC +\nD"
+ expect(Registry.at("A::B::MYCONSTANT").value.delete("\r")).to eq "A +\nB +\nC +\nD"
end
it "turns Const = Struct.new(:sym) into class Const with attr :sym" do
obj = Registry.at("MyClass")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
@@ -71,6 +72,30 @@
#{type} Foo; end
Foo = "value"
eof
end
end unless LEGACY_PARSER
-end
\ No newline at end of file
+
+ it "allows constant to have same name as constant in parent namespace" do
+ YARD.parse_string <<-eof
+ module A
+ class C; end
+ module B; C = 1 end
+ end
+ eof
+ expect(log.io.string).to eq ""
+ expect(Registry.at('A::B::C').type).to eq :constant
+ end
+
+ it "detects compound constant names" do
+ YARD.parse_string <<-eof
+ module A
+ class AA; end
+ AA::B = true
+ end
+ A::AA::C = true
+ eof
+
+ expect(Registry.at('A::AA::B').type).to eq :constant
+ expect(Registry.at('A::AA::C').type).to eq :constant
+ end if HAVE_RIPPER
+end