Does Watir work under ruby 1.9.1? - ruby

Here is the .rb program:
require 'watir'
b = Watir::Browser.new
the 2nd line will trigger a ""The program can't start because msvcrt-ruby18.dll
is missing from your computer!" error.
I am using 1.9.1p378 on win32
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
How can I fix this? Thanks for your attention.

I think the problem is that one of the win32 gems that Watir is using hasn't been updated to 1.9.1. We've fixed all the 1.9.1 issues we're aware of with the core Watir code.
Bret

I had to patch Ruby 1.9.1 with these two gems:
win32-api-1.4.0-x86-mswin32-60.gem
win32-open3-0.2.9-x86-mswin32-60.gem
Try doing a Google search for either of those gems and you should find a link. I'd host them myself but I can't access my ftp from here.

Related

Nokogiri Ruby 'require' Issues

I'm new to Ruby and I'm having a lot of trouble trying to use Nokogiri. I've been trying to find a resolution for hours now, so any help is appreciated. I tried searching for and using solutions from other related SO posts before caving and posting my own. When I run ruby -v I get: ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
(Edit: I have updated ruby with updates-alternatives --config ruby and selected /usr/bin/ruby1.9.1 but when I do ruby -v it is now showing version 1.9.3 WTF am I doing wrong here?)
I have a new project directory at ~/workspace/ruby/rubycrawler/ and I used Bundler to install nokogiri, which installed correctly:
Using mini_portile (0.5.2)
Using nokogiri (1.6.1)
Using bundler (1.5.1)
Your bundle is complete!
Running bundle show nokogiri returns /var/lib/gems/1.9.1/gems/nokogiri-1.6.1.
In the directory I'm running the script from I have a simple html file named "index.html". The script I'm trying to run is even simpler (or so I thought):
require 'nokogiri'
page = Nokogiri::HTML(open("index.html"))
puts page.class # Nokogiri::HTML::Document
The error is rubycrawler.rb:1:in 'require': no such file to load -- nokogiri (LoadError).
I also added require 'rubygems' even though I read it isn't needed for 1.9+ and still no luck.
A lot of searching shows "Did you put this gem in your Gemfile?". So I generate a Gemfile and add gem 'nokogiri'. I try running the small script again and get the same error. I read "Try deleting Gemfile.lock." so I did but still couldn't get it to work. I then read to try testing it out in irb so I tested "open-uri" and "nokogiri" and here's what I got:
irb(main):001:0> require 'open-uri'
=> true
irb(main):003:0> require 'nokogiri'
LoadError: no such file to load -- nokogiri
I'm really having a lot of trouble figuring this out, so really any help at all is really appreciated.
Ruby tools like RVM, Bundler, etc., to the novice, appear to do a lot of magic, but really, there is no magic to them. The key here lies in what Bundler actually does for you. It manages a manifest of dependencies, BUT at runtime, those dependencies STILL have to get loaded somehow, and my gut feeling is that is what is not happening here.
Regardless of what version of Ruby you are using, if you are using Bundler, there's an easy way to do this. Precede the command that starts your program with "bundle exec" and that will make Bundler edit Ruby's load path so that it includes all the things in the manifest (Gemfile.lock).
For example:
$ bundle exec ruby foo.rb
A additional note for anyone using RVM: RVM generally will modify the shebangs in the scripts that launch programs like "ruby" or "rake" so that they use the "ruby_no_exec" shell (or similar) instead of the plain old "ruby" shell. That alternate shell is Bundler-aware and makes it generally unnecessary to type "bundle exec," but since the OP is using system Ruby, that's not applicable and commands should be manually prefixed with "bundle exec".
Hope this helps!
In addition to Kent's answer, I would recommend switching to RVM instead of using the system installed ruby. System rubies tend to be horribly out of date, especially when it comes to important things like features and security updates. It might not help you in your current situation, but it would be well worth the time. If you are unfamiliar: http://rvm.io

Unable to generate xml results with ci_reporter using Ruby 1.9.2 with Watir

I have installed Watir 1.7.1, Ruby 1.9.2, ci_reporter 1.6.4, test unit 2.2.0.
Since testunit donot come with Ruby 1.9.2, I installed the testunit seperately.
When I run the script, ci_reporter donot create 'test/reports' folder in the directory iam running the tests. When i execute the script, script runs fine but the folder is not created.
Does the folder 'test/reports' gets created by itself or the 'test/reports' folder should be as part of testunit.
Following is the simple test iam running, please look at the code snippet :
gem 'test-unit'
require 'test/unit/ui/console/testrunner.rb'
require 'ci/reporter/rake/test_unit_loader.rb'
require 'watir'
class My_Test < Test::Unit::TestCase
def test_me
browser = Watir::IE.start('http://www.google.com')
assert(browser.link(:text, 'About Google').exists?)
browser.close
end
end
Does ruby 1.9.2 support ci_reporter 1.6.4?
Can any one help me with an example as to how the reports would be created by ci_reporter and where the reports get stored?
Based on Tiffany's response and the link she gave, I think the answer to your question is 'NO. it is not supported at this time'
I'd also echo the recommendation to use 1.8.7 that's what I've been using for a while now and it is working good with watir.
I think most folks are still using ruby 1.8.7 with Watir. I'm still on 1.8.7, and I use ci_reporter with Watir every day without any problems.
Any chance you can try your code in a 1.8.7 environment? I just found this blog post that indicates that ci_reporter has not been updated to work with ruby 1.9.2: http://www.larkware.com/posts/fix-ci-reporter-for-test-unit-2-dot-0

