Sha256: f6f43c62509becad1d5a5f5d20c193dfc77a3abe436382d971ed10bef5e2f0a4

Contents?: true

Size: 1.54 KB

Versions: 17

Compression:

Stored size: 1.54 KB

Contents

require "spec_helper"

describe Shamu::Features::EnvStore do
  hunt( :codec, Shamu::Features::ToggleCodec ) { scorpion.new Shamu::Features::ToggleCodec }

  it "reads from rack header" do
    packed = codec.pack( "buy_now" => true )
    env    = {
      "rack.input" => StringIO.new,
      Shamu::Features::EnvStore::RACK_ENV_KEY => packed
    }
    scorpion.hunt_for Scorpion::Rack::Env, return: env

    store = scorpion.fetch( Shamu::Features::EnvStore )
    expect( store.fetch( "buy_now" ) ).to eq true
  end

  it "reads from rack params" do
    packed = codec.pack( "buy_now" => true )
    env    = {
      "rack.input" => StringIO.new,
      "QUERY_STRING" => "#{ Shamu::Features::EnvStore::RACK_PARAMS_KEY }=#{ URI.escape( packed ) }"
    }
    scorpion.hunt_for Scorpion::Rack::Env, return: env

    store = scorpion.fetch( Shamu::Features::EnvStore )
    expect( store.fetch( "buy_now" ) ).to eq true
  end

  it "falls back to env" do
    scorpion.hunt_for Scorpion::Rack::Env, return: { "rack.input" => StringIO.new }
    store = scorpion.fetch( Shamu::Features::EnvStore )
    key   = store.class.env_key_name( "buy_now" )

    expect( ENV ).to receive( :key? ).with( key ).and_return true
    expect( ENV ).to receive( :[] ).with( key ).and_return "false"

    expect( store.fetch( "buy_now" ) ).to eq false
  end

  it "falls back to fall back block" do
    scorpion.hunt_for Scorpion::Rack::Env, return: { "rack.input" => StringIO.new }
    store = scorpion.fetch( Shamu::Features::EnvStore )

    expect( store.fetch( "buy_now" ) { "yep" } ).to eq "yep"
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.21 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.20 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.19 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.18 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.17 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.15 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.14 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.13 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.11 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.9 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.8 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.7 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.5 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.4 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.3 spec/lib/shamu/features/env_store_spec.rb
shamu-0.0.2 spec/lib/shamu/features/env_store_spec.rb