The gem I'm using to integrate OpenTok in my Rails application is at: https://github.com/opentok/Opentok-Ruby-SDK. I based the core of the application on this example: http://www.tokbox.com/blog/building-a-video-party-app-with-ruby-on-rails.
In the relevant part of code, I'm creating an @opentok object in the config_opentok method:
def config_opentok
if @api_key.nil? or @api_secret.nil?
if Rails.env.development?
@api_key = API_KEY
@api_secret = API_SECRET
else
@api_key = ENV['API_KEY']
@api_secret = ENV['API_SECRET']
end
end
if @opentok.nil?
@opentok = OpenTok::OpenTokSDK.new(@api_key, @api_secret)
end
end
And I'm creating a session with the following code:
config_opentok
if Rails.env.development?
session = @opentok.create_session('localhost')
else
session = @opentok.create_session(request.remote_addr)
end
The trouble is, the create_session seems to throw an error
SocketError: getaddrinfo: nodename nor servname provided, or not known
whenever I run my Rspec tests without an internet connection. So I'd like to stub that method so that it returns just a hash {:sessionId => 1}. But I'm having trouble figuring out how to stub the method. I can't just stub the OpenTok module or the OpenTok::OpenTokSDK class. How would I go about stubbing the create_session method?