Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer block name 'given' over 'setup' #786

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Swap 'given' and 'setup' as default block label.
  • Loading branch information
BurkHufnagel committed Oct 29, 2017
commit 69d7297323c9195b1bc27a2bd85a9d16f12b87a7
4 changes: 1 addition & 3 deletions docs/data_driven_testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Math.max(a, b) == c

The obvious question is: Which iteration failed, and what are its data values? In our example, it isn't hard to figure
out that it's the second iteration that failed. At other times this can be more difficult or even impossible.
footnote:[For example, a feature method could use data variables in its `setup:` block, but not in any conditions.]
footnote:[For example, a feature method could use data variables in its `given:` block, but not in any conditions.]
In any case, it would be nice if Spock made it loud and clear which iteration failed, rather than just reporting the
failure. This is the purpose of the `@Unroll` annotation.

Expand Down Expand Up @@ -289,5 +289,3 @@ include::{sourcedir}/datadriven/DataSpec.groovy[tag=unrolled-3a]
...
include::{sourcedir}/datadriven/DataSpec.groovy[tag=unrolled-3b]
----


7 changes: 3 additions & 4 deletions docs/interaction_based_testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ target constraint
A stubbed interaction can be declared in the usual places: either inside a `then:` block, or anywhere before a
`when:` block. (See <<Where to Declare Interactions>> for the details.) If a mock object is only used for stubbing,
it's common to declare interactions <<declaring-interactions-at-creation-time,at mock creation time>> or in a
`setup:` block.
`given:` block.

=== Returning Fixed Values

Expand Down Expand Up @@ -649,7 +649,7 @@ statements will _not_ work:

[source,groovy]
----
setup:
given:
subscriber.receive("message1") >> "ok"

when:
Expand All @@ -662,7 +662,7 @@ then:
As explained in <<Where to Declare Interactions>>, the `receive` call will first get matched against
the interaction in the `then:` block. Since that interaction doesn't specify a response, the default
value for the method's return type (`null` in this case) will be returned. (This is just another
facet of Spock's lenient approach to mocking.). Hence, the interaction in the `setup:` block will never
facet of Spock's lenient approach to mocking.). Hence, the interaction in the `given:` block will never
get a chance to match.

NOTE: Mocking and stubbing of the same method call has to happen in the same interaction.
Expand Down Expand Up @@ -974,4 +974,3 @@ http://martinfowler.com/articles/mocksArentStubs.html[Mocks Aren't Stubs]::

http://www.growing-object-oriented-software.com[Growing Object-Oriented Software Guided by Tests]::
TDD pioneers Steve Freeman and Nat Pryce explain in detail how test-driven development and mocking work in the real world.

1 change: 1 addition & 0 deletions docs/spock_primer.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Here is the code:
[source,groovy]
----
def "events are published to all subscribers"() {
given:
def subscriber1 = Mock(Subscriber)
def subscriber2 = Mock(Subscriber)
def publisher = new Publisher()
Expand Down