Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:48:13+00:00 2026-05-29T19:48:13+00:00

I have a specification which essentially looks like this: def my example specification(){ given:some

  • 0

I have a specification which essentially looks like this:

def "my example specification"(){
given:"some mocked object which depends on a object created in the where clause"
        def display = mockDisplay()

and:"a activityt"
        def activity = new ConfigActivity(display)
when:
        activity.doStuff()
then:
        1 * display.select()

where:
        dependency << new Dependency()
}


private mockDisplay() {
        def display = Mock(ConfigActivity.Display)
        display.addDependency(dependency)
        return display
}

I understand that that the “mockDisplay()” method is out of scope from the “where” clause. However since a few specifications tend to get rather cluttered with boilerplate code (not in this over simplified example offcourse) I really need some way to reuse my “given” statements and in doing so I would really like to make use of the Spock “where” clauses as well.

Is this doable? Or is there another way to go about this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:48:15+00:00Added an answer on May 29, 2026 at 7:48 pm

    There is no magic way to access a data variable from a helper method, but you can pass it as a method parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file which looks like: name1 1 0 1 0 1
I have 2 tables which in simplified form look like this: Products( id: int,
I have a specification that validates codes. It looks like the following: public ClassificationSpecification
I'm relatively new to the Component Object Model specification - I have a simple
I have been given a specification that requires the ISO 8601 date format, does
I have this rule which says use this CSS rule ONLY FOR PRINTING. @media
I have a content type Audio which includes an audio file field. This field
I have been using Hibernate ORM, which is an implementation of the JPA specification
I have a set of files in several directories which I would like to
I've implemented an OAuth 1.0 provider following this specification , which should be the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.