本文介绍了如何将水豚包含在Cucumber项目的模块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了一个模块:
模块支持
包括Capybara :: DSL
def self.do_something
click_link'Questions'
end
end
它位于features / support / support.rb
我的env.rb:
require'capybara'
require'cucumber'
require'capybara / cucumber'
Capybara.app_host =http://www.stackoverflow.com
Capybara.run_server = false
Capybara.default_driver =:selenium
调用模块的调用函数:
支持:: do_something
pre>
我有例外:
未定义的方法`click_link'支持:模块(NoMethodError)
如何在支持模块中提供Capybara?解决方案Capybara应该
extend
-ed而不是include
-ed:模块支持
extend Capybara :: DSL
def self.do_something
click_link'Questions'
end
end
I defined a module:
module Support include Capybara::DSL def self.do_something click_link 'Questions' end end
It's situated at features/support/support.rb
My env.rb:
require 'capybara' require 'cucumber' require 'capybara/cucumber' Capybara.app_host = "http://www.stackoverflow.com" Capybara.run_server = false Capybara.default_driver = :selenium
I invoke function of module in steps.rb:
Support::do_something
And I have exception:
undefined method `click_link' for Support:Module (NoMethodError)
How can I make Capybara available in Support module?
解决方案Capybara should be
extend
-ed, notinclude
-ed:module Support extend Capybara::DSL def self.do_something click_link 'Questions' end end
这篇关于如何将水豚包含在Cucumber项目的模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!