I'm currently thinking about a new Spock feature and want to know about
your opinion on it. It's a long post, because I added some code
examples. Any feedback is appreciated.
First what I'm trying to do: I want to write a Spock extension that
pretty prints the steps of each feature method to stdout, so that you
know what happens inside your feature methods.
For that purpose I'm using the FeatureInfo object that gets passed to my
IRunListener implementation and print the "blocks" field.
This works already pretty well, but there are cases, when the state
described in the blocks description string needs to be detailed further.
For that purpose I want to introduce the concept of "step-data" into Spock.
Here is an example, to show you what I want to do:
Spock test:
---- SNIP ----
def "test the filter feature"() {
given: "I have a list of my customers"
def customers = [['john', 23], ['jeff', 42]]
when: "I get the customers that have more than 30 credits"
def filtered = customers.grep { name, credits -> credits >= 30 }
then: "the list should be as follows"
filtered == [['jeff', 42]]
}
---- SNAP ----
Output of the test run on stdout:
---- SNIP ----
Given I have a list of my customers
| name | credits |
| john | 23 |
| jeff | 42 |
When I get the customers that have more than 30 credits
Then the list should be as follows
| name | credits |
| jeff | 42 |
---- SNAP ----
To achieve the above output, Spock must know about the data that is used
in the steps.
Here is my proposed change: Each block has the possibility, to specify a
Map of step data, that is stored within the BlockMetadata annotation.
Each key of that map maybe used as a variable.
Example in Spock:
--- SNIP ---
given: "I have a list of my customers"
data: [allCustomers: [['john', 23], ['jeff', 42]]
when: "i get the customers that have more than 30 credits"
def filtered = allCustomers.grep { name, credits -> credits >= 30 }
then: "the list should be as follows";
data: [richCustomers: ['jeff', 42]]
filtered == richCustomers
--- SNAP ---
What do you think about it? Is this a feature that would sound useful to
you?
Maybe I can talk with some of you about that idea on the GR8Conf next
week in Copenhagen.
Cheers,
Jan
Hi All,I have a very concrete application of this. I'm working on adding Spock integration to Thucydides (http://www.thucydides.info). Basically, Thucydides keeps track of what methods were invoked during a test, in what order, and so forth. One obvious way for this to work would be to extend the IRunListener class with methods like the following:beforeStep(stepInfo)afterStep(stepInfo)
where the StepInfo would include the type (given, when, then, expect...) and the associated text (if any).Thoughts?John
--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
Thanks, I wasn't aware of that. Unfortunately, I checked, and it's not quite enough, as I need to know not only what the blocks are, but when they start and finish. I need to know this so that Thucydides can create a corresponding step in the reporting structure, and nest the subsequent calls underneath.
--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.