Skip to content

Commit f4f24b4

Browse files
eregonandrykonchin
authored andcommitted
Spec that Constant === object is checked before calling #deconstruct/#deconstruct_keys
1 parent 74e2b6b commit f4f24b4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

spec/ruby/language/pattern_matching_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,20 @@ def obj.deconstruct
739739
RUBY
740740
end
741741

742+
it "checks Constant === object before calling #deconstruct" do
743+
c1 = Class.new
744+
obj = c1.new
745+
obj.should_not_receive(:deconstruct)
746+
eval(<<~RUBY).should == false
747+
case obj
748+
in String[1]
749+
true
750+
else
751+
false
752+
end
753+
RUBY
754+
end
755+
742756
it "does not match object without #deconstruct method" do
743757
obj = Object.new
744758
obj.should_receive(:respond_to?).with(:deconstruct)
@@ -1068,6 +1082,20 @@ def obj.deconstruct_keys(*)
10681082
RUBY
10691083
end
10701084

1085+
it "checks Constant === object before calling #deconstruct_keys" do
1086+
c1 = Class.new
1087+
obj = c1.new
1088+
obj.should_not_receive(:deconstruct_keys)
1089+
eval(<<~RUBY).should == false
1090+
case obj
1091+
in String(a: 1)
1092+
true
1093+
else
1094+
false
1095+
end
1096+
RUBY
1097+
end
1098+
10711099
it "does not match object without #deconstruct_keys method" do
10721100
obj = Object.new
10731101
obj.should_receive(:respond_to?).with(:deconstruct_keys)

0 commit comments

Comments
 (0)