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

Support for argument transforms #9

Open
mscottford opened this issue Sep 15, 2009 · 5 comments
Open

Support for argument transforms #9

mscottford opened this issue Sep 15, 2009 · 5 comments

Comments

@mscottford
Copy link

Add support for the use of argument transforms in the Given/When/Then regular expressions.

@mscottford
Copy link
Author

Example:

[Transform("^user \w+$")]
public static User TransformUser(string userName) {
    return new User(userName);
}

[Given("^(user \w+) is assigned (user \w+)$"]
public static void UserIsAssignedAnotherUser(User user, User userToAssign) {
    user.Assign(userToAssign);
}

@richardlawrence
Copy link
Owner

I've done parameter type conversion in the invocation code here (http://github.com/richardlawrence/Cuke4Nuke/blob/step_definition_parameters/Cuke4Nuke/Core/StepDefinitionRepository.cs) such that if you register a custom TypeConverter than can convert from string you can then use your type as a parameter. As far as I can tell, this accomplishes the same thing as argument transforms without changing the regexp format, which I like better.

@mscottford
Copy link
Author

Registering custom type converters is messy, though. For example, to register a custom type converter, you have to decorate the class that you want to convert. This does two things, (1) it forces the user to modify the class that is being executed/passed and (2) it moves the logic for the conversion into a different class.

I prefer modifying the regular expression for this case. Especially, since such a modification has been accepted within cucumber proper.

That said, grabbing the type formatter is still a great idea. It covers the types that have built-in type converters like Font and Point and others.

@x97mdr
Copy link

x97mdr commented Dec 4, 2009

May I throw in my two cents? Fitnesse looks for a static Parse method on the object and uses that to convert the text into the object if it exists. This works for all of the value types and might be a nice easy compromise between the complexity of TypeConverter and modifying the regular expressions (which could be a breaking change). I'd be willing to give this a shot, if anyone wanted

@richardlawrence
Copy link
Owner

@x97mdr - I wouldn't mind if it tried the TypeConverter first, which works well for many of the basic types, and then fell back on a static Parse(string) method if one exists. Feel free to give it a shot and send me a pull request when it's ready. Thanks.

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

3 participants