Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/data/deconstruct_keys_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Data#deconstruct" do
describe "Data#deconstruct_keys" do
it "returns a hash of attributes" do
klass = Data.define(:x, :y)
d = klass.new(1, 2)

d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
end

Expand All @@ -29,6 +30,7 @@
it "accepts string attribute names" do
klass = Data.define(:x, :y)
d = klass.new(1, 2)

d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
end

Expand Down Expand Up @@ -58,6 +60,7 @@
it "returns an empty hash when there are more keys than attributes" do
klass = Data.define(:x, :y)
d = klass.new(1, 2)

d.deconstruct_keys([:x, :y, :x]).should == {}
end

Expand Down
7 changes: 7 additions & 0 deletions core/struct/deconstruct_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
s.deconstruct_keys([-1] ).should == {-1 => 30}
end

it "ignores incorrect position numbers" do
struct = Struct.new(:x, :y, :z)
s = struct.new(10, 20, 30)

s.deconstruct_keys([0, 3]).should == {0 => 10}
end

it "support mixing attribute names and argument position numbers" do
struct = Struct.new(:x, :y)
s = struct.new(1, 2)
Expand Down