ruby cannot load file when run from LaunchControl? - ruby

I have a ruby file that runs files directly in command line via:
ruby /Users/Greg/Dropbox/source_ruby/myapp/main.rb
When I try to schedule this using LaunchControl on Mac however (using the same command line call) I get the following error?
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- watir-webdriver (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Greg/Dropbox/source_ruby/myapp/main.rb:3:in `<main>'
This is noting the first lines of my main.rb file are:
#!/usr/bin/ruby
require 'watir-webdriver'
require 'nokogiri'
Any ideas why? (i.e. why it would run fine when I open a Terminal session, then use the same command line to run it, but when I try to schedule in LaunchControl I get the error)

actually I managed to find a post/lead that ended up working. The following line added to the beginning of my ruby script made things work:
Selenium::WebDriver::Chrome::Service.executable_path = '/usr/local/bin/chromedriver'
(not sure if one would view this as the root cause fix, c.f. workaround)

Related

Rspec a file which requires others. `require': cannot load such file

Is it possible to run an rspec on a file which requires other files?
my .rb file has the following lines:
require "colorize"
require "./board_initializer"
require "./pieces"
and when running a rake I get the following error:
.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- ./board_initializer (LoadError)
Thanks!
The error means board_initializer.rb isn't in the current working directory for __FILE__. Some ways to resolve this include:
Providing a valid filename argument to require.
Using require_relative with a valid relative path.
Modifying the current LOAD_PATH.
There are certainly other ways to resolve this, but they all amount to ensuring that board_initializer.rb can be found by the interpreter when you load or require the file.

How to run wukong examples?

Wukong looks like a pretty nice Ruby way to get into Hadoop through the streaming interface. However, after looking over the examples at the git page:
https://github.com/infochimps-labs/wukong/tree/master/examples
I have no idea how to actually run any of these and generate output.
EDIT: I tried running the following example:
$ ./word_count.rb --run=local README.txt .
This generates an error:
/Users/evanzamir/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- wukong/script (LoadError)
from /Users/evanzamir/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ./word_count.rb:2:in `<main>'
It seems to be having an issue with the line require 'wukong/script', but I'm not sure how to fix it.

Can't get RSpec to work -- 'require': cannot load such file

I just spent three days of my life banging my head against the wall trying to figure out why a simple 'rake' would not pass my spec file.
If this happens to you: Do not have a space in any folder path!. Seriously. In fact do not have a space in anything you name from here on out.
Here is my console output:
(in /Users/*****/Desktop/Learning Ruby/learn_ruby)
$ rake
/Users/*******/Desktop/Learning Ruby/learn_ruby/00_hello/hello_spec.rb:116:
in `require': cannot load such file -- hello (LoadError)
The failure is caused by the line: require "hello"
This line tells Ruby that it needs to search the load path for a file named hello.rb. However, when it looks at the load path, it can't find that file. You should either remove that line and define your code directly in the spec file, or create a hello.rb file.
Newer versions of RSpec (2.11+ I believe) automatically add subdirectory lib to the load path. Based on your Rakefile it seems you are also loading the current lab directory and the subdirectory solution.
I'm guessing you're expected to put your solution in solution/hello.rb.
What worked for me was changing the require statement to a require_relative
I am using windows and an IDE

Compile ruby script with dependencies on other classes

have a problem with compressing my script.
I have a main.rb and some classes in subfolders like Subfolder/Class.rb
In my main.rb, I have the Classes declared like that:
require './Subfolder/Class.rb'
When I just run my main script, it works. Also my exe works, when it is in the same place as the main.rb.
But when I put the exe somewhere else I get this error:
C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/lib/ruby/site_ruby/1.9.1/rubyge
ms/custom_require.rb:36:in `require': cannot load such file -- ./Parsing/Calibra
tionState (LoadError) from C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/lib/ruby/site_ruby
/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/src/main.rb:9:in `
<main>'
Can I somehow put the dependencies into my exe?
I also tried to include them like that:
ocra main.rb Subfolder/*.rb
But it doesn't help.
Have you tried making a ruby gem out of your project? http://guides.rubygems.org/make-your-own-gem/
Gems define their own dependencies.
Your require is using a relative path from the current directory (which you can see because it starts with "./"
Instead, try:
require 'Subfolder/Class.rb'
And make sure $LOAD_PATH includes the location where all of your ruby code is unpacked (which you can look at by examining $0 (or figure out the full path from $0 and require the .rb with a full path)

(...)in `require': no such file to load -- 'gemname' (LoadError)

I haven been all day training to fix this problem but i couldn't.
The question is easy, i don't want to put anymore the require 'rubygems' line everytime i require a gem...
If i put the require 'rubygems' before any other "require" the file runs perfect but if i don't put the require 'rubygems' line the following error occurs:
(...)in `require': no such file to load -- 'gemname' (LoadError)
I suspect that may be there is some path remaining where to check out the gems repository.
I want to ask you if there is a way to do this.
Thanks a lot.
Cheers,
Juan.
You could invoke you ruby script with
ruby -rubygems script.rb
or add rubygems to RUBYOPT
$ export RUBYOPT="rubygems"
put
require 'rubygems'
as first line of your ruby code and be safe.
of course you can invoke with -rubygems switch (as Peter Krenn wrote) instead of it
In Unix you can:
$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby juans_masterpiece.rb
and in Windows:
SET RUBYOPT=rubygems
or right-click on My Computer->Properties->Advanced->Environment Variables
and then finally add the RUBYOPT variable there. Next time you open a cmd.exe run set and it will be there.
You don't have to put it every time you require a gem — you just have to have it before the first time you require a gem. When you require Rubygems, it replaces the default require with a special one that does all the Rubygems magic.
But that's only in 1.8. You don't have to require Rubygems at all in Ruby 1.9 — so that's a very easy solution to the problem as long as you aren't dependent on 1.8-specific things.
Right-click the Computer Icon, then select Properties, then Additional system parameters, then Environment variables, there is a GUI for changing opts, click Create, put name and value, OK. This is an approximate translation of how you do this on windows 7, if you can't find the place try to google for "changing environment variables in {your windows version here}"

Resources