watir on ubuntu 11.10 - ruby

I've just updated my system from ubuntu 11.04 to 11.10 and...surprise!
Now if I try to use watir, doing
require 'rubygems'
require 'watir-webdriver'
I obtain this error
require 'watir-webdriver'
Invalid gemspec in [/var/lib/gems/1.8/specifications/json_pure-1.6.1.gemspec]:
invalid date format in specification: "2011-09-18 00:00:00.000000000Z"
Invalid gemspec in [/var/lib/gems/1.8/specifications/watir-webdriver-0.3.5.gemspec]:
invalid date format in specification: "2011-10-05 00:00:00.000000000Z"
LoadError: no such file to load -- watir-webdriver
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/lib/ruby/1.8/x86_64-linux/rbconfig.rb:22
How to make it work again?

All I know about running Watir on Linux is here:
https://github.com/zeljkofilipin/watirbook/blob/master/installation/ubuntu.md
Did you check if Ubuntu update broke your Ruby installation? Maybe it uninstalled watir-webdriver gem or something.
What do you get for gem list watir?

Your version of ruby has problems. Install RVM, and get it to install a fresh ruby:
1. bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
2. echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
3. source .bash_profile
4. rvm install 1.9.2
5. rvm use 1.9.2

I have had the same problem and could fix it by adjusting the jason spec file:
/var/lib/gems/1.8/specifications/json_pure-1.6.1.gemspec
In the date format line I removed everything which looked like this "00:00:00.000000000Z"
and kept just the plain date format.
After again installing watir (see watir installation web page)
everything worked properly:
sudo apt-get install rubygems
gem install watir --no-rdoc --no-ri

I've seen this issue with the json gem (and now that I've upgraded to 11.10 other gems). The fix I'd previously seen for the json gem was to go into the gem file and listed in the error and remove the "00:00:00.000000000Z" string wherever you found it.
I've used it on every gem I've received this error on (which was only a couple but I don't remember which exactly). The the gems seem to work just fine. I haven't noticed any problems since removing that string.

Related

Can't get awesome_print gem to work

awesome_print looks like a pretty nice gem, so I wanted to try it out.
I went to one of my projects and did:
gem install awesome_print
and it says one gem installed, documentation installed, etc.
Then, while I am in that project, I went to my Rails console to try it out, but when I did a require "awesome_print" as their help file says, I get a "cannot load such file".
Has anyone got this to work?
gem install will put the gem code on your computer, but unless the gem's source code files are on your load path, require won't be able to find them. bundle exec looks at the nearest Gemfile.lock and adds the source code for all the gems listed there to your load path. Rails initialization includes getting Bundler to do this for you.
One solution is to add awesome_print to your Gemfile. However, this will cause your application to have awesome_print as a dependency. Alternatively you can manually add the awesome_print library to your load path after starting up the Rails console and then requiring it:
$ rails c
> $LOAD_PATH << path/to/awesome_print-x.x.x/lib
> require 'awesome_print'
> ap {foo: {bar: {baz: :qux}}}
If you're using RVM, the path is likely to be something like:
~/.rvm/rubies/ruby-x.x.x-pxxx#your_gemset_name/gems/awesome_print-x.x.x/lib
Add it to your Gemfile like this:
gem 'awesome_print', :require => 'ap'
I add it to the development group, since that's the only time I need it. The gem doesn't have any other gem dependencies, so I routinely add it to my Gemfile.
Also, add these two lines to your ~/.irbrc file to set ap to be your default pager:
require "awesome_print"
AwesomePrint.irb!
Note that if you use this, however, any projects where awesome_print is not installed in its Gemfile will raise this error when you run rails c:
cannot load such file -- awesome_print
Depending on whatever else you may have in your ~/.irbrc file, this can cause other side effects, such as messing up your prompt. To avoid these, simply add the two lines to the very end of that file.
install it :
$ gem install awesome_print
include it in you GemFile, if you want :
gem 'awesome_print', :require => 'ap'
add this line to the file ~/.irbrc :
require 'awesome_print'
AwesomePrint.irb!
restart your shell!
just a note: I did this and it didnt work right away, probably need to restart the computer... or I just needed to close all shell tabs and open the terminal again!
Install the gem on your machine
gem install awesome_print
Get the path to which it has installed
gem which awesome_print
Add the following configuration to your ~/.irbrc and ~/.pryrc. This will load Awesome Print whenever you fire an IRB or a pry session.
*Remember $LOAD_PATH will hold whatever you got from typing gem which awesome_print
# ~/.irbc and ~/.pryrc
$LOAD_PATH << "~/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/awesome_print-1.8.0/lib/"
require "awesome_print"
AwesomePrint.irb!
If you are looking to install it without having it in your Gemfile, this is how to do it:
$ gem install awesome_print
I was running into an issue where it was installing successfully but it not in the right directory.
In that case just put this in your .bashrc, this will set the load path:
export PATH="/home/user/.gem/ruby/2.3.0/bin:$PATH"
PATH="`ruby -e 'puts Gem.user_dir'`/bin:$PATH"
replace 2.3.0 with the version of ruby you are working with.
replace user with your username or if you are using vagrant then replace with vagrant
reload your .bashrc or exit the Terminal to reload changes, then install the gem again.
In my case, I struggled with PATHs and such, while missing something obvious!
# which ruby
/usr/bin/ruby
# ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]
# locate bin/ruby
/usr/bin/ruby
/usr/local/Cellar/ruby/2.7.2/bin/ruby
/usr/local/opt/ruby/bin/ruby
# /usr/local/opt/ruby/bin/ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin17]
#
Aha! Version crud. I was running an old ruby. Thanks, Apple!
# sudo mv /usr/bin/ruby /usr/bin/ruby_2.3.7
# sudo ln /usr/local/opt/ruby/bin/ruby /usr/bin/ruby
Solved the problem!
There is probably something I could have told brew to do to fix things, but I was impatient. :-)

