////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


=== @RunOnce

The `grails.testing.spock.RunOnce` annotation may be applied to any Spock test
fixture method that you wish to be executed only once.  This is useful when
applied in conjunction with a fixture annnotation like `@Before` as shown below.

[source,groovy]
.src/test/groovy/grails/testing/spock/RunOnceSpec.groovy
----
include::{sourcedir}/grails-testing-support/src/test/groovy/grails/testing/spock/RunOnceSpec.groovy[indent=0]
----

Applying both the `@RunOnce` and `@Before` annotations to a method will yield
behavior similar to the behavior associated with Spock's `setupSpec` method but
an important difference is that `setupSpec` is run before the test instance is
subjected to dependency injection while `@Before` methods are run after the
test instance is subjected to dependency injection.  This means that the
`setupSpec` method will not have access to injected variables but methods marked
with `@Before` will have access to injected variables.  If a test has some one
time setup logic that needs to be executed after dependency injection happens,
the `RunOnce` annotation can help accomplish that.

=== @OnceBefore

The `grails.testing.spock.OnceBefore` annotation is a shorthand way of
accomplishing the same behavior that would be accomplished by applying both the
`@RunOnce` and `@Before` annotations to a fixture method.

[source,groovy]
.src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy
----
include::{sourcedir}/grails-testing-support/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy[indent=0]
----

This is useful in the context of an integration test which wants to reference
dependency injected values during setup as shown below.

[source,groovy]
.src/integration-test/groovy/demo/DependencyInjectionSpec.groovy
----
include::{functionalSourceDir}/demo33/src/integration-test/groovy/demo/DependencyInjectionSpec.groovy[indent=0]
----
