本文介绍了状态变量-黄瓜-Ruby-正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cucumber-Ruby的新手。定义场景之后,我在终端中执行了测试,黄瓜提示了如下代码段:


I更改了以下代码

但是即使在那之后,当我使用终端执行测试时,我仍然收到添加代码段的建议。



当我更改下面的代码时,它起作用了


有人可以帮助我描述代码之间的区别吗?



使用



Ruby:红宝石2.3.3p222
黄瓜:3.1.0

解决方案

Cucumber使用大小写相等又称为三重相等来比较传递给 Then 的自变量与方案标题。也就是说,对于场景标题 Foo Bar 和摘要然后执行某操作,它将执行

 某物=== Foo Bar 

对于字符串,三等号别名为 == ,因为 Show ...(启用|禁用) 字符串不等于显示...已启用 也不等于显示...已禁用 ,没有任何匹配项。



OTOH,当您将参数更改为 Regexp 时,它匹配项

  / ^ Show ...(enabled | disabled)$ / === Show。 .. enabled 
#⇒真正的

这就是后面的代码段有效工作的原因。 / p>

I am a newbie to Cucumber-Ruby. After defining the scenario, I executed the test in the terminal and cucumber suggested the snippet as follows :

I changed the code as below

But even after that when I execute the test using the terminal I receives the suggestion to add the snippet.

When I changed the code as below it worked

Can someone help me describing the difference between the codes?

USING

Ruby : ruby 2.3.3p222Cucumber : 3.1.0

解决方案

Cucumber compares the argument passed to Then against scenario titles using case-equal aka triple-equal. That said, for the scenario title "Foo Bar" and the snippet Then something do, it executes

something === "Foo Bar"

For strings, triple-equal is aliased to == and since "Show ... (enabled|disabled)" string is not equal to "Show ... enabled" nor to "Show ... disabled", nothing is matched.

OTOH, when you change the argument to Regexp, it matches:

/^Show ... (enabled|disabled)$/ === "Show ... enabled"
#⇒ true

That is why the latter snippet effectively works.

这篇关于状态变量-黄瓜-Ruby-正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:25