File: fetch_values_spec.rb

package info (click to toggle)
ruby-hamster 3.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,932 kB
  • sloc: ruby: 16,915; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 726 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  describe "#fetch_values" do
    context "when the all the requests keys exist" do
      it "returns a vector of values for the given keys" do
        h = H[:a => 9, :b => 'a', :c => -10, :d => nil]
        h.fetch_values.should be_kind_of(Hamster::Vector)
        h.fetch_values.should eql(V.empty)
        h.fetch_values(:a, :d, :b).should be_kind_of(Hamster::Vector)
        h.fetch_values(:a, :d, :b).should eql(V[9, nil, 'a'])
      end
    end

    context "when the key does not exist" do
      it "raises a KeyError" do
        -> { H["A" => "aye", "C" => "Cee"].fetch_values("A", "B") }.should raise_error(KeyError)
      end
    end
  end
end