Method: Whitestone.execute

Defined in:
lib/whitestone.rb

.executeObject

Whitestone.execute

Executes the current test scope recursively. A SCOPE is a collection of D blocks, and the contents of each D block is a TEST, comprising a description and a block of code. Because a test block may contain D statements within it, when a test block is run @current_scope is set to Scope.new so that newly-encountered tests can be added to it. That scope is then executed recursively. The invariant is this: @current_scope is the CURRENT scope to which tests may be added. At the end of ‘execute’, The per-test guts of this method have been extracted to execute_test so that the structure of execute is easier to see. execute_test contains lots of exception handling and comments.



521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/whitestone.rb', line 521

def execute
  @current_scope.before_all.each {|b| call b }     # Run pre-test setup
  @current_scope.tests.each do |test|              # Loop through tests
    @current_scope.before_each.each {|b| call b }  # Run per-test setup
    @tests.push test; @current_test = test

    execute_test(test)                             # Run the test

    @tests.pop; @current_test = @tests.last
    @current_scope.after_each.each {|b| call b }   # Run per-test teardown
  end
  @current_scope.after_all.each {|b| call b }      # Run post-test teardown
end