Sha256: d80cfab48c8e14370a8cb9ae937846fb5ed887204550fb7327902a20893b1cbe

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe Grape::RackBuilder do
  let(:builder) {
    Module.new do
      class << self
        include Grape::RackBuilder::ClassMethods
        def get_config
          config
        end
      end
    end
  }

  before do
    builder.setup do
      environment 'development'
      add_source_path File.expand_path('**/*.rb', APP_ROOT)
    end
  end
  before :each do
    builder.get_config.mounts.clear
  end

  describe '.setup' do
    subject(:config){ builder.get_config }

    it 'configures builder with options' do
      expect(config.sources).to include(File.expand_path('**/*.rb', APP_ROOT))
      expect(config.environment).to eq('development')
    end

    it 'allows to mount bunch of grape apps to different roots' do
      builder.setup do
        mount 'TestClass1', to: '/test1'
        mount 'TestClass2', to: '/test2'
      end
      expect(config.mounts.size).to eq(2)
    end
  end
  #
  describe '.boot!' do
    before(:each) do
      builder.setup do
        mount 'Test::App1', to: '/test1'
        mount 'Test::App2', to: '/test2'
      end
    end

    it 'autoloads mounted apps files' do
      expect{ builder.boot! }.to_not raise_error
      expect(defined?(Test::App1)).not_to be_nil
      expect(defined?(Test::App2)).not_to be_nil
    end

    it 'autoloads apps dependencies, too' do
      expect{ builder.boot! }.to_not raise_error
      expect(defined?(Test::Mount1)).not_to be_nil
      expect(defined?(Test::Mount2)).not_to be_nil
    end
  end

  describe '.application' do
    before(:each) do
      builder.setup do
        mount 'Test::App1', to: '/test1'
        mount 'Test::App2', to: '/test2'
      end
      builder.boot!
    end
    it 'creates Rack::Builder application' do
      expect{ @app = builder.application }.not_to raise_error
      expect(@app).to be_an_instance_of(Rack::Builder)
      def @app.get_map; @map end
      expect(@app.get_map.keys).to include('/test1','/test2')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-reload-0.0.3 spec/grape/reload/rack_builder_spec.rb
grape-reload-0.0.2 spec/grape/reload/rack_builder_spec.rb