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
- #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.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
#body ⇒ Object
284 285 286 |
# File 'lib/rspec/spec_helper.rb', line 284 def body @rest_body end |
#body? ⇒ Boolean
288 289 290 |
# File 'lib/rspec/spec_helper.rb', line 288 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
292 293 294 |
# File 'lib/rspec/spec_helper.rb', line 292 def form @rest_form end |
#form? ⇒ Boolean
296 297 298 |
# File 'lib/rspec/spec_helper.rb', line 296 def form? !!form end |
#headers ⇒ Object
276 277 278 |
# File 'lib/rspec/spec_helper.rb', line 276 def headers @rest_headers end |
#headers? ⇒ Boolean
280 281 282 |
# File 'lib/rspec/spec_helper.rb', line 280 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 |
#reprovision? ⇒ Boolean
309 310 311 |
# File 'lib/rspec/spec_helper.rb', line 309 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
313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/rspec/spec_helper.rb', line 313 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
301 302 303 |
# File 'lib/rspec/spec_helper.rb', line 301 def unauthenticated? unencrypted? || @unauthenticated end |
#unencrypted? ⇒ Boolean
305 306 307 |
# File 'lib/rspec/spec_helper.rb', line 305 def unencrypted? @unencrypted end |
#user ⇒ Object
257 258 259 |
# File 'lib/rspec/spec_helper.rb', line 257 def user @user end |