File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 8484 d . deconstruct_keys ( nil ) . should == { x : 1 , y : 2 }
8585 end
8686
87+ it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
88+ klass = Data . define ( :x , :y )
89+ d = klass . new ( 1 , 2 )
90+
91+ key = mock ( "to_int" )
92+ key . should_receive ( :to_int ) . and_return ( 1 )
93+
94+ d . deconstruct_keys ( [ key ] ) . should == { key => 2 }
95+ end
96+
97+ it "raises a TypeError if the conversion with #to_int does not return an Integer" do
98+ klass = Data . define ( :x , :y )
99+ d = klass . new ( 1 , 2 )
100+
101+ key = mock ( "to_int" )
102+ key . should_receive ( :to_int ) . and_return ( "not an Integer" )
103+
104+ -> {
105+ d . deconstruct_keys ( [ key ] )
106+ } . should raise_error ( TypeError , /can't convert MockObject to Integer/ )
107+ end
108+
87109 it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do
88110 klass = Data . define ( :x , :y )
89111 d = klass . new ( 1 , 2 )
Original file line number Diff line number Diff line change 8080 obj . deconstruct_keys ( nil ) . should == { x : 1 , y : 2 }
8181 end
8282
83+ it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
84+ struct = Struct . new ( :x , :y )
85+ s = struct . new ( 1 , 2 )
86+
87+ key = mock ( "to_int" )
88+ key . should_receive ( :to_int ) . and_return ( 1 )
89+
90+ s . deconstruct_keys ( [ key ] ) . should == { key => 2 }
91+ end
92+
93+ it "raises a TypeError if the conversion with #to_int does not return an Integer" do
94+ struct = Struct . new ( :x , :y )
95+ s = struct . new ( 1 , 2 )
96+
97+ key = mock ( "to_int" )
98+ key . should_receive ( :to_int ) . and_return ( "not an Integer" )
99+
100+ -> {
101+ s . deconstruct_keys ( [ key ] )
102+ } . should raise_error ( TypeError , /can't convert MockObject to Integer/ )
103+ end
104+
83105 it "raises TypeError if index is not a String, a Symbol and not convertible to Integer" do
84106 struct = Struct . new ( :x , :y )
85107 s = struct . new ( 1 , 2 )
You can’t perform that action at this time.
0 commit comments