Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created February 24, 2015 17:37
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 JEG2/eb4dac4023a2c0acd110 to your computer and use it in GitHub Desktop.
Save JEG2/eb4dac4023a2c0acd110 to your computer and use it in GitHub Desktop.
Minitest stubbing is weird
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