[Solved] Why is it helpful to use irb (as opposed to a GUI-based testing method) when coding with Ruby?


So this question relates to testing and that’s a very broad topic but I’ll try to answer your question from my point of view.

First and foremost we have to agree on a platform on which to stand when talking about Ruby and related web-technologies.

1 – Ruby isn’t strictly a web language. This is a HUGE misconception. Ruby is not Ruby on Rails. And thusly while most applications end up in the browser nowadays, its thanks to RoR and not Ruby.

Ruby is a jack-of-all-trades kind of language, ie. it can do many things. Scripting, web, “normal applications”. If you have a problem, Ruby can as a language more than likely solve it.

2 – IRB is Ruby’s REPL (Read eval print loop) or, more commonly interpreter, it’s not the compiler. It stands for Interactive RuBy shell.

So on to your question:

You don’t test perse with IRB, you use IRB to test smaller type statements like 1 + 1 or perhaps

my_name = "henrik"
my_age = 28
p = Person.new(my_name, my_age)
p.my_name
>> "henrik"

You can think of IRB as “your small testing wizard”, ie. “Does this work, let’s try it in IRB!”.

For real-life testing as you describe it you use RSpec or other types of testing frameworks and if you want to do stand alone testing you might do ruby my_test_file.rb. Where your my_test_file.rb contains all of your tests.

RSpec read this, this is extremely valuable when starting with tests in Ruby.

Doing testing the way you’re describing is extremely tedious but it has nothing to do with IRB .

solved Why is it helpful to use irb (as opposed to a GUI-based testing method) when coding with Ruby?