minitest-stub_any_instance will define a method stub on any instance of a class for the duration of a block.
String.stub_any_instance(:length, 42) do
assert_equal "hello".length, 42 # this assertion passes!
end
@nashby_ actually extracted the code from SimpleForm to do the job, and
suggested it be included in MiniTest itself. But that didn't fly, so I packaged it as a plugin/gem.
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
There are no comments for this entry yet.
Leave a comment