spockframework / spockframework/spock

Spock & Spock Reports: How print a variable valuable in Label/Block

Open
#552 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Hello Spock Team

I am working with:

  • Spock Core
  • Spock Reports
  • Spock Spring
  • Spring MVC Testing

and I have the following code:

def "findAll() Expected"(){

    given: "The URL being used is: /personas/xml/personas"

        url = PersonaUrlHelper.FINDALL;

    when: "When the URL is being calling with a GET"

        resultActions = mockMvc.perform(get(url)).andDo(print())

    then: "something..."

        resultActions.andExpect(status().isOk())
                     .andExpect(content().contentType(RequestMappingProducesJsonUtf8.PRODUCES_JSON_UTF_8))

}

Two observations:

One: observe given: "The URL being used is: /personas/xml/personas" where the URL/URI value has been added manually.

Two: the url variable has been defined how an instance variable, because it is common in many test methods. Therefore def String url

My question is:

how I can display the url variable in a Spock's label/block? how (given, then…)?
It to be printed through Spock Reports and improve my testing documentation

I have read the following: Spocklight: Extra Data Variables for Unroll Description

It working around @Unroll. But I did realize all work around the where label/block.

I already have tried something like:

given: "The URL being used is: $url"
given: "The URL being used is: ${url}"

And does not work

I want to work around with a syntax similar like the following:

def "findAll() Expected"(){

    url = PersonaUrlHelper.FINDALL;

    given: "The URL being used is: $url"

        …. something

    when: "When the URL is being calling with a GET"

So what could be the correct configuration?

Asume I do a refactor for PersonaUrlHelper.FINDALL used in some Spring's @RequestMapping and in this test method. I don't want update manually the text in the given label/block

So what is the correct syntax?

If there is no a correct syntax, can be consider this how a new feature?

Thanks in advance

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shown findAll() Expected specification and compare block-label interpolation with the @Unroll behavior described in the linked Spocklight article. Reproduce the result through Spock Reports using the url instance variable; done means determining whether labels can evaluate it or documenting that a feature is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, spring
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.