Last active
February 28, 2020 10:21
-
-
Save JunichiIto/5a15d72d0eeb684dbdea to your computer and use it in GitHub Desktop.
Sample spec for https://twitter.com/ms2sato/status/623787172999507969
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
# 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