Ever write an entire blog post, spend significant time on it, correct it, and eventually grow to love it, only to discover two months later you did things the hard way?
That’s what I’ve just discovered about my post Test Driving Module Methods. Turns out I’d been missing an important feature of RSpec, the and_yield
command. Whereas previously I had written static methods and monkey patched the SFTP, I simply could have written:
That lets me test that the session I’m passing in is getting the right parameters like any normal code, and is far cleaner. Frankly I should have added the feature to RSpec for my original solution—if it didn’t already exist. Too bad about my lovely blog post—I guess I’ll stick to push-ups.