简体   繁体   English

在web_steps.rb中,World(WithinHelpers)是什么意思?

[英]In web_steps.rb what does World(WithinHelpers) mean?

A probably very newbie question: in Cucumber Rails web_steps.rb there's this piece at the top: 一个可能非常新手的问题:在Cucumber Rails web_steps.rb中,顶部是这样的:

module WithinHelpers
  def with_scope(locator)
    locator ? within(*selector_for(locator)) { yield } : yield
  end
end
World(WithinHelpers)

What does World(WithinHelpers) mean? World(WithinHelpers)是什么意思? Syntactically, it looks like a class/object instantiation to me, but in irb, if I paste those lines an error occurs: 在语法上,对我来说,它看起来像是类/对象的实例,但是在irb中,如果我粘贴这些行,则会发生错误:

1.9.3p448 :006 > World(WithinHelpers)
NoMethodError: undefined method 'World' for main:Object`

Thanks for a reply. 感谢您的答复。

I'm going to answer this as of the current version of cucumber code on github ( e3c6afb07f ) since that's the easiest version for me to search-- I'm guessing you at least got started on an older version, since web_steps has been deprecated and is no longer recommended. 我要在github( e3c6afb07f )上的最新版本的黄瓜代码上回答这个问题,因为这是我搜索的最简单的版本-我猜您至少已开始使用旧版本,因为不推荐使用web_steps并且不再推荐。 That doesn't affect your question, just that what you're running might be slightly different than the code I'm looking at. 这并不影响您的问题,只是您所运行的内容可能与我正在查看的代码略有不同。

World is a method defined in Cucumber::RbSupport::RbDsl that lets you mix modules into the World Object that is the context in which your features are run. WorldCucumber::RbSupport::RbDsl中定义的方法该方法使您可以将模块混合到World Object中, World Object是在其中运行要素的环境。 This wiki page and this blog post have more details about what's going on and why you might want to use it. 该Wiki页此博客文章详细介绍了正在发生的事情以及您为什么要使用它。

The reason it doesn't work in irb is that you haven't required cucumber in that environment, so the Cucumber::RbSupport::RbDsl module hasn't been mixed into Object . 它在irb中不起作用的原因是您在该环境中不需要黄瓜,因此Cucumber::RbSupport::RbDsl模块未混入Object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM