Class: TestbeatContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/spec_helper.rb

Overview

Context has getters for test case parameters that can be digged out from Rspec examples, initialized for each “it”

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ TestbeatContext

reads context from RSpec example metadata



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rspec/spec_helper.rb', line 222

def initialize(example)
  # enables de-duplication of requests within describe, using tostring to compare becase == wouldn't work
  @context_block_id = "#{example.[:example_group][:block]}"

  # defaults
  @user = { :username => 'testuser', :password => 'testpassword' }
  @unencrypted = false
  @unauthenticated = false
  @rest = false
  @reprovision = false

  # actual context
  parse_example_group(example.[:example_group], 0)

  @context_block_id_short = /([^\/]+)>$/.match(@context_block_id)[1]
  logger.info{ "#{example.[:example_group][:location]}: #{@rest ? @method : ''} #{@resource} #{@unencrypted ? '[unencrypted] ' : ' '}#{@unauthenticated ? '[unauthenticated] ' : ' '}" }
end

Instance Method Details

#bodyObject



300
301
302
# File 'lib/rspec/spec_helper.rb', line 300

def body
  @rest_body
end

#body?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/rspec/spec_helper.rb', line 304

def body?
  !!body
end

#context_block_idObject



244
245
246
# File 'lib/rspec/spec_helper.rb', line 244

def context_block_id
  @context_block_id
end

#formObject



308
309
310
# File 'lib/rspec/spec_helper.rb', line 308

def form
  @rest_form
end

#form?Boolean

Returns:

  • (Boolean)


312
313
314
# File 'lib/rspec/spec_helper.rb', line 312

def form?
  !!form
end

#headersObject



292
293
294
# File 'lib/rspec/spec_helper.rb', line 292

def headers
  @rest_headers
end

#headers?Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/rspec/spec_helper.rb', line 296

def headers?
  !!headers
end

#loggerObject



240
241
242
# File 'lib/rspec/spec_helper.rb', line 240

def logger
  $logger
end

#methodObject



269
270
271
272
273
274
# File 'lib/rspec/spec_helper.rb', line 269

def method
  if not rest?
    return nil
  end
  @method
end

#nop?Boolean

Returns:

  • (Boolean)


253
254
255
# File 'lib/rspec/spec_helper.rb', line 253

def nop?
  !rest?
end

#portObject



284
285
286
# File 'lib/rspec/spec_helper.rb', line 284

def port
  @rest_port
end

#port?Boolean

Returns:

  • (Boolean)


288
289
290
# File 'lib/rspec/spec_helper.rb', line 288

def port?
  !!port
end

#redirectObject



276
277
278
# File 'lib/rspec/spec_helper.rb', line 276

def redirect
  @rest_redirect
end

#redirect?Boolean

Returns:

  • (Boolean)


280
281
282
# File 'lib/rspec/spec_helper.rb', line 280

def redirect?
  !!redirect
end

#reprovision?Boolean

Returns:

  • (Boolean)


325
326
327
# File 'lib/rspec/spec_helper.rb', line 325

def reprovision?
  @reprovision
end

#resourceObject

Returns the REST resource if specified in context



262
263
264
265
266
267
# File 'lib/rspec/spec_helper.rb', line 262

def resource
  if not rest?
    return nil
  end
  @resource
end

#rest?Boolean

Returns true if the current context has a REST request specified

Returns:

  • (Boolean)


249
250
251
# File 'lib/rspec/spec_helper.rb', line 249

def rest?
  @rest
end

#to_sObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/rspec/spec_helper.rb', line 329

def to_s
  s = "Testbeat context"
  if rest?
    s += " #{method} #{resource}"
  else
    s += " non-REST"
  end
  if @unencrypted
    s += " unencrypted"
  elsif @unauthenticated
    s += " unauthenticated"
  end
  s
end

#unauthenticated?Boolean

Returns true if requests will be made without authentication even if the node expects authentication

Returns:

  • (Boolean)


317
318
319
# File 'lib/rspec/spec_helper.rb', line 317

def unauthenticated?
  unencrypted? || @unauthenticated
end

#unencrypted?Boolean

Returns:

  • (Boolean)


321
322
323
# File 'lib/rspec/spec_helper.rb', line 321

def unencrypted?
  @unencrypted
end

#userObject



257
258
259
# File 'lib/rspec/spec_helper.rb', line 257

def user
  @user
end