spock icon indicating copy to clipboard operation
spock copied to clipboard

Allow @Shared fields in traits mixed into Spock Specifications

Open carstenlenz opened this issue 10 years ago • 7 comments

Hi,

I tried to refactor common behaviour into traits and reuse them by implementing them in my Specifications. I noticed that Spock does not handle @Shared fields declared in a trait.

Would it be possible to support this?

carstenlenz avatar May 05 '15 11:05 carstenlenz

It looks like a duplication of issue 370 and I have even created test cases reproducing this problem.

szpak avatar May 05 '15 11:05 szpak

Cool. Haven't seen this :)

carstenlenz avatar May 05 '15 13:05 carstenlenz

Just for linking this issue to the pr #42

leonard84 avatar May 12 '15 19:05 leonard84

Btw, the problem is only with getting annotations from fields in a trait, so a workaround those fields can be marked as static.

szpak avatar Oct 28 '15 17:10 szpak

@szpak your comment relates to peters last comment on #203

leonard84 avatar Oct 28 '15 17:10 leonard84

Came here to ask for this.

chrylis avatar Jan 20 '21 06:01 chrylis

The main problem is that Spock works via AST transformations and the combination of AST+Traits is unsupported by groovy as you can see in the section Compatibility with AST transformations of the groovy docs.

leonard84 avatar Jan 20 '21 10:01 leonard84