在我的rails应用程序中,我有一个带有API调用的模块,我想为其编写rspec测试。你会写什么作为适当的测试?我已经读过不要将httparty与rspec结合使用,因为它非常慢,现在我不知道如何做到这一点。谢谢你的建议!
module BandsInTown
class API
attr_reader :artist_name, :info, :events
def initialize(artist_name)
@artist_name = artist_name
end
def artist_info
@info = fetch_data
end
def artist_events
@events = fetch_data 'events'
end
private
def fetch_data(endpoint = nil)
request_url = "http://api.bandsintown.com/artists/#{[@artist_name, endpoint].compact.join('/')}.json?api_version=2.0&app_id=AUTH_KEY"
resp = HTTParty.get(request_url)
return false if resp.code != 200
resp
end
end
end