Grouping several specs in blocks inside one Specification class

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grouping several specs in blocks inside one Specification class

grzesuav
Hi

I'm new to Spock (and I haven't seen much groovy so far) so my question could be very simple. I look onto some Spock tutorials but can't find answer.

Problem:

I would have structure like :

class SomeSpecs extends Specification{

   clientSpecs {

     // put here def()"related to client"
    }

   otherSpecs {

     // put here def()"related to other"
    }
}

all def's are related to SomeSpecs, but I want to group  them into block. I tried to do nested Specification classes (f.e. clientSpec extends Specification) but it don't work. Having two separate specs in one .groovy file is not enough for me.

So I have question :
1. Is it possible to do such construct in spock
2. How do to it (if answer to 1. is yes)
3. Alternatives (if answer to 1. is no)
4. If my question is related to lack of knowledge please point in which area (should I read about groovy or spock DSL ?)

Thanks in advance,
Regards Grzesiek.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grouping several specs in blocks inside one Specification class

rfletcher
I believe it's possible if the nested classes are static and extend Specification. Actually you've made me curious now. I'll experiment & report back.

On Monday, March 9, 2015 at 6:31:29 AM UTC-7, [hidden email] wrote:
Hi

I'm new to Spock (and I haven't seen much groovy so far) so my question could be very simple. I look onto some Spock tutorials but can't find answer.

Problem:

I would have structure like :

class SomeSpecs extends Specification{

   clientSpecs {

     // put here def()"related to client"
    }

   otherSpecs {

     // put here def()"related to other"
    }
}

all def's are related to SomeSpecs, but I want to group  them into block. I tried to do nested Specification classes (f.e. clientSpec extends Specification) but it don't work. Having two separate specs in one .groovy file is not enough for me.

So I have question :
1. Is it possible to do such construct in spock
2. How do to it (if answer to 1. is yes)
3. Alternatives (if answer to 1. is no)
4. If my question is related to lack of knowledge please point in which area (should I read about groovy or spock DSL ?)

Thanks in advance,
Regards Grzesiek.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grouping several specs in blocks inside one Specification class

rfletcher
I did a couple of simple proof of concept implementations. The first just has 2 static Specification classes nested inside a regular class:

class NestedSpec {
  static class SubSpec1 extends Specification {
    def "a feature"() {
      expect: 1 == 1
    }
  }
  static class SubSpec2 extends Specification {
    def "a feature"() {
      expect: "a" == "a"
    }
  }
}

The second uses a nested implementation (no reason you couldn't have more than one) of an abstract base spec:

abstract class NestedAbstractSpec extends Specification {

  def "a feature"() {
    expect: subject == 1
  }

  abstract Integer getSubject()

  static class SubSpec1 extends NestedAbstractSpec {
    Integer getSubject() { 1 }

    def "another feature"() {
      expect: subject instanceof Integer
    }
  }
}

Both these approaches work. I can imagine using this to divide up common setup code for testing different aspects of a unit.

On Monday, March 9, 2015 at 9:35:04 AM UTC-7, [hidden email] wrote:
I believe it's possible if the nested classes are static and extend Specification. Actually you've made me curious now. I'll experiment & report back.

On Monday, March 9, 2015 at 6:31:29 AM UTC-7, [hidden email] wrote:
Hi

I'm new to Spock (and I haven't seen much groovy so far) so my question could be very simple. I look onto some Spock tutorials but can't find answer.

Problem:

I would have structure like :

class SomeSpecs extends Specification{

   clientSpecs {

     // put here def()"related to client"
    }

   otherSpecs {

     // put here def()"related to other"
    }
}

all def's are related to SomeSpecs, but I want to group  them into block. I tried to do nested Specification classes (f.e. clientSpec extends Specification) but it don't work. Having two separate specs in one .groovy file is not enough for me.

So I have question :
1. Is it possible to do such construct in spock
2. How do to it (if answer to 1. is yes)
3. Alternatives (if answer to 1. is no)
4. If my question is related to lack of knowledge please point in which area (should I read about groovy or spock DSL ?)

Thanks in advance,
Regards Grzesiek.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grouping several specs in blocks inside one Specification class

grzesuav


W dniu poniedziałek, 9 marca 2015 18:36:50 UTC+1 użytkownik [hidden email] napisał:
I did a couple of simple proof of concept implementations. The first just has 2 static Specification classes nested inside a regular class:




Thanks,

first approach is what I was looking for.

Regards,

Grzesiek 

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...