ERROR: While executing gem ... (NoMethodError) undefined method `spec' for nil:NilClass
Asked Answered
L

2

6

I'm trying to get started with ruby and Watir-webdriver for some test automation.

sudo apt-get install ruby rubygems

sudo gem install watir-webdriver

Whenever I gem install I'm getting these errors like :

[/usr/lib/ruby/gems/1.8/specifications/selenium-webdriver-2.13.0.gemspec] isn't a Gem::Specification (NilClass instead).
ERROR:  While executing gem ... (NoMethodError)
    undefined method `spec' for nil:NilClass
Lumpkin answered 29/11, 2011 at 1:5 Comment(1)
BTW: if you are new to Ruby and will be using it mostly for scripting and automation, I'd strongly recommend 'Everyday Scripting with Ruby' by Brian Marick as a good book to get you started. You can get it for a pretty reasonable price in E-book format directly from Pragmatic Programmers. Also have a look at the (in progress) 'Watir Book' from Zeljko Filipin (github.com/zeljkofilipin/watirbook/downloads) it's free at the moment (but I'm sure the author would not turn down donations, or especially feedback from those new to Watir and Ruby)Fotina
L
4

The problem was due to corrupted downloads being stored in the cache, so that even after gem uninstall and reinstall, the error persisted. To force re-download, I emptied the cache directories which are found by checking under GEM PATHS in the output of the command gem env.

Lumpkin answered 29/11, 2011 at 5:7 Comment(2)
If this fixed the problem, you should accept your answer. I would recommend if you have not done so looking into RVM, it makes managing versions of ruby and gems etc much easier. it also makes things much easier down the road when the time comes to upgrade either the ruby language, or specific gems which have lots of dependencies on other gems.Fotina
+1, also empty specifications if you are getting gemspecs warnings.Homework
E
2

You should try using Ruby 1.9.x

The easiest way is to use RVM:

sudo apt-get install git
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
rvm install 1.9.2
rvm use 1.9.2
gem install watir-webdriver
Eam answered 29/11, 2011 at 3:30 Comment(2)
I get a similar error when using your script: 'ERROR: While executing gem ... (NoMethodError) undefined method 'spec' for nil:NilClass'Lumpkin
Don't use sudo to install gems you expect to use with an RVM managed Ruby.Rhythmics

© 2022 - 2024 — McMap. All rights reserved.