Class: GData::Client::Contacts
- Inherits:
-
Object
- Object
- GData::Client::Contacts
- Defined in:
- lib/gmail_contacts/test_stub.rb
Overview
Extension that provides a stub for testing GmailContacts
See GmailContacts::TestStub for usage details
Instance Attribute Summary collapse
-
#stub_data ⇒ Object
Accessor for data the stub will return.
-
#stub_token ⇒ Object
Accessor for the stub AuthSub token.
-
#stub_urls ⇒ Object
Accessor for URLs the stub accessed.
Instance Method Summary collapse
-
#authsub_token=(token) ⇒ Object
Sets the authsub token to
token
, but does no HTTP requests. -
#get(url) ⇒ Object
Fetches
url
, records in in stub_urls, and returns data if there’s still data in stub_data, or raises an exception. -
#stub_reset ⇒ Object
Resets the stub to empty.
Instance Attribute Details
#stub_data ⇒ Object
Accessor for data the stub will return
207 208 209 |
# File 'lib/gmail_contacts/test_stub.rb', line 207 def stub_data @stub_data end |
#stub_token ⇒ Object
Accessor for the stub AuthSub token
212 213 214 |
# File 'lib/gmail_contacts/test_stub.rb', line 212 def stub_token @stub_token end |
#stub_urls ⇒ Object
Accessor for URLs the stub accessed
217 218 219 |
# File 'lib/gmail_contacts/test_stub.rb', line 217 def stub_urls @stub_urls end |
Instance Method Details
#authsub_token=(token) ⇒ Object
Sets the authsub token to token
, but does no HTTP requests
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/gmail_contacts/test_stub.rb', line 222 def authsub_token=(token) @stub_token = token auth_handler = Object.new auth_handler.instance_variable_set :@revoked, nil auth_handler.instance_variable_set :@upgraded, nil auth_handler.instance_variable_set :@token, token def auth_handler.revoke() @revoked = true end def auth_handler.revoked?() @revoked end def auth_handler.upgrade() @upgraded = true end def auth_handler.upgraded?() @upgraded end def auth_handler.token() [@token, (@revoked ? 'revoked' : nil), (@upgraded ? 'upgraded' : nil)].compact.join '-' end self.auth_handler = auth_handler end |
#get(url) ⇒ Object
Fetches url
, records in in stub_urls, and returns data if there’s still data in stub_data, or raises an exception
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/gmail_contacts/test_stub.rb', line 244 def get(url) @stub_urls << url raise 'stub data empty' if @stub_data.empty? data = @stub_data.shift return data.call if Proc === data res = Object.new def res.body() @data end res.instance_variable_set :@data, data res end |
#stub_reset ⇒ Object
Resets the stub to empty
261 262 263 264 |
# File 'lib/gmail_contacts/test_stub.rb', line 261 def stub_reset @stub_urls = [] @stub_data = [] end |