Howto To Write A Step Implementation That Supports Multiple Words
Solution 1:
You can you write two step definitions, one for each case. This will reduce your problem a bit. These two steps would then delegate to a helper method that does the actual call.
When the next requirement shows up and you want to combine three things in the same step, it gets easier to catch the arguments in one step and delegate it to the same helper method that you already have.
This would most likely be my approach as I would find this easier to understand and maintain.
You don't want to write clever code. Clever code is very complicated for your future you to understand and change. Dead simple code is always better.
Solution 2:
I got a similar issue and after many attempts I have found that adding a dummy parameter _unused
solves the issue:
@when(u"waiting for (?P<time>\d+) (s|seconds)")defstep_impl(context, _unused, time):
pass
My similar issue was about negative lookahead assertion regex:
@when(r'buy')@when(r'buy (?P<home_owner>((?!.* car).)+) home')@when(r'buy (?P<car_owner>((?!.* home).)+) car')@when(r'buy (?P<home_owner>.+) home and (?P<car_owner>.+) car')defbuy(context, home_owner="default", car_owner="default"):
pass
I have fixed it by splitting my single function and adding parameter _unused
:
@when(r'buy')@when(r'buy (?P<home_owner>.+) home and (?P<car_owner>.+) car')defbuy1(context, home_owner="default", car_owner="default"):
pass@when(r'buy (?P<home_owner>((?!.* car).)+) home')@when(r'buy (?P<car_owner>((?!.* home).)+) car')defbuy2(context, _unused, home_owner="default", car_owner="default"):
buy1(context, home_owner, car_owner)
Post a Comment for "Howto To Write A Step Implementation That Supports Multiple Words"