Class: TestbeatContext
- Inherits:
-
Object
- Object
- TestbeatContext
- 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
- #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
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
#body ⇒ Object
264 265 266 |
# File 'lib/spec_helper.rb', line 264 def body @rest_body end |
#body? ⇒ Boolean
268 269 270 |
# File 'lib/spec_helper.rb', line 268 def body? !!body end |
#context_block_id ⇒ Object
224 225 226 |
# File 'lib/spec_helper.rb', line 224 def context_block_id @context_block_id end |
#form ⇒ Object
272 273 274 |
# File 'lib/spec_helper.rb', line 272 def form @rest_form end |
#form? ⇒ Boolean
276 277 278 |
# File 'lib/spec_helper.rb', line 276 def form? !!form end |
#headers ⇒ Object
256 257 258 |
# File 'lib/spec_helper.rb', line 256 def headers @rest_headers end |
#headers? ⇒ Boolean
260 261 262 |
# File 'lib/spec_helper.rb', line 260 def headers? !!headers end |
#logger ⇒ Object
220 221 222 |
# File 'lib/spec_helper.rb', line 220 def logger $logger end |
#method ⇒ Object
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
233 234 235 |
# File 'lib/spec_helper.rb', line 233 def nop? !rest? end |
#reprovision? ⇒ Boolean
289 290 291 |
# File 'lib/spec_helper.rb', line 289 def reprovision? @reprovision end |
#resource ⇒ Object
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
229 230 231 |
# File 'lib/spec_helper.rb', line 229 def rest? @rest end |
#to_s ⇒ Object
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
281 282 283 |
# File 'lib/spec_helper.rb', line 281 def unauthenticated? unencrypted? || @unauthenticated end |
#unencrypted? ⇒ Boolean
285 286 287 |
# File 'lib/spec_helper.rb', line 285 def unencrypted? @unencrypted end |
#user ⇒ Object
237 238 239 |
# File 'lib/spec_helper.rb', line 237 def user @user end |