Skip to content

Commit

Permalink
Add spec for MonitorMixin#mon_initialize
Browse files Browse the repository at this point in the history
* Based on #1428.
  • Loading branch information
eregon committed Sep 20, 2018
1 parent 6d3bc69 commit 422d83d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/ruby/library/monitor/mon_initialize_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative '../../spec_helper'
require 'monitor'

describe "MonitorMixin#mon_initialize" do
it "can be called in initialize_copy to get a new Mutex and used with synchronize" do
cls = Class.new do
include MonitorMixin

def initialize(*array)
mon_initialize
@array = array
end

def to_a
synchronize { @array.dup }
end

def initialize_copy(other)
mon_initialize

synchronize do
@array = other.to_a
end
end
end

instance = cls.new(1, 2, 3)
copy = instance.dup
copy.should_not equal(instance)
end
end

0 comments on commit 422d83d

Please sign in to comment.