Git Product home page Git Product logo

Comments (5)

mscottford avatar mscottford commented on August 15, 2024

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);
}

from cuke4nuke.

richardlawrence avatar richardlawrence commented on August 15, 2024

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.

from cuke4nuke.

mscottford avatar mscottford commented on August 15, 2024

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.

from cuke4nuke.

x97mdr avatar x97mdr commented on August 15, 2024

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

from cuke4nuke.

richardlawrence avatar richardlawrence commented on August 15, 2024

@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.

from cuke4nuke.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.