Skip to content

Commit 66e5c08

Browse files
committed
Write Hash#fetch_values specs
Follow r50845 and Feature-10017
1 parent e0cc72c commit 66e5c08

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/hash/fetch_values_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
require File.expand_path('../fixtures/classes', __FILE__)
3+
4+
ruby_version_is "2.3" do
5+
describe "Hash#fetch_values" do
6+
before :each do
7+
@hash = new_hash a: 1, b: 2, c: 3
8+
end
9+
10+
describe "with matched keys" do
11+
it "returns the values for keys" do
12+
@hash.fetch_values(:a).should == [1]
13+
@hash.fetch_values(:a, :c).should == [1, 3]
14+
end
15+
end
16+
17+
describe "with unmatched keys" do
18+
it "raises a KeyError" do
19+
->{ @hash.fetch_values :z }.should raise_error(KeyError)
20+
->{ @hash.fetch_values :a, :z }.should raise_error(KeyError)
21+
end
22+
23+
it "returns the default value from block" do
24+
@hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"]
25+
@hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"]
26+
end
27+
end
28+
29+
describe "without keys" do
30+
it "returns an empty Array" do
31+
@hash.fetch_values.should == []
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)