https://github.com/joke/spock-outputcapture
OutputCapture for the Spock Framework
https://github.com/joke/spock-outputcapture
output-checking spock-extension spock-framework
Last synced: 5 months ago
JSON representation
OutputCapture for the Spock Framework
- Host: GitHub
- URL: https://github.com/joke/spock-outputcapture
- Owner: joke
- License: apache-2.0
- Created: 2020-05-30T12:51:27.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2025-08-11T22:14:55.000Z (11 months ago)
- Last Synced: 2025-08-12T00:20:17.559Z (11 months ago)
- Topics: output-checking, spock-extension, spock-framework
- Language: Java
- Size: 276 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.adoc
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.adoc
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
= `spock-outputcapture`
:icons: font
image:https://github.com/joke/spock-deepmock/workflows/build/badge.svg[]
image:https://img.shields.io/github/license/joke/spring-factory[GitHub]
image:https://img.shields.io/maven-central/v/io.github.joke/spock-outputcapture?label=latest%20version[link=https://search.maven.org/artifact/io.github.joke/spock-outputcapture]
image:https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg[link=https://conventionalcommits.org]
image:https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit[pre-commit, link=https://github.com/pre-commit/pre-commit]
`spock-outputcapture` captures `System.out` and `System.err` in order to be verified during tests written with the http://spockframework.org/[Spock Framework].
It is intended as groovier replacement for https://spring.io/projects/spring-boot[Spring Boot] `OutputCaptureRule`,
which has been superseed by the `OutputCaptureExtension` that on the other hand is not working with Spock.
* Groovy syntax
* Captures both `System.out` and `System.err`
* Captures logs of the entire Spec via
** `@Share @OutputCapture globalLogs`
* Captures logs per Test
** `@OutputCapture localLogs`
* Working with Spock Framework 2.0, 2.1, 2.2, 2.3 and 2.4-M2
== Dependency setup
.Gradle build.gradle
image:https://img.shields.io/maven-central/v/io.github.joke/spock-outputcapture?label=latest%20version[link=https://search.maven.org/artifact/io.github.joke/spock-outputcapture]
.build.gradle
[source,groovy]
----
dependencies {
testImplementation 'io.github.joke:spock-outputcapture:x.y.z'
}
----
.Maven pom.xml
[source,xml]
----
io.github.joke
spock-outputcapture
x.y.z
test
----
== Usage
Add the output capture to your specification. `globalLogs` and `localLogs` will contain logged messages.
.Basic setup
[source,groovy]
----
// Contains all logs of the entire specification
@Shared @OutputCapture globalLogs
// contains logs the of current feature method only
@OutputCapture localLogs
----
If you need more control over the logs object you can add the type.
.With concrete type
[source,groovy]
----
@Shared @OutputCapture CapturedOutput globalLogs
@OutputCapture CapturedOutput localLogs
----
In most cases you want to perform basic regex matching on the output.
.Full example of how to use verify the output.
[source,groovy]
----
class LoggingSpec extends Specification {
@OutputCapture localLogs
def 'local log contains service name'() {
setup:
new LoggingService().logYourName()
expect:
localLogs ==~ /(?s).*My name is LoggingService.*/
}
}
----
Take a look at the link:examples[].
== Contributing
If you're looking to contribute, you can find additional information in link:CONTRIBUTING.adoc[here].