【问题标题】:Cucumber and WebRat in Selenium mode: Can't start mongrel_rails when using gem bundleSelenium 模式下的 Cucumber 和 WebRat:使用 gem bundle 时无法启动 mongrel_rails
【发布时间】:2010-03-02 03:15:29
【问题描述】:

我正在使用 gem bundler (v.0.9.6) 和 Rails 2.3.5、rubygems 1.3.6 和 ruby​​ 1.8.7(在雪豹上)。我的 Gemfile 看起来像这样:

source :rubyforge
source "http://gems.github.com"

gem "rails", "2.3.5"
gem "ruby-debug"
gem "activemerchant", :require => 'active_merchant'
gem "hpricot"
gem "nokogiri"
gem "state_machine"
gem "fastercsv"
gem "yubikey"
gem "httparty"
gem "ruby-openid"
gem "mongrel" 

group :development do 
  gem 'mongrel'
end

#teste
group :test do
  gem 'rspec'  
  gem 'rspec-rails'
  gem 'cucumber' 
  gem 'cucumber-rails'
  gem "mechanize"
  gem 'notahat-machinist', :require => 'machinist'
  gem 'faker'
  gem 'webrat'
  gem 'selenium-client'
  gem 'database_cleaner'
  gem 'fakeweb'
  gem 'mongrel' #Selenium needs this
end

到目前为止一切顺利。我已经成功使用 bundler 几个星期了。但是,我开始在 Selenium 模式下使用 Cucumber 和 WebRat 来测试网站的一些 ajaxy 功能,每当我运行该功能时,WebRat 都会告诉我 Rails 服务器已启动,但我总是收到 XHR_ERROR,Selenium 无法'找不到网址。 好吧,服务器没有启动。

然后,我打开了 webrat/lib/webrat/selenium/application_servers/rails.rb 文件并在 start 方法中放置了一个调试器语句。再次运行该功能,当调试器触发时,我打印了 start_command def 的返回,即:

mongrel_rails start -d --chdir='/Users/fullofcaffeine/Projetos/myproject' --port=3001 --environment=test --pid /Users/fullofcaffeine/Projetos/myproject/tmp/pids/mongrel_selenium.pid 

我将它复制并粘贴到控制台中,从末尾删除了 -d 和 &,这是我得到的输出:

** Rails loaded.
** Loading any Rails specific GemPlugins
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require': no such file to load -- /Users/fullofcaffeine/.bundle/ruby/1.8/gems/mongrel-1.1.5/lib/mongrel/init.rb (MissingSourceFile)
 from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
 from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
 from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
 from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:134:in `load'
 from /Library/Ruby/Site/1.8/rubygems/source_index.rb:241:in `each'
 from /Library/Ruby/Site/1.8/rubygems/source_index.rb:241:in `each'
 from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:112:in `load'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:231:in `load_plugins'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:117:in `cloaker_'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:149:in `call'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:149:in `listener'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:99:in `cloaker_'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:50:in `call'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:50:in `initialize'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `new'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `run'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/command.rb:212:in `run'
 from /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
 from /usr/bin/mongrel_rails:19:in `load'
 from /usr/bin/mongrel_rails:19

检查它尝试从以下位置加载 mongrel 的路径:“~/.bundle/...”,但 mongrel 是作为系统 gem 安装的。 Bundle 在其他情况下可以很好地处理系统 gem 的加载,但是在这种特殊情况下,我不知道它为什么会失败:(。

我尝试再次运行“捆绑安装”,它总是说:

从系统安装 mongrel (1.1.5) 宝石

我已经尝试从系统中卸载 mongrel 以 尝试制作 bundle 以将其安装到 ~/.bundle (因为这似乎是错误的来源,因为正在搜索 mongrel在这条路上,我像上面一样开始 mongrel_rails),但我就是做不到。

gem uninstall mongrel
ERROR:  While executing gem ... (Gem::InstallError)
    cannot uninstall, check `gem list -d mongrel`

当我运行“gem list | grep mongrel”时,我得到:

mongrel (1.1.5)

很奇怪。

我只是希望能够在使用 gem bundler 时成功运行 Cucumber 和 WebRat + Selenium,但这让我抓狂。

有谁能给我指点一下吗?

【问题讨论】:

    标签: cucumber bundle gem webrat bundler


    【解决方案1】:

    好吧,我找到了一种解决方法,有点可疑,但有效:

     cp  /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/ mongrel-1.1.5
    

    现在,如果您尝试:

    mongrel_rails start --chdir='/Users/fullofcaffeine/Projetos/myproject' --port=3001 --environment=test --pid /Users/fullofcaffeine/Projetos/myproject/tmp/pids/mongrel_selenium.pid
    

    它会找到 mongrel 并启动服务器,然后你可以运行使用 Selenium 的 Cucumber 功能,它会工作:)

    如果其他人发现或知道有关此问题的任何其他信息,请分享,这可能最终成为某个地方的错误。

    【讨论】:

    • 您能否验证此解决方法是否从捆绑包中加载了所有 rails gem?还是 mongrel 和所有活动的* gem 最终都从系统 gemenv 加载?
    【解决方案2】:

    我遇到了类似的问题,但结果是我的 /Users/{account}/.gems/ 和 /Library/Ruby/Gems/ 中安装的 gem 版本不匹配(默认安装) ) 或 /opt/local/lib/ruby/gems/ (Mac Ports 安装)。我一删除 /Users/{account}/.gems/ 就一切正常。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,并花了一段时间尝试调试它。 Mongrel、GemPlugin 和 Bundler 之间似乎存在某种交互。可能的解决方案包括:

      1. 修复 GemPlugin 以与 Bundler 0.9 完美配合。
      2. 修改 Mongrel 以不再使用 GemPlugin。
      3. 修改 Webrat 以支持 Mongrel 以外的 Web 服务器。

      由于最近 GemPlugin 和 Mongrel 看起来有些过时和被抛弃,我决定基于 this patch 为 Webrat 添加 Thin 支持。

      您可以find the new patch on github,或将以下内容添加到您的 Gemfile:

      gem 'webrat', :git => 'git://github.com/emk/webrat.git'
      

      ...并相应地更新您的 features/support/env.rb 文件:

      Webrat.configure do |config|
        # Add this line.
        config.application_framework = :rails_thin
      
        # Your previous configuration here...
      end
      

      【讨论】:

        【解决方案4】:

        bundle exec mongrel_rails start ...?

        这里的重点是从包中加载 Rails gem,而不是从系统 gemenv 中加载。

        我们有一个类似的场景,写在这里: How to get mongrel working with bundler?

        【讨论】:

          【解决方案5】:

          尝试找到当前 gem 可执行文件正在使用的 gems 目录,并从缓存或规范目录中删除任何残留物,这应该可以。

          【讨论】:

            猜你喜欢
            • 2010-11-25
            • 2011-02-04
            • 1970-01-01
            • 2010-11-19
            • 2014-12-31
            • 2011-09-18
            • 2018-11-30
            • 2010-12-31
            • 2011-03-18
            相关资源
            最近更新 更多