Class: Spectre::SpecContext
Instance Attribute Summary collapse
-
#__after_blocks ⇒ Object
readonly
Returns the value of attribute __after_blocks.
-
#__before_blocks ⇒ Object
readonly
Returns the value of attribute __before_blocks.
-
#__desc ⇒ Object
readonly
Returns the value of attribute __desc.
-
#__parent ⇒ Object
readonly
Returns the value of attribute __parent.
-
#__setup_blocks ⇒ Object
readonly
Returns the value of attribute __setup_blocks.
-
#__subject ⇒ Object
readonly
Returns the value of attribute __subject.
-
#__teardown_blocks ⇒ Object
readonly
Returns the value of attribute __teardown_blocks.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #context(desc = nil, &block) ⇒ Object
-
#initialize(subject, desc = nil, parent = nil) ⇒ SpecContext
constructor
A new instance of SpecContext.
- #it(desc, tags: [], with: [], &block) ⇒ Object
- #setup(&block) ⇒ Object
- #teardown(&block) ⇒ Object
Methods inherited from DslClass
#_evaluate, #_execute, #method_missing
Constructor Details
#initialize(subject, desc = nil, parent = nil) ⇒ SpecContext
Returns a new instance of SpecContext.
351 352 353 354 355 356 357 358 359 360 |
# File 'lib/spectre.rb', line 351 def initialize subject, desc=nil, parent=nil @__subject = subject @__desc = desc @__parent = parent @__before_blocks = [] @__after_blocks = [] @__setup_blocks = [] @__teardown_blocks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Spectre::DslClass
Instance Attribute Details
#__after_blocks ⇒ Object (readonly)
Returns the value of attribute __after_blocks.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __after_blocks @__after_blocks end |
#__before_blocks ⇒ Object (readonly)
Returns the value of attribute __before_blocks.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __before_blocks @__before_blocks end |
#__desc ⇒ Object (readonly)
Returns the value of attribute __desc.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __desc @__desc end |
#__parent ⇒ Object (readonly)
Returns the value of attribute __parent.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __parent @__parent end |
#__setup_blocks ⇒ Object (readonly)
Returns the value of attribute __setup_blocks.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __setup_blocks @__setup_blocks end |
#__subject ⇒ Object (readonly)
Returns the value of attribute __subject.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __subject @__subject end |
#__teardown_blocks ⇒ Object (readonly)
Returns the value of attribute __teardown_blocks.
349 350 351 |
# File 'lib/spectre.rb', line 349 def __teardown_blocks @__teardown_blocks end |
Instance Method Details
#after(&block) ⇒ Object
372 373 374 |
# File 'lib/spectre.rb', line 372 def after &block @__after_blocks << block end |
#before(&block) ⇒ Object
368 369 370 |
# File 'lib/spectre.rb', line 368 def before &block @__before_blocks << block end |
#context(desc = nil, &block) ⇒ Object
392 393 394 395 |
# File 'lib/spectre.rb', line 392 def context desc=nil, &block ctx = SpecContext.new(@__subject, desc, self) ctx._evaluate &block end |
#it(desc, tags: [], with: [], &block) ⇒ Object
362 363 364 365 366 |
# File 'lib/spectre.rb', line 362 def it desc, tags: [], with: [], &block spec_file, line = get_call_location() @__subject.add_spec(desc, , with, block, self, spec_file, line) end |
#setup(&block) ⇒ Object
376 377 378 379 380 381 382 |
# File 'lib/spectre.rb', line 376 def setup &block name = "#{@__subject.name}-setup-#{@__setup_blocks.count+1}" spec_file, line = get_call_location() setup_ctx = SpecContext.new(@__subject, 'setup', self) @__setup_blocks << Spec.new(name, @__subject, 'setup', [], nil, block, setup_ctx, spec_file, line) end |
#teardown(&block) ⇒ Object
384 385 386 387 388 389 390 |
# File 'lib/spectre.rb', line 384 def teardown &block name = "#{@__subject.name}-teardown-#{@__teardown_blocks.count+1}" spec_file, line = get_call_location() teardown_ctx = SpecContext.new(@__subject, 'teardown', self) @__teardown_blocks << Spec.new(name, @__subject, 'teardown', [], nil, block, teardown_ctx, spec_file, line) end |