Sha256: 4879b770a859b294d469ed6d97f6805154299e7171c453a856f2c76d19283bd6

Contents?: true

Size: 1.95 KB

Versions: 21

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true
require File.dirname(__FILE__) + "/shared_signature_examples"

RSpec.describe YARD::Templates::Helpers::TextHelper do
  include YARD::Templates::Helpers::BaseHelper
  include YARD::Templates::Helpers::TextHelper
  include YARD::Templates::Helpers::MethodHelper

  describe "#signature" do
    before do
      @results = {
        :regular => "root.foo -> Object",
        :default_return => "root.foo -> Hello",
        :no_default_return => "root.foo",
        :private_class => "A.foo -> Object (private)",
        :single => "root.foo -> String",
        :two_types => "root.foo -> (String, Symbol)",
        :two_types_multitag => "root.foo -> (String, Symbol)",
        :type_nil => "root.foo -> Type?",
        :type_array => "root.foo -> Type+",
        :multitype => "root.foo -> (Type, ...)",
        :void => "root.foo -> void",
        :hide_void => "root.foo",
        :block => "root.foo {|a, b, c| ... } -> Object",
        :empty_overload => 'root.foobar -> String'
      }
    end

    def signature(obj) super(obj).strip end

    it_should_behave_like "signature"
  end

  describe "#align_right" do
    it "aligns text right" do
      text = "Method: #some_method (SomeClass)"
      expect(align_right(text)).to eq ' ' * 40 + text
    end

    it "truncates text that is longer than allowed width" do
      text = "(Defined in: /home/user/.rip/.packages/some_gem-2460672e333ac07b9190ade88ec9a91c/long/path.rb)"
      expect(align_right(text)).to eq ' ' + text[0, 68] + '...'
    end
  end

  describe "#h" do
    let(:object) do
      YARD::CodeObjects::MethodObject.new(:root, :foo, :instance).tap do |o|
        o.docstring = "test"
      end
    end

    it "resolves links" do
      expect(h("{include:#foo} 1 2 3").strip).to eq "test 1 2 3"
    end

    it "uses title when present" do
      expect(h("{A b}").strip).to eq "b"
    end

    it "uses object name when no title is present" do
      expect(h("{A}").strip).to eq "A"
    end
  end
end

Version data entries

21 entries across 20 versions & 4 rubygems

Version Path
yard-0.9.24 spec/templates/helpers/text_helper_spec.rb
yard-0.9.23 spec/templates/helpers/text_helper_spec.rb
yard-0.9.22 spec/templates/helpers/text_helper_spec.rb
yard-0.9.21 spec/templates/helpers/text_helper_spec.rb
yard-0.9.20 spec/templates/helpers/text_helper_spec.rb
yard-0.9.19 spec/templates/helpers/text_helper_spec.rb
yard-0.9.16 spec/templates/helpers/text_helper_spec.rb
yard-0.9.15 spec/templates/helpers/text_helper_spec.rb
yard-0.9.14 spec/templates/helpers/text_helper_spec.rb
yard-0.9.13 spec/templates/helpers/text_helper_spec.rb
yard-0.9.12 spec/templates/helpers/text_helper_spec.rb
yard-0.9.11 spec/templates/helpers/text_helper_spec.rb
yard-0.9.10 spec/templates/helpers/text_helper_spec.rb
yard-0.9.9 spec/templates/helpers/text_helper_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/spec/templates/helpers/text_helper_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/spec/templates/helpers/text_helper_spec.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/spec/templates/helpers/text_helper_spec.rb
yard-0.9.8 spec/templates/helpers/text_helper_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/spec/templates/helpers/text_helper_spec.rb
yard-0.9.7 spec/templates/helpers/text_helper_spec.rb