Installing a gem has no effect (aka how to use check_puppet.rb)

I'm sure this question is an easy one for Ruby users. However for me this is a issue I can't figure out by myself.
My goal is to use a script included in the Puppet archive (ext/nagios/check_puppet.rb) on a Ubuntu-10.4 system.
I try to launch the script:
$ sudo ./check_puppet.rb
./check_puppet.rb:4:in `require': no such file to load -- sys/proctable (LoadError)
from ./check_puppet.rb:4
Ok so there's something missing. I fount out I need some library called sys-proctable available at http://raa.ruby-lang.org/project/sys-proctable/
wget http://rubyforge.org/frs/download.php/65609/sys-proctable-0.9.0-x86-linux.gem
[...]
sudo apt-get install rubygems
[...]
$ sudo gem install sys-proctable-0.9.0-x86-linux.gem
Successfully installed sys-proctable-0.9.0-x86-linux
1 gem installed
Installing ri documentation for sys-proctable-0.9.0-x86-linux...
Installing RDoc documentation for sys-proctable-0.9.0-x86-linux...
Everything looks pretty good so far! Time to launch the script again
$ sudo ./check_puppet.rb
./check_puppet.rb:4:in `require': no such file to load -- sys/proctable (LoadError)
from ./check_puppet.rb:4
the gem listoutput tells me this:
$ gem list
*** LOCAL GEMS ***
sys-proctable (0.9.0)
Where has this gem been installed?
Why can't the script load the sys-proctable lib?
What the %&$# am I doing wrong?
Where's the official doc of gem?
The gem is installed - but in Ruby 1.8 you need to have the line:
require 'rubygems'
To use rubygems. This changes the 'require' function so it will pull in rubygems when you ask it to.
So in the script:
https://github.com/puppetlabs/puppet/blob/master/ext/nagios/check_puppet.rb
Just add the require near the top and try again.
For instructions on other ways to use rubygems, consult the Rubygems documentation:
http://docs.rubygems.org/read/chapter/3#page70
this is what i am getting on centos 6.4
sudo ./check_puppet.rb
./check_puppet.rb:75:in `-': no implicit conversion to float from nil (TypeError)
from ./check_puppet.rb:75:in `check_state'
from ./check_puppet.rb:122
i added require 'rubygems'
and installed sys-proctable

Rspec bundle is broken in TextMate and rvm

I've had a difficult time since I started using rvm. I've done all the rvm/textmate set up and have the latest bundles but I still can't run Rspec test from textmate.
I have the latest bundle from github.com/rspec/rspec-tmbundle.git
and it's installed in ~/Library/Application\ Support/TextMate/Bundles/
RSpec.tmbundle
RVM default is using the system ruby 1.8.6
Rspec gem versions
gem list --local | grep spec
blue_light_special (0.2.0)
rspec (2.2.0)
rspec-core (2.2.1, 2.0.1)
rspec-expectations (2.2.0, 2.0.1)
rspec-mocks (2.2.0, 2.0.1)
rspec-rails (2.0.1, 1.3.2)
TextMate
TM_RUBY=/Users/jspooner/.rvm/bin/rvm-auto-ruby
The Error: rspec/core (LoadError)
/Users/jspooner/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/rspec/mate.rb:29:in require': no such file to load -- rspec/core (LoadError) from /Users/jspooner/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/rspec/mate.rb:29 from /tmp/textmate-command-8073.rb:2:inrequire' from /tmp/textmate-command-8073.rb:2
The best solution I've found is from Jacques Crocker.
http://groups.google.com/group/rubyversionmanager/browse_thread/thread/64b84bbcdf49e9b?fwc=1
It requires replacing the contents of textmate_ruby with the code below and never running rvm wrapper xxx textmate again.
#!/usr/bin/env sh
source ~/.rvm/scripts/rvm
cd .
exec ruby "$#"
This has also fixed the same issue with the cucumber bundle.
Did you try following the instructions here: http://rvm.io/integration/textmate/
My case is slightly different but took me more than an hour to figure out:
Turns out I ran rvm wrapper ree textmate a while after installing ree with rvm and in the mean time the ree shorthand changed from meaning ree-1.8.7-2010.01 to ree-1.8.7-2010.02
here's more details on my message:
https://gist.github.com/721987
I'm posting it here too because it's one of the first pages I landed onto while trying to figure this one out.
I've got a similar problem and figured out that my textmate ruby wrapper is pointing to a different version. I was able to get it work by putting below content in projectx/.rvmrc
rvm 1.9.2#projectx --create
rvm wrapper 1.9.2#projectx textmate
Hope this helps.

