This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +16
-103
lines changed Expand file tree Collapse file tree 4 files changed +16
-103
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
module RSpec
2
2
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
+
3
11
# Allows a thread to lock out other threads from a critical section of code,
4
12
# while allowing the thread with the lock to reenter that section.
5
13
#
6
14
# Based on Monitor as of 2.2 -
7
15
# https://github.com/ruby/ruby/blob/eb7ddaa3a47bf48045d26c72eb0f263a53524ebc/lib/monitor.rb#L9
8
16
#
9
- # Depends on Mutex, but Mutex is only available as part of core since 1.9.1:
10
- # exists - http://ruby-doc.org/core-1.9.1/Mutex.html
11
- # dne - http://ruby-doc.org/core-1.9.0/Mutex.html
12
- #
13
17
# @private
14
18
class ReentrantMutex
15
19
def initialize
@@ -40,22 +44,5 @@ def exit
40
44
@mutex . unlock
41
45
end
42
46
end
43
-
44
- if defined? ::Mutex
45
- # On 1.9 and up, this is in core, so we just use the real one
46
- class Mutex < ::Mutex
47
- # If you mock Mutex.new you break our usage of Mutex, so
48
- # instead we capture the original method to return Mutexs.
49
- NEW_MUTEX_METHOD = Mutex . method ( :new )
50
-
51
- def self . new
52
- NEW_MUTEX_METHOD . call
53
- end
54
- end
55
- else # For 1.8.7
56
- # :nocov:
57
- RSpec ::Support . require_rspec_support "mutex"
58
- # :nocov:
59
- end
60
47
end
61
48
end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
require 'rspec/support/reentrant_mutex'
2
2
require 'thread_order'
3
3
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
+
4
11
# There are no assertions specifically
5
- # They are pass if they don't deadlock
12
+ # They pass if they don't deadlock
6
13
RSpec . describe RSpec ::Support ::ReentrantMutex do
7
14
let! ( :mutex ) { described_class . new }
8
15
let! ( :order ) { ThreadOrder . new }
You can’t perform that action at this time.
0 commit comments