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

Commit 2c58e18

Browse files
committed
fixup! Combine Mutex with ReentrantMutex
1 parent 03dbe8f commit 2c58e18

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

lib/rspec/support/mutex.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/rspec/support/reentrant_mutex.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
RSpec::Support.require_rspec_support "mutex"
2-
31
module RSpec
42
module Support
3+
# This class protects us against Mutex.new stubbed out within tests.
4+
# @private
5+
class Mutex < ::Mutex
6+
class << self
7+
define_method(:new, &::Mutex.method(:new))
8+
end
9+
end
10+
511
# Allows a thread to lock out other threads from a critical section of code,
612
# while allowing the thread with the lock to reenter that section.
713
#

spec/rspec/support/mutex_spec.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/rspec/support/reentrant_mutex_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require 'rspec/support/reentrant_mutex'
22
require 'thread_order'
33

4+
RSpec.describe RSpec::Support::Mutex do
5+
it "allows ::Mutex to be mocked" do
6+
expect(Mutex).to receive(:new)
7+
::Mutex.new
8+
end
9+
end
10+
411
# There are no assertions specifically
512
# They pass if they don't deadlock
613
RSpec.describe RSpec::Support::ReentrantMutex do

0 commit comments

Comments
 (0)