【发布时间】:2011-11-28 21:00:21
【问题描述】:
我正在编写一个示例应用程序,使用 Devise + OmniAuth 进行登录,并使用 twitter gem 来获取用户名。我想添加一些集成测试,但我不知道如何处理 twitter gem。
这是我的用户模型(大部分逻辑都在这里):
def build_authentication(omniauth)
# If the provider is twitter, get additional information
# to build a user profile.
if omniauth['provider'] == 'twitter'
self.build_twitter(omniauth)
end
# now put the authentication in the database
authentications.build(:provider => omniauth['provider'],
:uid => omniauth['uid'],
:token => omniauth['credentials']['token'],
:secret => omniauth['credentials']['secret'])
end
def build_twitter(omniauth)
Twitter.configure do |config|
config.consumer_key = TWITTER_KEY
config.consumer_secret = TWITTER_SECRET
config.oauth_token = omniauth['credentials']['token']
config.oauth_token_secret = omniauth['credentials']['secret']
end
client = Twitter::Client.new
self.name = client.current_user.name
end
我已将以下内容添加到我的 spec_helper.rb 中,以便通过集成测试的登录部分:
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '12345',
'credentials' => {
'token' => '12345',
'secret' => '54321'
}
}
但我不知道如何测试使用 twitter gem 的 build_twitter 方法。任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: ruby twitter integration-testing capybara omniauth