6

我定义了一个模块:

module Support
  include Capybara::DSL

  def self.do_something
    click_link 'Questions'
  end
end

它位于 features/support/support.rb

我的环境.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 在支持模块中可用?

4

2 回答 2

6

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

module Support
  extend Capybara::DSL

  def self.do_something
    click_link 'Questions'
  end
end
于 2012-12-27T16:26:18.587 回答
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

于 2012-12-27T16:35:59.327 回答