Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
3 changes: 3 additions & 0 deletions lib/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ def turn_on!
# @see #turn_off!
# @see #turned_off
def turned_on?
linked_context = current_context[:linked_context]
return !linked_context[:turned_off] if linked_context

!context_value(:turned_off)
end

Expand Down
29 changes: 29 additions & 0 deletions spec/acceptance/threading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,34 @@ def recorded_content_for(name)
expect(recorded_content_for("search") +
recorded_content_for("foo")).to include("query: thread", "FOO!")
end

it 'can turn off VCR after another thread has started and affect the new thread' do
# Trigger context in main thread
VCR.turned_on?

thread = Thread.start do
# Trigger VCR to dup context to this new thread, linked to main thread
VCR.turned_on?

# Stop processing this thread so we can turn off VCR on the main thread
Thread.stop

# This request should be made after VCR is turned off on the main thread
Excon.get "http://localhost:#{VCR::SinatraApp.port}"
end

# Ensure the other thread has a chance to stop before we proceed?
sleep 1

VCR.turned_off do
# Now that VCR is turned off, we can resume our other thread
thread.wakeup

# Ensure the other thread has a chance to resume before we proceed?
sleep 1
end

thread.join
end
end
end