Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to do this to make unit testing a breeze for myself.

The contents of an example script in question are as follows:

irb
require 'random_utils.rb'
a = SuccessChecker.new

Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…

What you want is to provide the script to irb via STDIN

irb <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF

But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:

ruby <<EOF
require 'random_utils.rb'
a = SuccessChecker.new
EOF
share|improve this answer
    
I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something. –  ac7v Aug 8 '12 at 23:21
    
@ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things. –  Ulrich Dangel Aug 8 '12 at 23:25
    
I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again. –  ac7v Aug 8 '12 at 23:32

Looks like you're ready to take the next step and use a unit testing library.

Here's an introduction to minitest, built into Ruby 1.9.

share|improve this answer
    
Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead! –  ac7v Aug 13 '12 at 3:03
    
Cool, hope you enjoy it :) –  Andrew H Aug 13 '12 at 7:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.