Sha256: b68458051f6ee23225772618b4ef555a9ea54527d3fe4868ca6662c5c9ffc44b

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'rack/when'

describe 'setting up for environments' do
  [:development, :test, :staging, :production].each do |env|
    before do
      allow(Rack::When::Builder).to receive(:new).and_return(builder)
    end

    let(:builder) { double "builder", mount: nil }
    let(:block)   { double "block" }

    context "implicit #{env}" do
      it 'sets up a builder with the environment and the current context as rackup' do
        Rack::When.send env, &(block = -> { })
        expect(Rack::When::Builder).to have_received(:new).with(env.to_sym,block)
      end

      it 'mounts the builder with caller as rackup' do
        Rack::When.send(env) { }
        expect(builder).to have_received(:mount)
      end
    end

    context "explicit #{env}" do
      it 'sets up a builder with the environment and the current context as rackup' do
        Rack::When.environments env, &(block = -> { })
        expect(Rack::When::Builder).to have_received(:new).with(env.to_sym,block)
      end

      it 'mounts the builder with caller as rackup' do
        Rack::When.environments(env) { }
        expect(builder).to have_received(:mount)
      end
    end

  end

  context "mutiple envs" do
    it 'sets up a builder with the environments and the current context as rackup' do
      Rack::When.environments :one, :two, &(block = -> { })
      expect(Rack::When::Builder).to have_received(:new).with(:one, :two, block)
    end

    it 'mounts the builder with caller as rackup' do
      Rack::When.environments(:one, :two) { }
      expect(builder).to have_received(:mount)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-when-1.0.0 spec/rack/when_spec.rb
rack-when-0.0.4 spec/rack/when_spec.rb
rack-when-0.0.3 spec/rack/when_spec.rb