Ruby cannot find required libraries even though gem is installed

I have spent literally days trying to install ruby 1.9.2 and get it working with gems :-/ I eventually gave up on my Mac OSX 10.6 machine and below is the current state on my Ubuntu machine. Any advice would be greatly appreciated!
# ruby test.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mongo (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from test.rb:1:in `<main>'
# cat test.rb
require 'mongo'
db = Mongo::Connection.new.db("mydb")
# gem which mongo
/usr/local/rvm/gems/ruby-1.9.2-p0/gems/mongo-1.1.2/lib/mongo.rb
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"
According to this page: http://docs.rubygems.org/read/chapter/19
I symlinked which ruby I was using to match that which gem is using:
# which ruby
/usr/local/rvm/bin/ruby
# ls -l `which ruby`
lrwxrwxrwx 1 root root 44 2010-11-17 13:25 /usr/local/rvm/bin/ruby -> /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
# gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
# which gem
/usr/local/rvm/bin/gem
# gem -v
1.3.7
# ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Try putting the following line at the beginning
require "rubygems"
Why is "rvm" displaying in your /usr/local/rvm/ path? Did you do a system-wide install, as a system administrator using administering Ruby system wide for multiple users?
Did you add [[ -s '/usr/local/lib/rvm' ]] && source '/usr/local/lib/rvm' to your ~/.bashrc, ~/.bash_profile or ~/.profile (whichever you have configured)?
For normal, every day use, I recommend RVM's default setup:
RVM installation, RVM gems management.
Note to self: Buy stock in RVM. It's too cool.
Does it work under Ruby 1.8.7, which is pre-installed by default on OS X?
If so, one difference between 1.9.1 and 1.9.2 is that "." isn't part of $:'s path any more.
I recommend that you do rvm implode and delete the current setup. Then use the railsready script to setup RVM and Ruby properly for you on Ubuntu. It's important to understand that until you know what you are doing you should run the script as a user. Hope that helps.
On linux and OS X, I have always had to put require "rubygems" in the beginning. However it has always worked fine without this line on windows.

I see gem in "gem list" but have "no such file to load"

I am on Ubuntu10
sudo apt-get install ruby1.9.1-full
then download sources of rubygem 1.3.7 and install it
sudo ruby setup.rb
then, for example, install sinatra
sudo gem install sinatra
Finally open irb and type
require "rubygems"
require "sinatra"
and get error
LoadError: no such file to load -- sinatra
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
I had exactly this problem. The problem is that gem and ruby disagree about where the gems live. Compare these:
ruby -e "puts Gem.path"
gem env
gem which sinatra
If you're like my setup, you'll notice that there's an entry in gem env's paths that isn't in Gem.path, and that's exactly where sinatra will claim to be. In my case, I had to add
export GEM_HOME=/usr/lib/ruby/gems/1.9.1
to my .profile. Then everyone was happy.
Execute
sudo gem install sinatra --verbose
and note the path where the gem is getting installed.
Then try this in irb
puts $LOAD_PATH
and make sure that gem is installed in one of the directories in $LOAD_PATH
And ideally just start using http://rvm.beginrescueend.com/
I usually hit this error when I forget:
require 'rubygems'
It'd be helpful if you provided the actual code sample, though, what gem you want to require, and what Ruby version you're using if this doesn't solve the problem.
This was before here on SO quite a few times. Problem is that you probably have two versions of ruby. The one is installing the gem and the other one is trying to use it. Do this in terminal:
$ which -a ruby
Or this:
$ which -a gem
to see if you have more than one version of ruby/gem installed. If so - remove one version (via $ rm or package manager of your system).
I use ruby gems 1.8.7 for a project. I was getting the same error. Use the line require 'rubygems'. It must always be the first require statement, otherwise you can get an error. In my code, I had
require 'watir'
require 'rubygems'
# more code
I got the error - in `require': no such file to load -- watir (LoadError).
When I put rubygems first, the error went away and everything worked. I don't know
why this happens.
Btw, I tried user24359 answer and it did not help me.
C:\code>ruby -e "puts Gem.path"
-e:1: uninitialized constant Gem (NameError)

Resources