From ae05448017805b0695d0c8fbb030ad49ffdc6cd7 Mon Sep 17 00:00:00 2001 From: Herwin Date: Mon, 23 Sep 2024 19:11:21 +0200 Subject: [PATCH] Add specs for Queue#freeze and SizedQueue#freeze References: * https://rubyreferences.github.io/rubychanges/3.3.html#threadqueuefreeze-and-sizedqueuefreeze-raise-typeerror * https://bugs.ruby-lang.org/issues/17146 * https://docs.ruby-lang.org/en/3.3/Thread/Queue.html#method-i-freeze * https://docs.ruby-lang.org/en/3.3/Thread/SizedQueue.html#method-i-freeze --- core/queue/freeze_spec.rb | 6 ++++++ core/sizedqueue/freeze_spec.rb | 6 ++++++ shared/queue/freeze.rb | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 core/queue/freeze_spec.rb create mode 100644 core/sizedqueue/freeze_spec.rb create mode 100644 shared/queue/freeze.rb diff --git a/core/queue/freeze_spec.rb b/core/queue/freeze_spec.rb new file mode 100644 index 000000000..ced2cc52d --- /dev/null +++ b/core/queue/freeze_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/freeze' + +describe "Queue#freeze" do + it_behaves_like :queue_freeze, :freeze, -> { Queue.new } +end diff --git a/core/sizedqueue/freeze_spec.rb b/core/sizedqueue/freeze_spec.rb new file mode 100644 index 000000000..98f01cae2 --- /dev/null +++ b/core/sizedqueue/freeze_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/freeze' + +describe "SizedQueue#freeze" do + it_behaves_like :queue_freeze, :freeze, -> { SizedQueue.new(1) } +end diff --git a/shared/queue/freeze.rb b/shared/queue/freeze.rb new file mode 100644 index 000000000..4c506a423 --- /dev/null +++ b/shared/queue/freeze.rb @@ -0,0 +1,18 @@ +describe :queue_freeze, shared: true do + ruby_version_is ""..."3.3" do + it "can be frozen" do + queue = @object.call + queue.freeze + queue.should.frozen? + end + end + + ruby_version_is "3.3" do + it "raises an exception when freezing" do + queue = @object.call + -> { + queue.freeze + }.should raise_error(TypeError, "cannot freeze #{queue}") + end + end +end