Hooking into the guts of spock for awesome reporting

43 views
Skip to first unread message

David Dawson

unread,
Apr 18, 2013, 11:14:39 AM4/18/13
to spockfr...@googlegroups.com
Hey guys,

I have an odd idea (well, its not mine, but I digress).

given the specification

def "some poll"() {
  given:
  def poll = new Poll(values:["Red", "Green", "Blue"])

  when:  
  poll.addVote("Red")
  poll.addVote("Green")
  poll.addVote("Blue")
  poll.addVote("Red")
  poll.addVote("Red")
  poll.addVote("Red")

  then:
  poll.votes == 6
  poll.winner == "Red"
}


I'd like to be able to extract a few things out.  At the end of the when: block, I'd like to  get a list (somehow...) of the interactions that have occurred.  As in the expressions.

Similarly, I'd like to get the expressions that have been executed in the then or expect and be able to process them.  

The idea is to generate documentation of the form

----
Some poll

given a poll between Red, Green, Blue

when 4 votes added to Red, 1 vote added to Green, 1 vote added to Blue

then 10 total votes, Red is the winner
-----

I'm suspecting that I'll be deep in AST land, which is fine.  I just wanted to get a handle on if this might be possible in some way?

The actual conversion of expressions into documentation is something I've got specced out.  Its the hook into spock to get those expressions that I'm wondering about.

I've checked the AST after conversion, and the labels are still available.  I was wondering if you had any thoughts on a second AST transform hooking into the code part way through spocks ? (it might be a horrific idea :-) )

Or could this be handled another way?

Best,

David.

--
David Dawson

Dawson Systems Ltd

Email    : da...@dawsonsystems.com
Mobile : 07866011256
Jabber : da...@dawsonsystems.com
Skype   : davidadawson
Twitter : @davidthecoder

http://davidadawson.wordpress.com

Peter Niederwieser

unread,
Apr 19, 2013, 11:58:53 PM4/19/13
to spockfr...@googlegroups.com
David,

Spock doesn't provide any compile-time hooks, but you could always run your own AST transform by registering it in the standard Groovy way. Spock's own transform runs in the semantic analysis phase, which comes (right) after conversion.
Without knowing more details about your plans, it's hard for me to say if you would need any hooks over the runtime hooks currently offered by Spock.

Cheers,
Peter

--
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 spockframewor...@googlegroups.com.
To post to this group, send email to spockfr...@googlegroups.com.
Visit this group at http://groups.google.com/group/spockframework?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages