Sha256: 1410211b5a953e71f1ecf4d161d898597a28100004c8e8ee1a8ec3a3497d705b
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
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 = full_rspec_description key = find_key(example_description, @name) puts "[warn] Could not find example '#{example_description}'" unless key @text = RSpecExampleRegistry.example_map[key] end def name find_key(full_rspec_description, @name) || '' end private def find_key(example_description, name) key = RSpecExampleRegistry.example_map.keys.detect { |k| k.include?(example_description) } key || RSpecExampleRegistry.example_map.keys.detect { |k| k.include?(name) } end def full_rspec_description example_description = rspec_description(object).gsub(/^::/, '') example_description + (@name.empty? ? '' : (@name.to_s =~ /^(#|\.)/ ? @name.to_s : " #{@name}")) end def rspec_description(object) case object when CodeObjects::RootObject "" when CodeObjects::MethodObject if object.scope == :instance "#{rspec_description(object.namespace)}##{object.name}" else "#{rspec_description(object.namespace)}.#{object.name}" end when CodeObjects::ClassObject "::#{object.name}" when CodeObjects::ModuleObject "#{rspec_description(object.namespace)}::#{object.name}" else "" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yard-rspec_examples-0.0.2 | lib/yard/tags/rspec_example_tag.rb |