Testing Twitter notifications
In La Coctelera we offer to the users the possibility to automatically update their Twitter status with a link to the last post or the last published photos (shortly :).
The tests for notifying twitter are very easy if you use the powerful Mocha (in the beginning we tried to simulate the Twitter::Base class, but it gets a little bit more complicated):
def test_an_activity_of_new_photos_notify_in_twitter
User.any_instance.stubs(:premium_role?).returns(true)
User.any_instance.stubs(:twitter_photos?).returns(true)
User.any_instance.stubs(:twitter_username).returns('wadus')
User.any_instance.stubs(:twitter_password).returns('wadus')
photo = photos(:photo_blat_1)
a = activities(:activity1)
Twitter::Base.any_instance.expects(:update).with("He subido una nueva foto a La Coctelera: #{photo.guid}").once
a.notify_in_twitter
end
If you don't know Mocha you should learn to use it, in other case, you can ignore this post :)
Also, I recommend you to watch this old screencast about Mocha
