From 6d8a5911ee29ecb8e0e047c17fdaab14205e35d6 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Thu, 12 Nov 2020 11:18:27 +0100 Subject: [PATCH] Docs: Add an example unstubbing all keys at once --- docsite/source/testing.html.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docsite/source/testing.html.md b/docsite/source/testing.html.md index 9e90908..815ee14 100644 --- a/docsite/source/testing.html.md +++ b/docsite/source/testing.html.md @@ -37,3 +37,21 @@ container[:redis] # => "Stubbed redis instance" container.unstub(:redis) # => "Redis instance" ``` + +To clear all stubs at once, call `#unstub` without any arguments: + +```ruby +container = Dry::Container.new +container.register(:redis) { "Redis instance" } +container.register(:db) { "DB instance" } + +require 'dry/container/stub' +container.enable_stubs! +container.stub(:redis, "Stubbed redis instance") +container.stub(:db, "Stubbed DB instance") + +container.unstub # This will unstub all previously stubbed keys + +container[:redis] # => "Redis instance" +container[:db] # => "Redis instance" +```