Class: TestbeatContext
- Inherits:
-
Object
- Object
- TestbeatContext
- 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
- #body ⇒ Object
- #body? ⇒ Boolean
- #context_block_id ⇒ Object
- #form ⇒ Object
- #form? ⇒ Boolean
- #headers ⇒ Object
- #headers? ⇒ Boolean
-
#initialize(example) ⇒ TestbeatContext
constructor
reads context from RSpec example metadata.
- #logger ⇒ Object
- #method ⇒ Object
- #nop? ⇒ Boolean
- #port ⇒ Object
- #port? ⇒ Boolean
- #redirect ⇒ Object
- #redirect? ⇒ Boolean
- #reprovision? ⇒ Boolean
-
#resource ⇒ Object
Returns the REST resource if specified in context.
-
#rest? ⇒ Boolean
Returns true if the current context has a REST request specified.
- #to_s ⇒ Object
-
#unauthenticated? ⇒ Boolean
Returns true if requests will be made without authentication even if the node expects authentication.
- #unencrypted? ⇒ Boolean
- #user ⇒ Object
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
#body ⇒ Object
300 301 302 |
# File 'lib/rspec/spec_helper.rb', line 300 def body @rest_body end |
#body? ⇒ Boolean
304 305 306 |
# File 'lib/rspec/spec_helper.rb', line 304 def body? !!body end |
#context_block_id ⇒ Object
244 245 246 |
# File 'lib/rspec/spec_helper.rb', line 244 def context_block_id @context_block_id end |
#form ⇒ Object
308 309 310 |
# File 'lib/rspec/spec_helper.rb', line 308 def form @rest_form end |
#form? ⇒ Boolean
312 313 314 |
# File 'lib/rspec/spec_helper.rb', line 312 def form? !!form end |
#headers ⇒ Object
292 293 294 |
# File 'lib/rspec/spec_helper.rb', line 292 def headers @rest_headers end |
#headers? ⇒ Boolean
296 297 298 |
# File 'lib/rspec/spec_helper.rb', line 296 def headers? !!headers end |
#logger ⇒ Object
240 241 242 |
# File 'lib/rspec/spec_helper.rb', line 240 def logger $logger end |
#method ⇒ Object
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
253 254 255 |
# File 'lib/rspec/spec_helper.rb', line 253 def nop? !rest? end |
#port ⇒ Object
284 285 286 |
# File 'lib/rspec/spec_helper.rb', line 284 def port @rest_port end |
#port? ⇒ Boolean
288 289 290 |
# File 'lib/rspec/spec_helper.rb', line 288 def port? !!port end |
#redirect ⇒ Object
276 277 278 |
# File 'lib/rspec/spec_helper.rb', line 276 def redirect @rest_redirect end |
#redirect? ⇒ Boolean
280 281 282 |
# File 'lib/rspec/spec_helper.rb', line 280 def redirect? !!redirect end |
#reprovision? ⇒ Boolean
325 326 327 |
# File 'lib/rspec/spec_helper.rb', line 325 def reprovision? @reprovision end |
#resource ⇒ Object
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
249 250 251 |
# File 'lib/rspec/spec_helper.rb', line 249 def rest? @rest end |
#to_s ⇒ Object
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
317 318 319 |
# File 'lib/rspec/spec_helper.rb', line 317 def unauthenticated? unencrypted? || @unauthenticated end |
#unencrypted? ⇒ Boolean
321 322 323 |
# File 'lib/rspec/spec_helper.rb', line 321 def unencrypted? @unencrypted end |
#user ⇒ Object
257 258 259 |
# File 'lib/rspec/spec_helper.rb', line 257 def user @user end |