diff options
author | Benoit Daloze <eregontp@gmail.com> | 2022-08-29 15:36:29 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2022-08-29 15:36:29 +0200 |
commit | 4ee1a687768338a1928014fc6042c320a1a1af3e (patch) | |
tree | 37c1717dcd7a2a757e343a41b827fd096397fbca /spec/ruby/core/io | |
parent | a319d3cfdc1afef8497321fee7f690052b16739c (diff) | |
download | ruby-4ee1a687768338a1928014fc6042c320a1a1af3e.tar.gz |
Update to ruby/spec@d01709f
Diffstat (limited to 'spec/ruby/core/io')
-rw-r--r-- | spec/ruby/core/io/fixtures/classes.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/io/pipe_spec.rb | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb index 067ab59d93..204a2a101b 100644 --- a/spec/ruby/core/io/fixtures/classes.rb +++ b/spec/ruby/core/io/fixtures/classes.rb @@ -7,6 +7,18 @@ module IOSpecs class SubIO < IO end + class SubIOWithRedefinedNew < IO + def self.new(...) + ScratchPad << :redefined_new_called + super + end + + def initialize(...) + ScratchPad << :call_original_initialize + super + end + end + def self.collector Proc.new { |x| ScratchPad << x } end diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb index 2f2cf06f4d..aee0d9003f 100644 --- a/spec/ruby/core/io/pipe_spec.rb +++ b/spec/ruby/core/io/pipe_spec.rb @@ -25,6 +25,17 @@ describe "IO.pipe" do @r.should be_an_instance_of(IOSpecs::SubIO) @w.should be_an_instance_of(IOSpecs::SubIO) end + + it "does not use IO.new method to create pipes and allows its overriding" do + ScratchPad.record [] + + # so redefined .new is not called, but original #initialize is + @r, @w = IOSpecs::SubIOWithRedefinedNew.pipe + ScratchPad.recorded.should == [:call_original_initialize, :call_original_initialize] # called 2 times - for each pipe (r and w) + + @r.should be_an_instance_of(IOSpecs::SubIOWithRedefinedNew) + @w.should be_an_instance_of(IOSpecs::SubIOWithRedefinedNew) + end end describe "IO.pipe" do |