简体   繁体   中英

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:

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

What does World(WithinHelpers) mean? Syntactically, it looks like a class/object instantiation to me, but in irb, if I paste those lines an error occurs:

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. 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. This wiki page and this blog post have more details about what's going on and why you might want to use it.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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