From c890fb04581e156bdf397a00d5723915a8754f77 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 10 Sep 2023 15:18:49 +0200 Subject: [PATCH 1/2] Add specs for IO#autoclose? and IO#autoclose= The actual behaviour is still untested. --- core/io/autoclose_spec.rb | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 core/io/autoclose_spec.rb diff --git a/core/io/autoclose_spec.rb b/core/io/autoclose_spec.rb new file mode 100644 index 000000000..0375a9191 --- /dev/null +++ b/core/io/autoclose_spec.rb @@ -0,0 +1,49 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +describe "IO#autoclose" do + before :each do + @io = IOSpecs.io_fixture "lines.txt" + end + + after :each do + @io.autoclose = true unless @io.closed? + @io.close unless @io.closed? + end + + it "can be set to true" do + @io.autoclose = true + @io.should.autoclose? + end + + it "can be set to false" do + @io.autoclose = false + @io.should_not.autoclose? + end + + it "can be set to any truthy value" do + @io.autoclose = 42 + @io.should.autoclose? + end + + it "can be set multple times" do + @io.autoclose = true + @io.should.autoclose? + + @io.autoclose = false + @io.should_not.autoclose? + + @io.autoclose = true + @io.should.autoclose? + end + + it "cannot be queried on a closed IO object" do + @io.close + -> { @io.autoclose? }.should raise_error(IOError, /closed stream/) + end + + it "cannot be set on a closed IO object" do + @io.close + -> { @io.autoclose = false }.should raise_error(IOError, /closed stream/) + end +end From 8363787208ab29911c2a4ce2690595a9b5357d8c Mon Sep 17 00:00:00 2001 From: Herwin Date: Thu, 28 Sep 2023 17:45:05 +0200 Subject: [PATCH 2/2] Process review comments --- core/io/autoclose_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/io/autoclose_spec.rb b/core/io/autoclose_spec.rb index 0375a9191..c5ab98ea9 100644 --- a/core/io/autoclose_spec.rb +++ b/core/io/autoclose_spec.rb @@ -11,19 +11,36 @@ @io.close unless @io.closed? end + it "is set to true by default" do + @io.should.autoclose? + end + it "can be set to true" do + @io.autoclose = false @io.autoclose = true @io.should.autoclose? end it "can be set to false" do + @io.autoclose = true @io.autoclose = false @io.should_not.autoclose? end it "can be set to any truthy value" do + @io.autoclose = false @io.autoclose = 42 @io.should.autoclose? + + @io.autoclose = false + @io.autoclose = Object.new + @io.should.autoclose? + end + + it "can be set to any falsy value" do + @io.autoclose = true + @io.autoclose = nil + @io.should_not.autoclose? end it "can be set multple times" do