Sha256: 0b1d093de1424653167009a79c14db94819410d65167ec098a822efb18824f98

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe GrapeMarkdown::Document do
  include_context 'configuration'

  before do
    GrapeMarkdown.config do |config|
      config.name               = name
      config.description        = description
      config.resource_exclusion = [:admin]
    end

    GrapeMarkdown.config.request_headers = [
      { 'Accept-Charset' => 'utf-8' },
      { 'Connection'     => 'keep-alive' }
    ]

    GrapeMarkdown.config.response_headers = [
      { 'Content-Length' => '21685' },
      { 'Connection'     => 'keep-alive' }
    ]
  end

  subject { GrapeMarkdown::Document.new(SampleApi) }

  context '#generate' do
    let(:klass) { SampleApi }

    subject { GrapeMarkdown::Document.new(klass).generate }

    it 'creates a header from configuration' do
      expect(subject).to include("# #{name}")
    end

    it 'adds the description' do
      expect(subject).to include(description)
    end

    it 'includes properties for the resources' do
      expect(subject).to include('Properties')
    end

    it 'includes short route descriptions' do
      expect(subject).to include('## Post a Widget')
    end
  end

  it 'exposes configuration settings' do
    GrapeMarkdown::Configuration::SETTINGS.each do |setting|
      value = GrapeMarkdown.config.send(setting)

      expect(subject.send(setting)).to eq(value)
    end
  end

  it 'exposes the raw routes of the given api' do
    expect(subject.routes).to eq(SampleApi.routes)
  end

  context '#resources' do
    let(:unique_routes) { subject.routes.map(&:route_name).uniq }

    let(:included_routes) do
      unique_routes.reject do |name|
        GrapeMarkdown.config.resource_exclusion.include?(name.to_sym)
      end
    end

    it 'aggregates routes into resources' do
      expect(subject.resources.first).to be_a(GrapeMarkdown::Resource)
    end

    it 'excluded resources based on configuration' do
      expect(subject.resources.map(&:key)).to eq(included_routes)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-markdown-0.0.7 spec/grape-markdown/document_spec.rb
grape-markdown-0.0.6 spec/grape-markdown/document_spec.rb