Sha256: ef7b7af1276c02cc37af322a94ed48e66225735dfb1fca9e67cc4a5b168195eb

Contents?: true

Size: 1.72 KB

Versions: 21

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true
require File.dirname(__FILE__) + '/spec_helper'

class StringSerializer < YARD::Serializers::Base
  attr_accessor :files, :string
  def initialize(files, string)
    @files = files
    @string = string
  end

  def serialize(object, data)
    files << object
    string << data
  end
end

RSpec.describe YARD::Templates::Engine.template(:default, :onefile) do
  before do
    Registry.clear
    if defined?(::Encoding)
      @eenc = Encoding.default_external
      Encoding.default_external = 'ascii-8bit'
      @ienc = Encoding.default_internal
      Encoding.default_internal = 'ascii-8bit'
    end
  end

  after do
    if defined?(::Encoding)
      Encoding.default_internal = @ienc
      Encoding.default_external = @eenc
    end
  end

  def render
    @files = []
    @output = String.new("")
    YARD.parse_string <<-eof
      class A
        # Foo method
        # @return [String]
        def foo; end

        # Bar method
        # @return [Numeric]
        def bar; end
      end
    eof
    readme = CodeObjects::ExtraFileObject.new('README',
      "# This is a code comment\n\n# Top of file\n\n\nclass C; end")
    Templates::Engine.generate Registry.all(:class),
      :serializer => StringSerializer.new(@files, @output),
      :onefile => true, :format => :html, :readme => readme, :files => [readme,
        CodeObjects::ExtraFileObject.new('LICENSE', 'This is a license!')]
  end

  it "renders html" do
    render
    expect(@files).to eq ['index.html']
    expect(@output).to include("This is a code comment")
    expect(@output).to include("This is a license!")
    expect(@output).to include("Class: A")
    expect(@output).to include("Foo method")
    expect(@output).to include("Bar method")
  end
end

Version data entries

21 entries across 20 versions & 4 rubygems

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