diff --git a/lib/yard/handlers/ruby/mixin_handler.rb b/lib/yard/handlers/ruby/mixin_handler.rb index c7edc0070..b01b99458 100644 --- a/lib/yard/handlers/ruby/mixin_handler.rb +++ b/lib/yard/handlers/ruby/mixin_handler.rb @@ -34,7 +34,10 @@ def process_mixin(mixin) end rec = recipient(mixin) - return if rec.nil? || rec.mixins(scope).include?(obj) + return if rec.nil? + + ensure_loaded!(rec) + return if rec.mixins(scope).include?(obj) shift = statement.method_name(true) == :include ? :unshift : :push rec.mixins(scope).send(shift, obj) diff --git a/spec/handlers/examples/mixin_handler_002.rb.txt b/spec/handlers/examples/mixin_handler_002.rb.txt new file mode 100644 index 000000000..72b10cc4f --- /dev/null +++ b/spec/handlers/examples/mixin_handler_002.rb.txt @@ -0,0 +1,3 @@ +module B1; end + +A1.include(B1) diff --git a/spec/handlers/examples/mixin_handler_003.rb.txt b/spec/handlers/examples/mixin_handler_003.rb.txt new file mode 100644 index 000000000..68f69ec52 --- /dev/null +++ b/spec/handlers/examples/mixin_handler_003.rb.txt @@ -0,0 +1 @@ +module A1; end \ No newline at end of file diff --git a/spec/handlers/mixin_handler_spec.rb b/spec/handlers/mixin_handler_spec.rb index 8d38f1460..f84faf63f 100644 --- a/spec/handlers/mixin_handler_spec.rb +++ b/spec/handlers/mixin_handler_spec.rb @@ -62,11 +62,18 @@ it "can mixin a const by complex path" do YARD.parse_string <<-eof class A1; class B1; class C1; end end end - class D1; class E1; class F1; end end end + class D1; class E1; module F1; end end end A1::B1::C1.include D1::E1::F1 eof expect(YARD::Registry.root.instance_mixins).not_to eq [P('D1::E1::F1')] expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')] end + + it "ensures the recipient is loaded from another file" do + # 002 includes a module into a module defined in 003 + parse_file [:mixin_handler_002, :mixin_handler_003], __FILE__ + + expect(P('A1').instance_mixins).to eq [P('B1')] + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca9eda76d..513210a6c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,10 +31,10 @@ def self.parser_type; @parser_type == :ruby ? :ruby18 : @parser_type end NAMED_OPTIONAL_ARGUMENTS = RUBY_VERSION >= '2.1.0' -def parse_file(file, thisfile = __FILE__, log_level = log.level, ext = '.rb.txt') +def parse_file(files, thisfile = __FILE__, log_level = log.level, ext = '.rb.txt') Registry.clear - path = File.join(File.dirname(thisfile), 'examples', file.to_s + ext) - YARD::Parser::SourceParser.parse(path, [], log_level) + paths = Array(files).map { |file| File.join(File.dirname(thisfile), 'examples', file.to_s + ext) } + YARD::Parser::SourceParser.parse(paths, [], log_level) end def described_in_docs(klass, meth, file = nil)