次の単純なクラスとHTTPartyメソッドがあります。
class Token
require 'httparty'
include HTTParty
base_uri 'https://<some url>'
headers 'auth_user' => 'user'
headers 'auth_pass' => 'password'
headers 'auth_appkey' => 'app_key'
def self.getToken
response = get('/auth/token')
@token = response['auth']['token']
end
end
Railsコンソールでメソッドを呼び出してトークンを正常に取り戻すことができるので、機能することはわかっています。
上記のコードをRSpecでテストするにはどうすればよいですか?
それで私の最初の刺し傷は機能しません:
describe Token do
before do
HTTParty.base_uri 'https://<some url>'
HTTParty.headers 'auth_user' => 'user'
HTTParty.headers 'auth_pass' => 'password'
HTTParty.headers 'auth_appkey' => 'app_key'
end
it "gets a token" do
HTTParty.get('auth/authenticate')
response['auth']['token'].should_not be_nil
end
end
それは言う:NoMethodError: undefined method 'base_uri' for HTTParty:Module
..。
ありがとう!