Published on August 19, 2014 by Michael Yagudaev
rspec you can typically call the
stub method to stub something out. However, this method only works inside an
example or a
before(:each) block. Try using rspec stubs anywhere else and you get the following error message
The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported.
What if you wanted to temporarily stub out one object inside a
before(:all) (since you like those fast test, don’t you 😉 or globally for the entire test suite for say disabling image processing. How would you do that?
Simple, Ruby has this magic word called
metaprogramming to rescue us.
Instead of doing:
image = Image.new
image = Image.new
That is it. We just overwrote the definition of the process method for only this one image instance. No side-effect or stub-code leakage will occur here.
Published on September 12, 2013 by Michael Yagudaev
My roommate (Anton Kishchenko) and I started working on a marketplace to help event organizers find venues called 0idle. After initial market research, we received great feedback and decided to start building the product. I decided to start building it in Rails, since I have worked with it before, knowing that it is a great framework.
Published on June 18, 2013 by Michael Yagudaev
Rails AssetPipeline is a great feautre. However, sometimes it gets really confusing as to where a resource is located. Imagine you had to upgrade a basic library like jQuery UI on an older Rails project. How would you go about doing that if you can’t simply find it as a gem in the gemfile and can’t seem to find it anywhere in the project.
Published on July 13, 2012 by Michael Yagudaev
As you may have noticed the site has a fresh new look now. But it is more than that, much more. I now have a more focused approach to the content and a simpler website to navigate through.
Many of my personal heroes — including the super heroes listed on the bottom — have an incredible sense of focus, which contributes in no small part to their success. I have been hearing about the need to focus a lot lately. More…