Skip to content

Commit

Permalink
Merge pull request #383 from eloycoto/master
Browse files Browse the repository at this point in the history
Added Duration on GinkgoTestDescription
  • Loading branch information
williammartin committed Jan 18, 2018
2 parents 6c46eb8 + 0747408 commit 528417e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ginkgo_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ type GinkgoTestDescription struct {
FileName string
LineNumber int

Failed bool
Failed bool
Duration time.Duration
}

//CurrentGinkgoTestDescripton returns information about the current running test.
Expand All @@ -169,6 +170,7 @@ func CurrentGinkgoTestDescription() GinkgoTestDescription {
FileName: subjectCodeLocation.FileName,
LineNumber: subjectCodeLocation.LineNumber,
Failed: summary.HasFailureState(),
Duration: summary.RunTime,
}
}

Expand Down
12 changes: 9 additions & 3 deletions internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Spec struct {

state types.SpecState
runTime time.Duration
startTime time.Time
failure types.SpecFailure
previousFailures bool
}
Expand Down Expand Up @@ -91,13 +92,18 @@ func (spec *Spec) Summary(suiteID string) *types.SpecSummary {
componentTexts[len(spec.containers)] = spec.subject.Text()
componentCodeLocations[len(spec.containers)] = spec.subject.CodeLocation()

runTime := spec.runTime
if runTime == 0 {
runTime = time.Since(spec.startTime)
}

return &types.SpecSummary{
IsMeasurement: spec.IsMeasurement(),
NumberOfSamples: spec.subject.Samples(),
ComponentTexts: componentTexts,
ComponentCodeLocations: componentCodeLocations,
State: spec.state,
RunTime: spec.runTime,
RunTime: runTime,
Failure: spec.failure,
Measurements: spec.measurementsReport(),
SuiteID: suiteID,
Expand All @@ -118,9 +124,9 @@ func (spec *Spec) Run(writer io.Writer) {
spec.previousFailures = true
}

startTime := time.Now()
spec.startTime = time.Now()
defer func() {
spec.runTime = time.Since(startTime)
spec.runTime = time.Since(spec.startTime)
}()

for sample := 0; sample < spec.subject.Samples(); sample++ {
Expand Down
7 changes: 7 additions & 0 deletions internal/spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ var _ = Describe("Spec", func() {
Ω(summary.RunTime).Should(BeNumerically(">=", 10*time.Millisecond))
})

It("should have a runtime which remains consistent after spec run", func() {
totalRunTime := summary.RunTime
Ω(totalRunTime).Should(BeNumerically(">=", 10*time.Millisecond))

Consistently(func() time.Duration { return spec.Summary("suite id").RunTime }).Should(Equal(totalRunTime))
})

It("should not be a measurement, or have a measurement summary", func() {
Ω(summary.IsMeasurement).Should(BeFalse())
Ω(summary.Measurements).Should(BeEmpty())
Expand Down
14 changes: 14 additions & 0 deletions internal/suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var _ = Describe("Suite", func() {
Ω(description.LineNumber).Should(BeNumerically(">", 50))
Ω(description.LineNumber).Should(BeNumerically("<", 150))
Ω(description.Failed).Should(BeFalse())
Ω(description.Duration).Should(BeNumerically(">", 0))
})

Measure("should run measurements", func(b Benchmarker) {
Expand Down Expand Up @@ -152,6 +153,19 @@ var _ = Describe("Suite", func() {
"AfterSuite",
}))
})
Context("when in an AfterEach block", func() {
AfterEach(func() {
description := CurrentGinkgoTestDescription()
Ω(description.IsMeasurement).Should(BeFalse())
Ω(description.FileName).Should(ContainSubstring("suite_test.go"))
Ω(description.Failed).Should(BeFalse())
Ω(description.Duration).Should(BeNumerically(">", 0))
})

It("still provides information about the current test", func() {
Ω(true).To(BeTrue())
})
})

Context("when told to randomize all specs", func() {
BeforeEach(func() {
Expand Down

0 comments on commit 528417e

Please sign in to comment.