Sha256: ba92c67108b1e484b94557b0a3fc8880908c80739c74cd234f52aca1d35d89ea

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe NYNY::App do
  describe 'namespace' do
    let (:app) do
      mock_app do
        helpers do
          def le_helper
            :lulwut
          end
        end

        namespace '/foo' do
          get '/' do
            le_helper.should == :lulwut
            'bar'
          end
        end

        namespace '/nested' do
          namespace '/space' do
            get '/' do
              le_helper.should == :lulwut
              'caramba'
            end
          end
        end

        get '/' do
          'no namespace here'
        end
      end
    end

    it 'accepts a app as a parameter' do
      mounted = mock_app_class do
        get '/' do
          'mounted!'
        end
      end

      app = mock_app do
        namespace '/mounted', mounted

        get '/' do
          'root'
        end
      end

      app.get('/').body.should == 'root'
      app.get('/mounted').body.should == 'mounted!'
    end

    it 'allows to use middlewares inside namespace' do
      kls = Class.new(NYNY::Base) do
        get '/' do
          'foo'
        end
      end

      app = mock_app do
        namespace '/foo' do
          use kls
        end
      end

      app.get('/foo')
    end

    it 'allows to specify stuff in namespaces' do
      app.get('/foo').body.should == 'bar'
    end

    it 'does not break the main app' do
      app.get('/').body.should == 'no namespace here'
    end

    it 'can be nested as well' do
      app.get('/nested/space/').body.should == 'caramba'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nyny-3.4.3 spec/namespace_spec.rb
nyny-3.4.2 spec/namespace_spec.rb