Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Last active February 28, 2020 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunichiIto/5a15d72d0eeb684dbdea to your computer and use it in GitHub Desktop.
Save JunichiIto/5a15d72d0eeb684dbdea to your computer and use it in GitHub Desktop.
# see also
# https://relishapp.com/rspec/rspec-mocks/v/3-9/docs/configuring-responses/block-implementation#simulating-a-transient-network-failure
describe 'Mock' do
specify do
foo = double
counter = 0
allow(foo).to receive(:bar) do
if counter.zero?
counter += 1
'abc'
else
raise 'This is test.'
end
end
expect(foo.bar).to eq 'abc'
expect{foo.bar}.to raise_error("This is test.")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment