Forum: Ruby on Rails Help with stubbing Twitter::Client in Unit Test

Posted by Ben Densmore (bdensmore)
on 2013-01-17 15:16
(Received via mailing list)
Hi All,

I recently added some code to a model Object named EmailUser in my app 
so
that we can grab a users number of followers from their Twitter account.
The code works fine but my Unit Test is failing now. I'm fairly certain 
I
should stub this new code but have failed at all the attempts I've made.

The new code that I've added to this method is:

self.user.update_attributes( :twitter_follower_count =>
Twitter::Client.from_user( self.user ).user.followers_count )

The initial error from my test is "Twitter::BadRequest: GET
https://api.twitter.com/1/account/verify_credentials.json: 400: Bad
Authentication data" which makes sense because I'm not actually passing 
a
valid Twitter user from the test.

the from_user method is really just instantiating a new Client object 
with
twitter credentials:

    def self.from_user(user)
      self.new(:consumer_key => OauthConfig["twitter"].consumer_key,
               :consumer_secret => 
OauthConfig["twitter"].consumer_secret,
               :oauth_token => user.twitter_auth.token,
               :oauth_token_secret => user.twitter_auth.secret)
    end

I'm just really at a loss at how to get past this.

Does anyone have any wisdom they can throw my way? I've been stuck on 
this
pretty much all day and have yet to find a solution.

Thanks,
Ben
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.