erikedin / Behavior.jl

Tool for Behavior Driven Development in Julia
Other
25 stars 3 forks source link

Instead of "Multiple matches found", try to pick a step somehow #115

Open hakanai opened 1 year ago

hakanai commented 1 year ago

I have a situation where I have the following two step definitions:

@then("{} + {} = tuple({}, {}, {}, {})") do context, var1, var2, x, y, z, w
    @expect isclose(context[:var1] + context[:var2], parsetuple(x, y, z, w))
end

@then("{} = tuple({}, {}, {}, {})") do context, var, x, y, z, w
    @expect isclose(context[Symbol(var)], parsetuple(x, y, z, w))
end

Then when I run,

     Then a1 + a2 = tuple(1, 1, 6, 1)

        Multiple matches found:
          In path\to\RayTracerChallenge\features\steps\TupleSteps.jl
          In path\to\RayTracerChallenge\features\steps\TupleSteps.jl

(It really should tell me what lines those two are on, in case my file is really large. Right now though, it isn't, so not an issue for me.)

Now, in Cucumber, I would be able to break the tie by means of saying that the variable must be of a given type, where I have to provide a regex which matches valid values. So I would say that the second case can only contain characters which can occur in a variable name, or something like that.

In this case, though, can we not just automatically take the rule with the most parameters?

The only workaround I seem to have is, accept only the shorter pattern, and then attempt to parse the string to extract the plus operands. I don't like the sound of that because I know that the next scenario will be minus, then the next scenario after that will be times, etc...

The context is, I was on the first chapter of the book, The Ray Tracer Challenge, seeing whether Julia would be a viable language for doing the exercise.