Last active
August 29, 2015 13:57
-
-
Save jsgarvin/9573255 to your computer and use it in GitHub Desktop.
Name your MiniTest::Mock for more descriptive errors.
This file contains hidden or 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
MiniTest::Mock errors are especially vague, particularly when you need more than one mock in your test. | |
To improve things slightly, add this to the bottom of your test_helper... | |
module MiniTest | |
class NamedMock < Mock | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
super() | |
end | |
def method_missing(sym, *args, &block) | |
super(sym, *args, &block) | |
rescue NoMethodError, MockExpectationError, ArgumentError => error | |
raise(error.class, "#{error.message} (mock:#{name})") | |
end | |
end | |
end | |
Then use NamedMock instead of Mock... | |
let(:mock_foobar) { MiniTest::NamedMock.new('foobar') } | |
let(:mock_shazam) { MiniTest::NamedMock.new('shazam') } | |
And, Voilà... | |
NoMethodError: unmocked method :frozen?, expected one of [] (mock:shazam) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment