Created
December 5, 2022 16:27
-
-
Save djuber/cf0fec3b996b316ced18908fcbdf6e5b to your computer and use it in GitHub Desktop.
leaked double reproduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass | |
def self.client | |
true | |
end | |
end | |
class UsesClient | |
def self.call | |
client.nil? | |
end | |
def self.client | |
@client ||= SomeClass.client | |
end | |
end | |
RSpec.describe 'tangled web we weave' do | |
let(:client) { double(:client) } | |
before do | |
allow(SomeClass).to receive(:client).and_return(client) | |
end | |
it 'does one thing' do | |
expect(client).to receive(:nil?) | |
UsesClient.call | |
end | |
it 'does another thing' do | |
expect(client).to receive(:nil?) | |
UsesClient.call | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the memoized UsesClient.client value gets captured in UsesClient (the class object) and the double supplied to the first example pollutes the environment of the second example