require 'spec_helper'
require 'brainstem/api_docs'

module Brainstem
  describe ApiDocs do
    let(:lorem) { "lorem ipsum dolor sit amet" }

    describe "configuration" do
      describe "formatters" do
        it "has a formatters constant" do
          expect(Brainstem::ApiDocs::FORMATTERS).to be_a(Hash)
        end
      end

      %w(
        controller_filename_pattern
        presenter_filename_pattern
        controller_filename_link_pattern
        presenter_filename_link_pattern
        write_path
        output_extension
        base_presenter_class
        base_controller_class
        document_empty_presenter_associations
        document_empty_presenter_filters
      ).each do |meth|
        describe meth do
          before do
            @original = described_class.public_send(meth)
          end

          after do
            described_class.public_send("#{meth}=", @original)
          end

          it "can be set and read" do
            described_class.public_send("#{meth}=", lorem)
            expect(described_class.public_send(meth)).to eq lorem
          end
        end
      end
    end

    describe "filename link patterns" do
      it 'defaults to the filename pattern' do
        expect(described_class.public_send("controller_filename_link_pattern")).
          to eq(described_class.public_send("controller_filename_pattern"))

        expect(described_class.public_send("presenter_filename_link_pattern")).
          to eq(described_class.public_send("presenter_filename_pattern"))
      end
    end
  end
end

require 'spec_helper'
require 'brainstem/api_docs'

module Brainstem
  describe ApiDocs do
    let(:lorem) { "lorem ipsum dolor sit amet" }

    describe "configuration" do
      describe "formatters" do
        it "has a formatters constant" do
          expect(Brainstem::ApiDocs::FORMATTERS).to be_a(Hash)
        end
      end

      %w(
        controller_filename_pattern
        presenter_filename_pattern
        controller_filename_link_pattern
        presenter_filename_link_pattern
        write_path
        output_extension
        base_presenter_class
        base_controller_class
        base_application_proc
        document_empty_presenter_associations
        document_empty_presenter_filters
      ).each do |meth|
        describe meth do
          before do
            @original = described_class.public_send(meth)
          end

          after do
            described_class.public_send("#{meth}=", @original)
          end

          it "can be set and read" do
            described_class.public_send("#{meth}=", lorem)
            expect(described_class.public_send(meth)).to eq lorem
          end
        end
      end
    end

    describe "filename link patterns" do
      it 'defaults to the filename pattern' do
        expect(described_class.public_send("controller_filename_link_pattern")).
          to eq(described_class.public_send("controller_filename_pattern"))

        expect(described_class.public_send("presenter_filename_link_pattern")).
          to eq(described_class.public_send("presenter_filename_pattern"))
      end
    end
  end
end

Test our configuration option for a "base" application proc
Test our configuration option for a "base" application proc

This proc returns either a Rails application (probably `Rails.application` or an engine (for example, Api::Engine) that the routes will be documented.
