Verifying doubles came out in RSpec 3, and it’s something that always sounded like such a brilliant yet obvious idea - make sure methods you stub actually exist. One friend in particular really stressed how many times this could have saved his tests from false positives. Sure, I thought, but usually I’d just modify something in the real code or modify the expectation to make sure it broke/worked in predictable ways, and move on. Then along came the perfect scenario while working on a little side project.
Below is the original spec and the corresponding controller method it's testing. (Things aren't especially DRY and a bunch of expectations are crammed into a single test to make things more explicit for this post.) # spec it 'sends the admin a message about a new order' do controller.stub(:params).and_return(fake_full_params) expect(AdminMailer).to receive(:order_confirmation).with(fake_email_params).and_return(Mail::Message.new) allow_any_instance_of(Mail::Message).…
January almost passed without an inaugural post for the year, and clearly the months quickly turn into years! Here's to sticking with New Year's resolutions and polishing up many drafts waiting to see the light of screens 🥂 To start gaining momentum again, below are a few topics and technologies I'd like to spend more time with in the coming year.
Here's to keeping up with one New Year's resolution!
Documenting and collecting resources has always helped me learn, not only for the occasional refresher but also a reminder of the progress I'm making (or not). For some of us, giving oneself a pat on the back every now and then isn't as forthcoming as it should be. Amidst the countless blog posts, tutorials, books, projects and rabbit holes, I'd like to begin collecting them a bit better. Just kidding, I'm kind of an information pack rat as anyone who's seen the multiple browsers on my computer, each with multiple windows containing dozens of tab, can attest. I'd like to start sharing more as a way to help others and help keep myself organized and focused. With that, here's the first This Month I Learned.