views:

608

answers:

5

I'm using gem bundler (v.0.9.6) and Rails 2.3.5, rubygems 1.3.6 and ruby 1.8.7 (On Snow Leopard). My Gemfile looks like this:

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

So far so good. I've been using bundler successfully for a couple of weeks already. However, I started using Cucumber and WebRat in the Selenium mode to test some ajaxy features of the site, and whenever I was running the feature, WebRat was telling me that the Rails server was started, but I always got a XHR_ERROR, where Selenium couldn't find the URL. Well, it happened the server was not being started.

Then, I opened the webrat/lib/webrat/selenium/application_servers/rails.rb file and put a debugger statement in start method. Ran the feature again, when the debugger triggered, I printed the return of the start_command def, which was:

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

I copied and pasted it in the console, removed the -d and & from the end, and here's the output I got:

** 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

Check the path it is trying to load mongrel from: "~/.bundle/...", but mongrel is installed as a system gem. Bundle handles the loading of system gems fine for in other context, but in this particular case, I have no idea why it is failing :(.

I've tried to run "bundle install" again, and it always says:

Installing mongrel (1.1.5) from system gems

I've tried uninstalling mongrel from the system to try to make bundle to install it on ~/.bundle *(as this seems the source of the error, since mongrel is being searched in this path I start mongrel_rails like above)*, but I just couldn't do it.

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

And when I run "gem list | grep mongrel", I get:

mongrel (1.1.5)

Weird.

I just want to be able to run Cucumber and WebRat + Selenium successfully while using gem bundler, but this is driving me nuts.

Could anyone enlighten me ?

A: 

Well, I found an workaround, kind of fishy, but works:

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

Now, if you try to:

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

It will find mongrel and start the server, you can then run the Cucumber feature that uses Selenium and it will work :)

If someone else finds out or knows anything else about this issue, please share, this might end up being a bug somewhere.

FullOfCaffeine
Could you verify whether this workaround loads all of the rails gems from the bundle? Or do mongrel and all the active* gems end up loading from the system gemenv ?
tribalvibes
A: 

I had a similar problem, but it turned out to be mismatching versions of gems between what was in my /Users/{account}/.gems/ and what was installed in either /Library/Ruby/Gems/ (default install) or in /opt/local/lib/ruby/gems/ (the Mac Ports install). As soon as I deleted the /Users/{account}/.gems/ it all worked.

Ed Zavada
A: 

I encountered this same problem, and spent a while trying to debug it. It appears that there's some kind of interaction between Mongrel, GemPlugin and Bundler. Possible solutions include:

  1. Fix GemPlugin to play nicely with Bundler 0.9.
  2. Modify Mongrel to no longer use GemPlugin.
  3. Modify Webrat to support a web server other than Mongrel.

Since both GemPlugin and Mongrel are looking somewhat obsolete and abandoned these days, I decided to add Thin support to Webrat based on this patch.

You can find the new patch on github, or add the following to your Gemfile:

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

...and update your features/support/env.rb file accordingly:

Webrat.configure do |config|
  # Add this line.
  config.application_framework = :rails_thin

  # Your previous configuration here...
end
emk
A: 

try to locate the gems directory which the current gem executable is using and delete any residue from cache or specifications directories , that should work

Raja
A: 

bundle exec mongrel_rails start ... ?

The point here is to load the rails gems from the bundle as well not from the system gemenv.

We have a similar scenario which was written up here: http://stackoverflow.com/questions/3877967/how-to-get-mongrel-working-with-bundler

tribalvibes