faketwitter
faketwitter copied to clipboard
Factory goodness for twitter search responses wrapped in FakeWeb awesomeness.
h1. faketwitter
Factory goodness for twitter search responses wrapped in FakeWeb awesomeness.
irb(main):001:0> require 'faketwitter'
=> true
irb(main):002:0> require 'twitter_search'
=> true
irb(main):003:0> FakeTwitter.register_search("#cheese", {:results => [{:text => "#cheese is good"}]})
=> [#<:responder:0x19792c0>"{"results":[{"text":"#cheese is good","from_user":"jojo","to_user_id":null,"id":1,"from_user_id":1,"iso_language_code":"en","source":"<a href="http:\\/\\/twitter.com\\/">web<\\/a>","created_at":"Fri, 21 Aug 2009 09:31:27 +0000","profile_image_url":"http:\\/\\/s3.amazonaws.com\\/twitter_production\\/profile_images\\/1\\/photo.jpg"}],"since_id":0,"max_id":1,"results_per_page":15,"completed_in":0.008646,"page":1,"query":"%23cheese"}"}, method:get]
irb(main):004:0> TwitterSearch::Client.new('').query('#cheese')
=> [#<:tweet:0x196cef8 is good aug href="%22http://twitter.com/%22>web</a>%22,">]
irb(main):005:0>
For an example on how to use this in Cucumber see this "scenario":http://github.com/bmabey/codenote/blob/master/features/twitter_quiz.feature#L31-34 and the corresponding "step definitions":http://github.com/bmabey/codenote/blob/master/features/step_definitions/twitter_search_steps.rb#L1-12.
Documentation is lacking at this point, but there really isn't much to this gem. Take a look at the "code":http://github.com/bmabey/faketwitter/blob/master/lib/faketwitter.rb and the corresponding "RSpec examples":http://github.com/bmabey/faketwitter/blob/master/spec/faketwitter_spec.rb.