Skip to content

Commit

Permalink
Merge pull request #14 from VBA-tools/v2
Browse files Browse the repository at this point in the history
V2: Evented Approach
  • Loading branch information
timhall authored Dec 19, 2016
2 parents 69a2dd7 + 1696e87 commit f8b84e5
Show file tree
Hide file tree
Showing 23 changed files with 843 additions and 2,318 deletions.
536 changes: 0 additions & 536 deletions build/dev.vbs

This file was deleted.

Binary file removed examples/Excel-TDD - Example - Inline.xlsm
Binary file not shown.
Binary file removed examples/Excel-TDD - Example - Runner.xlsm
Binary file not shown.
Binary file removed examples/Excel-TDD - Example - Test Workbook.xlsm
Binary file not shown.
Binary file modified specs/Excel-TDD - Specs.xlsm
Binary file not shown.
32 changes: 0 additions & 32 deletions specs/SpecSuiteSpecs.bas

This file was deleted.

36 changes: 36 additions & 0 deletions specs/Specs_Fixture.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Specs_Fixture"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private WithEvents pSuite As SpecSuite
Attribute pSuite.VB_VarHelpID = -1

Public BeforeEachCallCount As Long
Public ResultCalls As Collection
Public AfterEachCallCount As Long

Public Sub ListenTo(Suite As SpecSuite)
Set pSuite = Suite
End Sub

Private Sub pSuite_BeforeEach()
BeforeEachCallCount = BeforeEachCallCount + 1
End Sub

Private Sub pSuite_Result(Spec As SpecDefinition)
Me.ResultCalls.Add Spec
End Sub

Private Sub pSuite_AfterEach()
AfterEachCallCount = AfterEachCallCount + 1
End Sub

Private Sub Class_Initialize()
Set Me.ResultCalls = New Collection
End Sub

35 changes: 18 additions & 17 deletions specs/SpecDefinitionSpecs.bas → specs/Specs_SpecDefinition.bas
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
Attribute VB_Name = "SpecDefinitionSpecs"
Attribute VB_Name = "Specs_SpecDefinition"
Public Function Specs() As SpecSuite
Set Specs = New SpecSuite
Specs.Description = "SpecDefinition"

Dim Reporter As New ImmediateReporter
Reporter.ListenTo Specs

Dim TestSuite As New SpecSuite
Dim Definition As SpecDefinition
Dim Expectation As SpecExpectation

With Specs.It("should pass if all expectations pass")
Set Definition = TestSuite.It("should pass")
With Definition
.Expect("A").ToEqual "A"
.Expect(2).ToEqual 2
.Expect("pass").ToEqual "pass"
End With
.Expect(Definition.Result).ToEqual SpecResult.Pass

.Expect(Definition.Result).ToEqual SpecResultType.Pass
End With

With Specs.It("should fail if any expectation fails")
Set Definition = TestSuite.It("should fail")
With Definition
.Expect("A").ToEqual "A"
.Expect(2).ToEqual 2
.Expect("pass").ToEqual "fail"
End With
.Expect(Definition.Result).ToEqual SpecResult.Fail

.Expect(Definition.Result).ToEqual SpecResultType.Fail
End With

With Specs.It("should contain collection of failed expectations")
Set Definition = TestSuite.It("should fail")
With Definition
Expand All @@ -37,20 +40,18 @@ Public Function Specs() As SpecSuite
.Expect("pass").ToEqual "fail"
.Expect(True).ToEqual False
End With
.Expect(Definition.Result).ToEqual SpecResult.Fail

.Expect(Definition.Result).ToEqual SpecResultType.Fail
.Expect(Definition.FailedExpectations(1).Actual).ToEqual 2
.Expect(Definition.FailedExpectations(1).Result).ToEqual ExpectResult.Fail
.Expect(Definition.FailedExpectations(1).Passed).ToEqual False
.Expect(Definition.FailedExpectations(2).Actual).ToEqual "pass"
.Expect(Definition.FailedExpectations(2).Result).ToEqual ExpectResult.Fail
.Expect(Definition.FailedExpectations(2).Passed).ToEqual False
.Expect(Definition.FailedExpectations(3).Actual).ToEqual True
.Expect(Definition.FailedExpectations(3).Result).ToEqual ExpectResult.Fail
.Expect(Definition.FailedExpectations(3).Passed).ToEqual False
End With

With Specs.It("should be pending if there are no expectations")
Set Definition = TestSuite.It("pending")
.Expect(Definition.Result).ToEqual SpecResult.Pending
.Expect(Definition.Result).ToEqual SpecResultType.Pending
End With

InlineRunner.RunSuite Specs
End Function
35 changes: 30 additions & 5 deletions specs/SpecExpectationSpecs.bas → specs/Specs_SpecExpectation.bas
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Attribute VB_Name = "SpecExpectationSpecs"
Attribute VB_Name = "Specs_SpecExpectation"
Public Function Specs() As SpecSuite
Dim Expectation As SpecExpectation

