Class: TestbeatContext

Inherits:
Object
  • Object
show all
Defined in:
lib/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



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/spec_helper.rb', line 202

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



264
265
266
# File 'lib/spec_helper.rb', line 264

def body
  @rest_body
end

#body?Boolean

Returns:

  • (Boolean)


268
269
270
# File 'lib/spec_helper.rb', line 268

def body?
  !!body
end

#context_block_idObject



224
225
226
# File 'lib/spec_helper.rb', line 224

def context_block_id
  @context_block_id
end

#formObject



272
273
274
# File 'lib/spec_helper.rb', line 272

def form
  @rest_form
end

#form?Boolean

Returns:

  • (Boolean)


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

def form?
  !!form
end

#headersObject



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

def headers
  @rest_headers
end

#headers?Boolean

Returns:

  • (Boolean)


260
261
262
# File 'lib/spec_helper.rb', line 260

def headers?
  !!headers
end

#loggerObject



220
221
222
# File 'lib/spec_helper.rb', line 220

def logger
  $logger
end

#methodObject



249
250
251
252
253
254
# File 'lib/spec_helper.rb', line 249

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

#nop?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/spec_helper.rb', line 233

def nop?
  !rest?
end

#reprovision?Boolean

Returns:

  • (Boolean)


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

def reprovision?
  @reprovision
end

#resourceObject

Returns the REST resource if specified in context



242
243
244
245
246
247
# File 'lib/spec_helper.rb', line 242

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)


229
230
231
# File 'lib/spec_helper.rb', line 229

def rest?
  @rest
end

#to_sObject



293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/spec_helper.rb', line 293

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)


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

def unauthenticated?
  unencrypted? || @unauthenticated
end

#unencrypted?Boolean

Returns:

  • (Boolean)


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

def unencrypted?
  @unencrypted
end

#userObject



237
238
239
# File 'lib/spec_helper.rb', line 237

def user
  @user
end