Skip to content

Conversation

@timhall
Copy link
Member

@timhall timhall commented Nov 7, 2016

Evented approach

Events are being added to SpecSuite with the goal of providing more feedback during tests, adding an AfterEach approach for teardown (Fixes #9), and providing a foundation for extensibility (WBProxy and Scenario can be built much more cleanly on top of events).

The following events are fired by SpecSuite:

BeforeEach: Called before each spec in suite (setup)
Result(Spec): Called when spec has result
AfterEach: Called after each spec in suite (teardown)

Note: BeforeAll and AfterAll type events are best handled in the listener Initialize and Terminate.

Before

Public Function Specs() As SpecSuite
  Set Specs = New SpecSuite
  Specs.BeforeEach "BeforeEach"
  ' no Result or AfterEach

  With Specs.It("...")

  End With

  ' InlineRunner only reports results after suite has run
  ' (also, RunSuite is a misnomer since suite has already run at this point)
  InlineRunner.RunSuite Specs
End Sub

Public Sub BeforeEach()
  ' Run public module sub before each spec
End Sub

After

' ResultFixture.cls
'
Private WithEvents pSpecs as SpecSuite
Public Function ListenTo(Specs As SpecSuite)
  Set pSpecs = Specs
End Function

Private Sub pSpecs_BeforeEach()
  ' Setup fixture
End Sub

Private Sub pSpecs_AfterEach()
  ' Teardown fixture
End Sub

Private Sub pSpecs_Result()
  ' (used by reporters to show results as they happen)
End Sub

' Specs.bas
'
Public Function Specs() As SpecSuite
  Set Specs = New SpecSuite
  Set Reporter = New ImmediateReporter
  Set Fixture = New ResultFixture

  Reporter.ListenTo Specs
  Fixture.ListenTo Specs
  ' -> BeforeEach, Result, and AfterEach are called for each spec

  With Specs.It("...")
    ' -> BeforeEach
    ' .Expect...
  End With
  ' -> Result, AfterEach
End Function

Tasks

  • Remove old, undocumented/unmaintained code (WBProxy and Scenario). May add back later, especially since WBProxy will work much better with events
  • Switch from callbacks to events and add "after-each" event (no good way to do this before)
  • Switch InlineRunner and DisplayRunner to reporters (use events)

Closes #7

@timhall timhall changed the title [WIP] V2: Evented Approach V2: Evented Approach Dec 19, 2016
@timhall timhall merged commit f8b84e5 into master Dec 19, 2016
@timhall timhall deleted the v2 branch December 19, 2016 15:18
@mistresseve666
Copy link

👍 Love this update! Much cleaner interaction between the Specs and Reporters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AfterEach Plan: Update runners

3 participants