我有以下代码
Class Client
def initialize(options = {})
@key = options['oauth_key']
@secret = options['oauth_secret']
@access_token_url = options['oauth_access_token_url']
@signature_method = options['signature_method']
@consumer = OAuth::Consumer.new(@key, @secret, {access_token_url: @access_token_url, signature_method: @signature_method})
end
def accounts_by_id(account_id)
response = query_account(account_id)
parse_json(response)
end
private
def access_token()
...
...
...
@access_token = @consumer.get_access_token(nil)
...
end
消费者被嘲讽如下
oauth_mock = mock('oauth')
OAuth::Consumer.stubs(:new).returns(oauth_mock)
:get_access_token with (nil)
然而,当我做一个模拟“oauth”时收到意外消息
GameSystem::Client.new(oauth_key: 'KEY',oauth_secret: 'SECRET',oauth_access_token_url: 'http://localhost').accounts_by_id("kk")
access_token 方法在 query_account 中被调用。有谁知道我也可以模拟它来克服这个问题。