Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Allow successful mocking of Mutex#synchronize #1575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/rspec/mocks/proxy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RSpec::Support.require_rspec_support 'mutex'

module RSpec
module Mocks
# @private
Expand All @@ -9,11 +11,6 @@ def ==(expectation)
end
end

unless defined?(Mutex)
Support.require_rspec_support 'mutex'
Mutex = Support::Mutex
end

# @private
def ensure_implemented(*_args)
# noop for basic proxies, see VerifyingProxy for behaviour.
Expand All @@ -27,7 +24,7 @@ def initialize(object, order_group, options={})
@order_group = order_group
@error_generator = ErrorGenerator.new(object)
@messages_received = []
@messages_received_mutex = Mutex.new
@messages_received_mutex = Support::Mutex.new
@options = options
@null_object = false
@method_doubles = Hash.new { |h, k| h[k] = MethodDouble.new(@object, k, self) }
Expand Down
18 changes: 18 additions & 0 deletions spec/rspec/mocks/mutex_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module RSpec
module Mocks
RSpec.describe "Mocking Mutex" do
let(:mocked_mutex) { instance_double(Mutex) }
before do
allow(Mutex).to receive(:new).and_return(mocked_mutex)
allow(mocked_mutex).to receive(:synchronize).and_yield
end

it "successfully yields" do
called = false
mutex = Mutex.new
mutex.synchronize { called = true }
expect(called).to be_truthy
end
end
end
end
Loading