Sha256: f70ef03b4638fac8330de8ff827a50dc6d299b24fbf24bd8acf0487f3839ea5c

Contents?: true

Size: 1014 Bytes

Versions: 42

Compression:

Stored size: 1014 Bytes

Contents

require 'minitest/autorun'
require 'rack/session/abstract/id'

describe Rack::Session::Abstract::SessionHash do
  attr_reader :hash

  def setup
    super
    store = Class.new do
      def load_session(req)
        ["id", {foo: :bar, baz: :qux}]
      end
      def session_exists?(req)
        true
      end
    end
    @hash = Rack::Session::Abstract::SessionHash.new(store.new, nil)
  end

  it "returns keys" do
    assert_equal ["foo", "baz"], hash.keys
  end

  it "returns values" do
    assert_equal [:bar, :qux], hash.values
  end

  describe "#fetch" do
    it "returns value for a matching key" do
      assert_equal :bar, hash.fetch(:foo)
    end

    it "works with a default value" do
      assert_equal :default, hash.fetch(:unknown, :default)
    end

    it "works with a block" do
      assert_equal :default, hash.fetch(:unkown) { :default }
    end

    it "it raises when fetching unknown keys without defaults" do
      lambda { hash.fetch(:unknown) }.must_raise KeyError
    end
  end
end

Version data entries

42 entries across 40 versions & 10 rubygems

Version Path
rack-2.0.3 test/spec_session_abstract_session_hash.rb
rack-2.0.2 test/spec_session_abstract_session_hash.rb