Skip to content

Commit 2b0adb0

Browse files
committed
Make Marshal extended Struct specs symmetrical
1 parent 8fdb72e commit 2b0adb0

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

spec/ruby/core/marshal/dump_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,13 @@
357357
end
358358

359359
it "dumps an extended Struct" do
360-
st = Struct.new("Extended", :a, :b).new
361-
Marshal.dump(st.extend(Meths)).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
360+
obj = Struct.new("Extended", :a, :b).new.extend(Meths)
361+
Marshal.dump(obj).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
362+
363+
s = 'hi'
364+
obj.a = [:a, s]
365+
obj.b = [:Meths, s]
366+
Marshal.dump(obj).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
362367
Struct.send(:remove_const, :Extended)
363368
end
364369
end

spec/ruby/core/marshal/shared/load.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,23 @@
478478
describe "for a Struct" do
479479
it "loads a extended_struct having fields with same objects" do
480480
s = 'hi'
481-
obj = Struct.new("Ure2", :a, :b).new.extend(Meths)
481+
obj = Struct.new("Extended", :a, :b).new.extend(Meths)
482+
dump = "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
483+
Marshal.send(@method, dump).should == obj
484+
482485
obj.a = [:a, s]
483486
obj.b = [:Meths, s]
484-
485-
Marshal.send(@method,
486-
"\004\be:\nMethsS:\021Struct::Ure2\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
487-
).should == obj
488-
Struct.send(:remove_const, :Ure2)
487+
dump = "\004\be:\nMethsS:\025Struct::Extended\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
488+
Marshal.send(@method, dump).should == obj
489+
Struct.send(:remove_const, :Extended)
489490
end
490491

491492
it "loads a struct having ivar" do
492493
obj = Struct.new("Thick").new
493494
obj.instance_variable_set(:@foo, 5)
494-
Marshal.send(@method, "\004\bIS:\022Struct::Thick\000\006:\t@fooi\n").should == obj
495+
reloaded = Marshal.send(@method, "\004\bIS:\022Struct::Thick\000\006:\t@fooi\n")
496+
reloaded.should == obj
497+
reloaded.instance_variable_get(:@foo).should == 5
495498
Struct.send(:remove_const, :Thick)
496499
end
497500

0 commit comments

Comments
 (0)