Selenium模式下的Cucumber和WebRat:使用gem bundle时无法启动mongrel_rails

时间:2010-03-02 03:15:29

标签: cucumber bundle gem webrat bundler

我正在使用gem bundler(v.0.9.6)和Rails 2.3.5,rubygems 1.3.6和ruby 1.8.7(On Snow Leopard)。我的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处理系统gems的加载在其他情况下很好,但在这种特殊情况下,我不知道它失败的原因:(。

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

  

从系统安装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,但这让我疯狂。

有人能开导我吗?

5 个答案:

答案 0 :(得分:0)

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

 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功能,它会起作用:)

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

答案 1 :(得分:0)

我遇到了类似的问题,但事实证明,我的/Users/{account}/.gems/和/ Library / Ruby / Gems /中安装的内容之间存在不匹配的宝石版本(默认安装)或在/ opt / local / lib / ruby​​ / gems /(Mac Ports安装)。一旦我删除了/Users/{account}/.gems/,它就会起作用。

答案 2 :(得分:0)

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

  1. 修复GemPlugin以便与Bundler 0.9很好地配合使用。
  2. 修改Mongrel不再使用GemPlugin。
  3. 修改Webrat以支持Mongrel以外的Web服务器。
  4. 由于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
    

答案 3 :(得分:0)

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

答案 4 :(得分:0)

bundle exec mongrel_rails start ...

这里的要点是从捆绑中加载rails gems,而不是从系统gemenv加载。

我们有类似的情况写在这里: How to get mongrel working with bundler?