Skip to content

Commit 1308d72

Browse files
committed
Cleanups for Data#deconstruct_keys and Struct#deconstruct_keys
* Use the correct method name in the description for Data#deconstruct_keys * Add blank line between Data object creation and specs, to keep this consistent. * Add spec for incorrect index for Struct#deconstruct_keys, this spec was present for Data#deconstruct_keys, but missing for Struct.
1 parent c557b4a commit 1308d72

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/data/deconstruct_keys_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
33

4-
describe "Data#deconstruct" do
4+
describe "Data#deconstruct_keys" do
55
it "returns a hash of attributes" do
66
klass = Data.define(:x, :y)
77
d = klass.new(1, 2)
8+
89
d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
910
end
1011

@@ -29,6 +30,7 @@
2930
it "accepts string attribute names" do
3031
klass = Data.define(:x, :y)
3132
d = klass.new(1, 2)
33+
3234
d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
3335
end
3436

@@ -58,6 +60,7 @@
5860
it "returns an empty hash when there are more keys than attributes" do
5961
klass = Data.define(:x, :y)
6062
d = klass.new(1, 2)
63+
6164
d.deconstruct_keys([:x, :y, :x]).should == {}
6265
end
6366

core/struct/deconstruct_keys_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
s.deconstruct_keys([-1] ).should == {-1 => 30}
4444
end
4545

46+
it "ignores incorrect position numbers" do
47+
struct = Struct.new(:x, :y, :z)
48+
s = struct.new(10, 20, 30)
49+
50+
s.deconstruct_keys([0, 3]).should == {0 => 10}
51+
end
52+
4653
it "support mixing attribute names and argument position numbers" do
4754
struct = Struct.new(:x, :y)
4855
s = struct.new(1, 2)

0 commit comments

Comments
 (0)