douningqiu4991 2014-08-24 08:04 采纳率: 0%
浏览 38
已采纳

无法识别:arg风格代币

I've just read that I can use tokens in the format of :argument in my context method Given annotations, however when I do this it's telling me the step is undefined...

/**
 * @Given I am logged in as :username
 */
public function iAmLoggedInAs( $username )
{
    // ...
}

This returns Undefined step "I am logged in as 'disco-superuser'", however ...

/**
 * @Given /^I am logged in as "([^"]*)"$/
 */
public function iAmLoggedInAs( $username )
{
    // ...
}

... works fine.

What am I missing here.

Behat version: 2.5.3

  • 写回答

1条回答 默认 最新

  • duanhuan7750 2014-08-24 19:01
    关注

    For those who are "unsure": the feature is called turnip pattern, this is new in Behat 3. You can read a little about it in the official docs or dig the TurnipPatternPolicy class for more details.

    It throws undefined step definition exception because you are using single quotes, given you provided the correct details. Check again with double quotes, must fix it. The TOKEN_REGEX in the TurnipPatternPolicy class allows for single and double quotes, as well as no quotes at all, the documentation also gives an example of all three cases, which I completely ignored.

    Also, in case some one tries, you cannot combine different types of pattern in one definition (turnip and regex that is), like I did. Read Konstantin's answer on why and other useful information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi