如何将Capybara纳入Cucumber项目的模块中

时间:2012-12-27 16:03:57

标签: ruby cucumber capybara

我定义了一个模块:

module Support
  include Capybara::DSL

  def self.do_something
    click_link 'Questions'
  end
end

它位于features / support / support.rb

我的环境:

require 'capybara'
require 'cucumber'
require 'capybara/cucumber'

Capybara.app_host = "http://www.stackoverflow.com"
Capybara.run_server = false
Capybara.default_driver = :selenium

我在steps.rb中调用模块的功能:

Support::do_something

我有例外:

undefined method `click_link' for Support:Module (NoMethodError)

如何在支持模块中提供Capybara?

2 个答案:

答案 0 :(得分:6)

Capybara应该是extend - ed,而不是include - ed:

module Support
  extend Capybara::DSL

  def self.do_something
    click_link 'Questions'
  end
end

答案 1 :(得分:1)

module SupportModule
    class Support
        include Capybara::DSL

        def do_something
            click_link 'Questions'
        end
    end
end

s = SupportModule::Support.new
s.do_something

http://rubydoc.info/github/jnicklas/capybara/master/Capybara/DSL