Sha256: 7df36b4303d54a7a6729c978ceb0c82d6fe2a0eb0e316060d24f88a13098d1f3
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
# -*- coding: utf-8 -*- require 'yard' require 'yard/rspec_examples/it_handler' require 'yard/rspec_examples/module_handler' require 'yard/rspec_examples/describe_handler' require 'yard/rspec_examples/parser_trace' ## # This class will hold a map that associates the method descriptions with its source code class RSpecExampleRegistry def self.example_map @example_map ||= {} end end module YARD module Tags ## # A new type of tags has to be used cause we need to intercept the # text call and generate its contents (in generation time, after everything was parsed) class RSpecExampleTag < Tag def text # for now, we just handle case where describes are derived from the context example_description = rspec_description(object).gsub(/^::/,'').gsub(/ ::/, ' ') example_description += " #{name}" unless name.empty? key = RSpecExampleRegistry.example_map.keys.detect{|k| k.include?(example_description)} puts "[warn] Could not find example '#{example_description}'" unless key @text = RSpecExampleRegistry.example_map[key] end private def rspec_description(object) case object when CodeObjects::RootObject "" when CodeObjects::MethodObject "#{rspec_description(object.namespace)} ##{object.name}" when CodeObjects::ClassObject "#{rspec_description(object.namespace)}::#{object.name}" when CodeObjects::ModuleObject "#{rspec_description(object.namespace)}#{object.name} " end end end class DefaultFactory def parse_tag_with_rspec_example_tag(tagname, text) RSpecExampleTag.new(:example, "", [], text) end end end end YARD::Tags::Library.define_tag("Rspec Example", :rspec_example, :with_rspec_example_tag)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yard-rspec_examples-0.0.1 | lib/yard-rspec_examples.rb |