Ruby Twitter gem

-- UPDATE --
Ok its fixed. This is what I did. remove all ruby and rubygems completely. then install ruby1.9.1-full and rubygems1.9.1 then install the twitter gem.
Hi guys,
I am having trouble working with the Twitter gem. I am using ruby 1.8.7
After installing when I try to run a simple script I get this error
ruby twitter.rb
./twitter.rb:5: uninitialized constant Twitter (NameError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from twitter.rb:2
I running this on a Ubuntu box. I checked with gem -list and I see the Twitter (1.1.0) is listed there.
this is the code I am trying to run
require "rubygems"
require 'twitter'
puts Twitter.user_timeline("test").first.text
Any ideas ?
I believe it only works with Ruby 1.9 If you want to use twitter gem try version 0.9 with Ruby 1.8.x
This works for me:
ruby-1.9.2-p0 > require 'twitter'
=> true
ruby-1.9.2-p0 > puts Twitter.user_timeline("test").first.text
TExES Pedagogy and Professional Responsibilities EC-12 Teacher Certification Test Prep Study Guid… - by Sharon A Wynne http://amzn.to/f3kF74
=> nil
which version of ruby are you using?
gouravtiwari21's comment seems to fix the problem, but it's wrong to suggest that the twitter gem requires 0.9.0 if you want to run it using Ruby 1.8.x.
You can check out the version compatibility here:
http://travis-ci.org/#!/jnunemaker/twitter
It shows the twitter gem working with Ruby installs as low as 1.8.7.
For me, it was an issue with having the correct dependent gems, as well as the correct versions.
Here's how I got it working:
I ran:
sudo gem list
And compared the versions of specific gems with what I found here:
https://github.com/jnunemaker/twitter/blob/master/HISTORY.md (I simply searched for the word 'dependency' to see which versions twitter cared about.
I also found this diff:
https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3
And I compared the gems listed there with what I had installed, and I just made sure my system lined up with what I was seeing in the version notes. Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence.
I'm not sure why I still have to add
gem 'twitter', '1.7.1'
to my Gemfile, but alas, that's the last step required in order to get this stuff working.
Don't forget to restart your server, and you should be good!

Segmentation Fault in rvm'd Ruby on Mac when running RSpec

I was developing something at the uni, saved to my Dropbox intending to continue at home. This is the message that greeted me:
$ spec graph_spec.rb
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/gems/PriorityQueue-0.1.2/ext/priority_queue/CPriorityQueue.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
However,
$ `which spec` graph_spec.rb
...........................................................................
Finished in 0.046973 seconds
75 examples, 0 failures
What the heck is going on here?
For the reference:
$ which spec
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/bin/spec
UPDATE: I just noticed the 1.8.7 there... how did it get there? The top of the spec file says:
$ head `which spec`
#!/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Where does it say "run 1.8.7"?!?
It's likely that RVM is messing your gems and rubies. I would recommend testing on a cleaned up RVM installation (with only 1.9 installed).
Is /Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/rubyreally ruby 1.9.2 ?
Other way to test would be to explicitely run ruby spec so you are sure this is really 1.9.2 which is called.
To conclude, Segfaults do happen in ruby (esp. on 1.8) and are sometimes avoided by reorganizing slightly the ruby code. Good Luck !

Watir with IronRuby!

Has anyone used Watir with IronRuby successfully? I am getting an error that the required file 'Watir' was not found. What path do I need to set to get this file to work in IronRuby?
For some reason my igem command is not working:
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Scripts\bin>igem instal
l watir
'"C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Scripts\bin\ir.exe"'
is not recognized as an internal or external command,
operable program or batch file.
I am using 0.9 version of Ironruby.
I remember that in 0.9 you have to indicate the ir tool: I used the following and got the error again!
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Scripts\bin>ir igem ins
tall watir
ERROR: While executing gem ... (RangeError)
bignum too big to convert into Fixnum
The current version of RubyGems is 1.3.5:
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Scripts\bin>ir igem -v
1.3.5
I even tried using the full path:
require File.dirname(__FILE__) + "C:/ruby/lib/ruby/gems/1.8/gems/commonwatir-1.6.2/lib/watir.rb"
Did you use gem install watir or igem install watir? If you are installing gems for IronRuby you have to use igem. Otherwise, it ends up being put inside the gems directory where your Ruby installation resides. IronRuby will not see that gems directory by default and you would have to use the full path to get to it. When using igem it puts the gem in the correct directory for use with IronRuby.
Watir uses MRI Ruby's WIN32OLE library. Is this library supported with Iron Ruby?
I found that when you get the required watir not found message in regular ruby you need to put before require 'watir' the text require 'rubygems'

Resources