Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@NestedSteps should allow formatting of nested steps #334

Open
prathyk opened this issue Jan 23, 2018 · 4 comments
Open

@NestedSteps should allow formatting of nested steps #334

prathyk opened this issue Jan 23, 2018 · 4 comments

Comments

@prathyk
Copy link

prathyk commented Jan 23, 2018

Currently the nested steps are just indented. What if I want to enclose nested steps in curly braces?

something like - If I use groovy to write JGiven tests, I can easily create a dsl to create a customer instance:

new Customer{
   name: "John"
   Age: 25
   Gender: Male
}

I want the above DSL to appear as it is even in the console report.
The methods name, Age, Gender are nested steps inside Customer. I tag the Customer method with @NestedSteps but it would have been nice if it allows us to format the nested steps, may be using a PrintFormatter etc... Like in @NestedSteps(PrintFormatter.class, "{$nested}"

I hope you get the idea. I want to control the formatting of nested steps.
By the way, is there a way we can provide our own listener to listen to JGiven steps???

@janschaefer
Copy link
Contributor

The question is why you want to use nested steps here. JGiven can format complex objects and you can provide your own formatter for that. See http://jgiven.org/userguide/#_the_pojoformat_annotation for more details. Please check whether this solves your use case.

Regarding your 2nd question: no there is no mechanism yet to have custom step listeners. There is already an open issue for that: #328

@prathyk
Copy link
Author

prathyk commented Jan 28, 2018

Yes, I know about the POJO formatter but that is not enough for my usecase.
I have a customer builder and the builder has many methods. If I have to print the customer using POJOFormatter, then I'll have to track what methods on the builder were called by using some kind of reflection. Moreover, I'll have to pass customer as a parameter than as a Closure as above.

Example:
cust1 = new Customer{
name: "John"
Age: 25
Gender: Male
}

cust2 = new Customer{
name: "John2"
Age: 21
Gender: Male
Mobile: 99xx99xx9xx
}
For cust2, the Mobile number is specified but for cust1 it assumes some default mobile number. While toString() or POJOFormatter can print all fields of the customer, it cannot track which fields were explicitly set by the user.

A custom stepListener also would solve problem such as this, because I would then be able to take control of how my steps are formatted.

I think the distinguishing feature of JGiven when compared to Spock etc... is the ability to automatically generate Scenario text and there should be all flexibility in that process. I feel this is important feature for JGiven.

@janschaefer
Copy link
Contributor

janschaefer commented Jan 28, 2018

Ok, I think I got it now. It is similar to #83. I think. The only difference is that you want to also be able to specify how the steps are formatted.

@prathyk
Copy link
Author

prathyk commented Jan 29, 2018

Yes. correct. I saw #83 . I understood that to get builders which again take embedded builders, I needed lambdas. So, I figured out I could use groovy closures to get nested steps but then the nested step is always differentiated only by its indentation. I want to be able to control the formatting of the steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants