[ 
http://jira.codehaus.org/browse/JBEHAVE-244?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mauro Talevi updated JBEHAVE-244:
---------------------------------

    Fix Version/s:     (was: 2.6)
                   3.0

> Step parameters should be converted just before the step executes (not when 
> the scenario is parsed)
> ---------------------------------------------------------------------------------------------------
>
>                 Key: JBEHAVE-244
>                 URL: http://jira.codehaus.org/browse/JBEHAVE-244
>             Project: JBehave
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.5
>            Reporter: Stephen Cresswell
>             Fix For: 3.0
>
>         Attachments: Added_support_for_deferred_parameter_conversion.patch, 
> BaseSteps.groovy, LazyCandidateStep.groovy
>
>
> I should be able to use a ParamaterConverter to retrieve an entity from the 
> database, e.g.
> Given an employee called Bob
> When I give Bob a pay rise of 10,000 pounds
> Then Bob forgets about his embarrassing law suit
> {code:title=EmployeeSteps.java|borderStyle=solid}
> @Given("an employee called $name")
> public void createEmployee(String name) {
>    new EmployeeBuilder().name(name).buildAndSave();
> }
> @When("I give $employee a pay rise of $amount pounds")
> public void givePayRise(Employee employee, Integer amount) {
>    employee.increaseSalary(amount);
> }
> {code}
> {code:title=EmployeeConverter.java|borderStyle=solid}
> public class EmployeeConverter implements ParamterConverter {
>       EmployeeRepository repo;
>       public Object convertValue(String value, Type type) {
>               return repo.findByFirstName(value)
>       }
> }{code}
> The parameter converter would be simple to implement, but currently won't 
> work without  shenanigans because the step arguments are converted when the 
> step is created,  and all the steps in a scenario are created up front, 
> before any of them are executed. This means that at the time the parameter 
> converter attempts to retrieve the entity from the database it hasn't been 
> created.
> To get around the problem I've created a LazyCandidateStep class, which only 
> creates the Step in the perform or doNotPerform methods. This isn't ideals 
> however because I also have to override Steps.createCandidateStep. I've 
> attached my workaround as an example.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to