gpt4 book ai didi

ruby - 如何在纯 Ruby(无 Rails)中使用 Capybara?

转载 作者:数据小太阳 更新时间:2023-10-29 06:25:14 27 4
gpt4 key购买 nike

我试图让 Capybara 在一个简单的 Ruby 脚本中运行——即没有/在 Rails 之外。这是脚本:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'

include Capybara

Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'

visit('/')

问题是,当我运行它时,我得到了这个错误:

NameError: uninitialized constant Capybara::Session

at top level in dsl.rb at line 52
method gem_original_require in custom_require.rb at line 36
method require in custom_require.rb at line 36
at top level in capybara_test.rb at line 3
method gem_original_require in custom_require.rb at line 31
method require in custom_require.rb at line 31
at top level in capybara_test.rb at line

我做错了什么?

更多信息:

  • Mac OS X 10.5
  • ruby 1.8.6(2009-06-08 补丁级别 369)[universal-darwin9.0]
  • capybara (0.3.9)

谢谢!

尼尔

注意:根据 jnicklas 的评论,我尝试了这个,它更接近于新的 README:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'

Capybara.default_driver = :selenium
Capybara.app_host = 'http://www.google.com'

module MyCapybaraTest
include Capybara

def test_google
visit('/')
end
end

不幸的是,我仍然看到同样的错误:

NameError: uninitialized constant Capybara::Session

想法?

谢谢!

最佳答案

下面是一些似乎对我有用的东西:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'

Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'

module MyCapybaraTest
class Test
include Capybara::DSL
def test_google
visit('/')
end
end
end

t = MyCapybaraTest::Test.new
t.test_google

关于ruby - 如何在纯 Ruby(无 Rails)中使用 Capybara?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3484169/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com