Skip to content

Commit cb8903a

Browse files
committed
Use rspec configuration properly
1 parent 219d39d commit cb8903a

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

spec/spec_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@
3333
config.order = 'random'
3434
config.disable_monkey_patching!
3535
config.example_status_persistence_file_path = 'spec/examples.txt'
36+
37+
config.include Concurrent::TestHelpers
38+
config.extend Concurrent::TestHelpers
39+
40+
config.before :each do
41+
expect(!defined?(@created_threads) || @created_threads.nil? || @created_threads.empty?).to be_truthy
42+
end
43+
44+
config.after :each do
45+
while defined?(@created_threads) && @created_threads && (thread = (@created_threads.pop(true) rescue nil))
46+
thread.kill
47+
thread_join = thread.join(0.25)
48+
expect(thread_join).not_to be_nil
49+
end
50+
end
51+
3652
end

spec/support/example_group_extensions.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def monotonic_interval
2828

2929
def in_thread(*args, &block)
3030
@created_threads ||= Queue.new
31-
new_thread = Thread.new(*args) do |*args, &b|
31+
new_thread = Thread.new(*args) do |*args, &b|
3232
Thread.abort_on_exception = true
3333
block.call *args, &b
3434
end
@@ -49,19 +49,3 @@ def join_with(threads, timeout = 5)
4949
end
5050
end
5151
end
52-
53-
class RSpec::Core::ExampleGroup
54-
include Concurrent::TestHelpers
55-
extend Concurrent::TestHelpers
56-
57-
before :each do
58-
expect(@created_threads.nil? || @created_threads.empty?).to be_truthy
59-
end
60-
61-
after :each do
62-
while (thread = (@created_threads.pop(true) rescue nil))
63-
thread.kill
64-
expect(thread.join(0.25)).not_to be_nil
65-
end
66-
end
67-
end

0 commit comments

Comments
 (0)