File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments