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