Set Specs = New SpecSuite
Specs.Description = "SpecExpectation"

Dim Reporter As New ImmediateReporter
Reporter.ListenTo Specs

With Specs.It("ToEqual/ToNotEqual")
.Expect("A").ToEqual "A"
.Expect(2).ToEqual 2
Expand Down Expand Up @@ -156,11 +161,31 @@ Public Function Specs() As SpecSuite
End With

With Specs.It("RunMatcher")
.Expect(100).RunMatcher "SpecExpectationSpecs.ToBeWithin", "to be within", 90, 110
.Expect(Nothing).RunMatcher "SpecExpectationSpecs.ToBeNothing", "to be nothing"
.Expect(100).RunMatcher "Specs_SpecExpectation.ToBeWithin", "to be within", 90, 110
.Expect(Nothing).RunMatcher "Specs_SpecExpectation.ToBeNothing", "to be nothing"
End With

InlineRunner.RunSuite Specs
With Specs.It("should set Passed")
Set Expectation = New SpecExpectation
Expectation.Actual = 4
Expectation.ToEqual 4

.Expect(Expectation.Passed).ToEqual True

Expectation.ToEqual 3
.Expect(Expectation.Passed).ToEqual False
End With

With Specs.It("should set FailureMessage")
Set Expectation = New SpecExpectation
Expectation.Actual = 4

Expectation.ToEqual 4
.Expect(Expectation.FailureMessage).ToEqual ""

Expectation.ToEqual 3
.Expect(Expectation.FailureMessage).ToEqual "Expected 4 to equal 3"
End With
End Function

Public Function ToBeWithin(Actual As Variant, Args As Variant) As Variant
Expand All @@ -179,7 +204,7 @@ Public Function ToBeWithin(Actual As Variant, Args As Variant) As Variant
End Function

Public Function ToBeNothing(Actual As Variant) As Variant
If IsObject(Actual) Then
If VBA.IsObject(Actual) Then
If Actual Is Nothing Then
ToBeNothing = True
Else
Expand Down
79 changes: 79 additions & 0 deletions specs/Specs_SpecSuite.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Attribute VB_Name = "Specs_SpecSuite"
Public Function Specs() As SpecSuite
Dim Suite As SpecSuite

Set Specs = New SpecSuite
Specs.Description = "SpecSuite"

Dim Reporter As New ImmediateReporter
Reporter.ListenTo Specs

Dim Fixture As New Specs_Fixture
Fixture.ListenTo Specs

With Specs.It("should fire BeforeEach event", "id")
.Expect(Fixture.BeforeEachCallCount).ToEqual 1
.Expect(1 + 1).ToEqual 2
End With

With Specs.It("should fire Result event")
.Expect(Fixture.ResultCalls(1).Description).ToEqual "should fire BeforeEach event"
.Expect(Fixture.ResultCalls(1).Result).ToEqual SpecResultType.Pass
.Expect(Fixture.ResultCalls(1).Expectations.Count).ToEqual 2
.Expect(Fixture.ResultCalls(1).Id).ToEqual "id"
End With

With Specs.It("should fire AfterEach event")
.Expect(Fixture.AfterEachCallCount).ToEqual 2
End With

With Specs.It("should store specs")
Set Suite = New SpecSuite
With Suite.It("(pass)", "(1)")
.Expect(4).ToEqual 4
End With
With Suite.It("(fail)", "(2)")
.Expect(4).ToEqual 3
End With
With Suite.It("(pending)", "(3)")
End With

.Expect(Suite.Specs.Count).ToEqual 3
.Expect(Suite.PassedSpecs.Count).ToEqual 1
.Expect(Suite.FailedSpecs.Count).ToEqual 1
.Expect(Suite.PendingSpecs.Count).ToEqual 1

.Expect(Suite.PassedSpecs(1).Description).ToEqual "(pass)"
.Expect(Suite.FailedSpecs(1).Description).ToEqual "(fail)"
.Expect(Suite.PendingSpecs(1).Description).ToEqual "(pending)"
End With

With Specs.It("should have overall result")
Set Suite = New SpecSuite

.Expect(Suite.Result).ToEqual SpecResultType.Pending

With Suite.It("(pending)", "(1)")
End With

.Expect(Suite.Result).ToEqual SpecResultType.Pending

With Suite.It("(pass)", "(2)")
.Expect(4).ToEqual 4
End With

.Expect(Suite.Result).ToEqual SpecResultType.Pass

With Suite.It("(fail)", "(3)")
.Expect(4).ToEqual 3
End With

.Expect(Suite.Result).ToEqual SpecResultType.Fail

With Suite.It("(pass)", "(4)")
.Expect(4).ToEqual 4
End With

.Expect(Suite.Result).ToEqual SpecResultType.Fail
End With
End Function
Loading

0 comments on commit f8b84e5

Please sign in to comment.