Sha256: 682798979d884f7b3720797f6523b4a7898b5408cba00d6d873e5cfa61dd8874

Contents?: true

Size: 1.95 KB

Versions: 25

Compression:

Stored size: 1.95 KB

Contents

require 'helper'

RSpec.describe Flipper::Middleware::SetupEnv do
  context 'with flipper instance' do
    let(:app) do
      app = lambda do |env|
        [200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
      end
      builder = Rack::Builder.new
      builder.use described_class, flipper
      builder.run app
      builder
    end

    it 'sets flipper in env' do
      get '/'
      expect(last_response.body).to eq(flipper.object_id.to_s)
    end
  end

  context 'with block that returns flipper instance' do
    let(:flipper_block) do
      -> { flipper }
    end
    let(:app) do
      app = lambda do |env|
        [200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
      end
      builder = Rack::Builder.new
      builder.use described_class, flipper_block
      builder.run app
      builder
    end

    it 'sets flipper in env' do
      get '/'
      expect(last_response.body).to eq(flipper.object_id.to_s)
    end
  end

  context 'when env already has flipper setup' do
    let(:app) do
      app = lambda do |env|
        [200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
      end
      builder = Rack::Builder.new
      builder.use described_class, flipper
      builder.run app
      builder
    end

    it 'leaves env flipper alone' do
      env_flipper = build_flipper
      get '/', {}, 'flipper' => env_flipper
      expect(last_response.body).to eq(env_flipper.object_id.to_s)
    end
  end

  context 'when flipper instance is nil' do
    let(:app) do
      app = lambda do |env|
        [200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
      end
      builder = Rack::Builder.new
      builder.use described_class, nil
      builder.run app
      builder
    end

    it 'leaves env flipper alone' do
      env_flipper = build_flipper
      get '/', {}, 'flipper' => env_flipper
      expect(last_response.body).to eq(env_flipper.object_id.to_s)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
flipper-0.19.1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.19.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.18.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.17.2 spec/flipper/middleware/setup_env_spec.rb
flipper-0.17.1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.16.2 spec/flipper/middleware/setup_env_spec.rb
flipper-0.16.1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.16.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.15.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.14.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.13.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.13.0.beta1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.12.2 spec/flipper/middleware/setup_env_spec.rb
flipper-0.12.1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.12.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.11.0 spec/flipper/middleware/setup_env_spec.rb
flipper-0.11.0.rc1 spec/flipper/middleware/setup_env_spec.rb
flipper-0.11.0.beta9 spec/flipper/middleware/setup_env_spec.rb
flipper-0.11.0.beta8 spec/flipper/middleware/setup_env_spec.rb
flipper-0.11.0.beta7 spec/flipper/middleware/setup_env_spec.rb