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.metadata[: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.metadata[:example_group][:location]}: #{@rest ? @method : ''} #{@resource} #{@unencrypted ? '[unencrypted] ' : ' '}#{@unauthenticated ? '[unauthenticated] ' : ' '}" }
end

Instance Method Details

#bodyObject



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

def body
  @rest_body
end

#body?Boolean

Returns:

  • (Boolean)


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

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



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

def form
  @rest_form
end

#form?Boolean

Returns:

  • (Boolean)


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

def form?
  !!form
end

#headersObject



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

def headers
  @rest_headers
end

#headers?Boolean

Returns:

  • (Boolean)


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

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



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

def port
  @rest_port
end

#port?Boolean

Returns:

  • (Boolean)


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

def port?
  !!port
end

#reprovision?Boolean

Returns:

  • (Boolean)


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

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



321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/rspec/spec_helper.rb', line 321

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)


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

def unauthenticated?
  unencrypted? || @unauthenticated
end

#unencrypted?Boolean

Returns:

  • (Boolean)


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

def unencrypted?
  @unencrypted
end

#userObject



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

def user
  @user
end