-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_values.rb
More file actions
36 lines (29 loc) · 909 Bytes
/
fetch_values.rb
File metadata and controls
36 lines (29 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "minitest/autorun"
# ruby -Ilib:test fetch_values.rb
class Hash
end
describe Numeric do
describe "#monkey_fetch_values" do
before do
@hash = {a: 1, b: 2, c: 3, d: 4}
end
it "returns an array of values for the given keys" do
@hash.monkey_fetch_values(:a, :b, :c, :d).must_equal [1,2,3,4]
end
it "returns an empty array if there are no arguments" do
@hash.monkey_fetch_values().must_equal []
end
it "raises error if a key is not present" do
proc { @hash.monkey_fetch_values(:d, :e) }.must_raise KeyError
end
it "doesn't raise an error if key is present with nil value" do
@hash[:e] = false
@hash[:f] = nil
@hash.monkey_fetch_values(:d, :e, :f).must_equal [4, false, nil]
end
it "doesn't mutate the hash" do
@hash.monkey_fetch_values(:a)
@hash.must_equal(a: 1, b: 2, c: 3, d: 4)
end
end
end