ruby test-unit test runner isnt running - ruby

I am attempting to make a custom test runner using test/unit in ruby
and have followed a tutorial outlined here
http://endofline.wordpress.com/2008/02/11/a-custom-testrunner-to-scratch-an-itch/
however when i try to run on it using the
ruby -rfast_fail_runner example_test.rb --runner fastfail
however i get the error
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- fast_fail_runner (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

You have a file in the current directory named fast_fail_runner.rb, right? Ruby is not finding it. You are following a very old tutorial and I suspect that old versions of Ruby had the current directory (.) on the load path or something like that.
Try replacing -rfast_fail_runner with -r./fast_fail_runner.

Related

Error on running a Ruby Application

I'm building an enigma machine simulator in ruby using aptana studio 3 on ubuntu 16.04 LTS.
When I run the application the following error occurs:
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- enigma/rotor.rb (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/xxxx/Downloads/enigma-ruby-master/lib/enigma.rb:1:in `<main>'
Please.
It would be helpful if you added the require code from your ruby file, but I suspect the following
rotor.rb is a file you have created in your enigma project, and is contained in the enigma folder
your require should be
require './enigma/rotor'
or
require './enigma/rotor.rb'
if the enigma directory is a sub-directory of the one you are currently operating in
require './rotor'
or
require './rotor'
This will say to source the file locally and not to look through the general libraries or gem's you may have added

LoadError when executing ruby code in /etc/rc.d/rc.local

I use CentOS 6.6. I want to execute a Ruby code on startup, so I added the following command to execute the code to /etc/rc.d/rc.local.
ruby /ruby/send_mail.rb
In send_mail.rb, there is require 'mail', but error occurred like the following.
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mail (LoadError)
from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /ruby/send_mail:23:in `<main>'
(I got this error by using ruby /ruby/send_mail.rb &> error_output)
I did gem install mail. And "send_mail.rb" works properly when I run this manually. Would you tell me what I should do?
Try running ruby using the RVM wrappers, as described here:
/usr/local/rvm/wrappers/ruby-2.2.2/ruby /ruby/send_mail.rb

Clarification of what Ruby's 'require' does

A heads up that I'm in no way a Ruby expert...I just use it from time to time for basic scripting. I'm trying to use the RubyCocoa framework so that I can use additional commands in my Ruby script.
As an example, if I was to try something as explicit as this:
#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
require '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb'
puts "Hello, World"
I receive this error:
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- osx/objc/cocoa.rb (LoadError)
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb:8:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from Test.rb:4:in `<main>'
I do have Homebrew installed on my Mac (running 10.10), but why does the require command go through to the Cellar folder? You can see I'm trying to use the 2.0 Ruby version from my Frameworks folder (the one in /usr/bin is still 1.9.3 (would also love for someone to explain how these versions differ and why)).
It goes through the Cellar folder because it is in your load path.
You can examine your load path by writing in your script
puts $:
Concerning your error message
You can use fully qualified path in require so
require '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb'
is correct.
And indeed in your error message you can see this line
from /System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/cocoa.rb:8:in `<top (required)>'
So you correctly required your file
However from the first line of your error message.
usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- osx/objc/cocoa.rb (LoadError)
We can see ruby/osx/cocoa.rb tries to require another file. This one is different and found under osx/objc/cocoa.rb. So those files have similar names but are different.
And since it tries to require with require 'osx/objc/cocoa.rb' it fails because it does not know how to find it (not a fully qualified path here).
Maybe you can try to change the load path variable.
By adding the line:
$: << '/System/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/'
It might work but I’m not sure since I don’t know where that osx/obj folder is located on your machine.
you might want to take some time to clean your ruby installation and maybe instead a fresh ruby using rvm or rbenv (I prefer rbenv)

`require': cannot load such file -- hello (LoadError)

I am attempting to run a test against a hello method contained within the hello file:
ruby hello_spec.rb
which returns:
/usr/local/Cellar/ruby/2.1.2_2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- hello (LoadError)
from /usr/local/Cellar/ruby/2.1.2_2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from hello_spec.rb:116:in `<main>'
The files are contained within the same directory. I've installed RSpec and (I believe) the necessary gems. Other people seem to have similar problems but none of the solutions have worked for me.
I am running Ruby 2.1.2
I am new to Ruby and am struggling (obviously) to get the environment properly configured. Any help is much appreciated.
Note: I didn't write any of the test code. I've literally only made the hello.rb file.
Change require 'hello' to require_relative 'hello' in your hello_spec.rb. Current directory is not included in default ruby load path by default.
Or, alternatively, add the current directory to ruby load path:
$:.unshift File.dirname(__FILE__)
Hope it helps.

Need help with require while modifiying a gem (active_merchant)

I'm trying to add a new gateway to the active_merchant gem and I'm having 'require' issues when I try to run it from source.
(I think my problem is not active_merchant-specific, but more of a general Ruby environment issue, so I dont think the specific gem in use has to do with it.)
This is what I've done:
Cloned the Git repo for AM, to my local directory "C:\Users\jb\Documents\Aptana Studio 3 Workspace\active_merchant"
Went about doing the changes in the "billing/gateways" directory (this is just background info..)
Copied the "Sample Usage" example on AM's Git repo to C:\Users\jb\Documents\Aptana Studio 3 Workspace\simple_gw_test.rb, which starts with:
require 'rubygems'
require 'active_merchant'
Ran "ruby simple_gw_test.rb" and got the error message:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:in 'require'
from simple_gw_test.rb:3:in '<main>'
This is understandable, since I don't have active_merchant gem installed
However, I want to use the downloaded source in the sample file, since I'm modifying the gateway source continually.
I tried
require '/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant'
And then got the same error:
<internal:lib/rubygems/custom_require>:29:in require': no such file to load --
/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:inrequire'
from simple_gw_test.rb:2:in `<main>';
Any Ruby Guru who can shed some light greatly appreaciated!
--jb
PS: I'm using MRI 1.9.2 on Windows 7 x64.
Make sure you have read access to that file. Ruby has given me that error before when I didn't have correct permissions.
I guess I scratched my own itch: After a couple of hours of "Pickaxe book-ing" and googling, I got the code necessary to bootstap the gem without it being installed:
require_relative 'active_merchant/lib/active_merchant'

Resources