Created
February 24, 2015 17:37
-
-
Save JEG2/eb4dac4023a2c0acd110 to your computer and use it in GitHub Desktop.
Minitest stubbing is weird
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
require "minitest/autorun" | |
class Something | |
def dont_do_it | |
:oops | |
end | |
end | |
class RetryTest < Minitest::Test | |
def test_different_return_values | |
thing = Something.new | |
results = [42, RuntimeError.new("Boom!")] | |
body = -> { | |
result = results.shift | |
result.is_a?(Exception) ? raise(result) : result | |
} | |
thing.stub(:dont_do_it, body) do | |
assert_equal(42, thing.dont_do_it) | |
assert_raises(RuntimeError) do | |
thing.dont_do_it | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment