开发者

Cucumber step ambiguity when using built in 'within' step scoper

开发者 https://www.devze.com 2023-03-12 11:10 出处:网络
I\'ve created a custom cucumber step for checking the destination for a link, and I\'m using Cucumber\'s new built in support in web_steps for scoping these lookups. So I have two cucumber steps invol

I've created a custom cucumber step for checking the destination for a link, and I'm using Cucumber's new built in support in web_steps for scoping these lookups. So I have two cucumber steps involved:

# My step to verify the link
Then /^"([^\"]*)" should link to (.*)$/ do |link_text,page_name|
  page.should have_link(link_text, :href开发者_开发技巧 => path_to(page_name))
end

# Cucumber's built in step to scope things
# Single-line step scoper
When /^(.*) within ([^:]+)$/ do |step, parent|
  with_scope(parent) { When step }
end

I use this by having cucumber scripts that do things like

And "home" should link to the home page within the "Email Signature" section

My problem is that I'm getting ambiguous matches on the above between these two steps, because the 'within' clause can't be told apart from the "the home page", because the latter doesn't have any bounding quotes.

I've tried changing the link step to read like this, thinking it might resolve the ambiguity by not matching the 'within', but I think the 'within' gets swallowed by the preceeding group instead:

Then /^"([^\"]*)" should link to (.*)(?!within)$/ do |link_text,page_name|
  page.should have_link(link_text, :href => path_to(page_name))
end

Any thoughts on how to resolve this?


Not directly an answer to the question I posed (for that see Qtax's answer), but here's what I've wound up doing. I think it's a nicer solution anyway, for what it's worth...

I've created a custom version of the scoping helper that looks like this:

Then /^within ([^,]*), (.+)$/ do |parent, step|
  with_scope(parent) { When step }
end

This allows me to write steps like this:

And within the "Email Signature" section, "home" should link to the home page

Which I think (a) reads more naturally (it's clearer that we're talking about the link being in the e-mail signature section, not the home page), and (b) works around the problem I was having, because the unquoted 'within' selector is well out of the way of the unquoted page name.


Try something like:

/^"([^"]*)" should link to ((?:(?!within).)+)$/

Don't know anything about Cucumber, I'm just going by what you tried to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号