# Ruby scrips getting executed in a loop

**URL:** <https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767>\
**Category:** Ruby\
**Created:** [August 5, 2010, 8:28am UTC](https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767 "2010-08-05T08:28:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 5, 2010, 8:28am UTC](https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767/1 "2010-08-05T08:28:45Z")

</div>

While calling multiple ruby scripts into a single file, my scripts are  
getting executed in a loop. Can someone please suggest me how to carry  
out the execution of all the scripts just once?  
For eg., I have abc.rb, xyz.rb being called out in a single file run.rb  
.  
While execution of run.rb, abc.rb and xyz.rb gets executed once and  
after completion, again the execution of abc.rb starts and the loop  
continues.

---

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 5, 2010, 9:32am UTC](https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767/2 "2010-08-05T09:32:04Z")

</div>

Following is the piece of code in Run.rb . All the three files are  
placed at the same location.

Require ‘abc.rb’  
require ‘xyz.rb’

suite = Test::Unit::TestSuite.new()  
suite \<\< TestSuite\_abc.suite  
suite \<\< TestSuite\_xyz.suite  
FileUtils.mkdir\_p ‘E:\Ruby\reports’  
Test::Unit::UI::Reporter.run(suite, ‘E:\Ruby\reports’, :html)

The last piece of code is for generating a combined html report.

Initially, abc.rb and xyz.rb gets executed individually. After getting  
executed once, a new â€œunnamedâ€ testsuite gets loaded which combines the  
test cases in both the scrips and execute them together.  
I am not sure whether the problem is due to the last piece of code which  
deals with report generation or is there any other issue ?

---

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 5, 2010, 8:41am UTC](https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767/3 "2010-08-05T08:41:01Z")

</div>

On Thu, Aug 5, 2010 at 8:28 AM, Parul K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> While calling multiple ruby scripts into a single file, my scripts are  
> getting executed in a loop. Can someone please suggest me how to carry  
> out the execution of all the scripts just once?  
> For eg., I have abc.rb, xyz.rb being called out in a single file run.rb

What do you mean by “called out”? Can you show the code?

> While execution of run.rb, abc.rb and xyz.rb gets executed once and  
> after completion, again the execution of abc.rb starts and the loop  
> continues.

One scenario I imagine is if you are using load to load the files:

run.rb:  
load ‘abc.rb’  
load ‘xyz.rb’

abc.rb:  
#something

xyz.rb:  
load ‘abc.rb’

This will execute abc.rb twice. It can also happen if you are using  
require but with different paths to abc.rb, for example:

run.rb:  
require ‘lib/abc’

lib/xyz.rb:  
require ‘abc’

I think we need more info to understand your problem.

Jesus.

---

<div class="post-metadata">

**Author:** ![parulg2386](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@parulg2386](https://www.ruby-forum.com/u/parulg2386)\
**Post date:** [August 5, 2010, 10:19am UTC](https://www.ruby-forum.com/t/ruby-scrips-getting-executed-in-a-loop/192767/4 "2010-08-05T10:19:23Z")

</div>

On Thu, Aug 5, 2010 at 9:32 AM, Parul K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Test::Unit::UI::Reporter.run(suite, ‘E:\Ruby\reports’, :html)
> 
> The last piece of code is for generating a combined html report.
> 
> Initially, abc.rb and xyz.rb gets executed individually. After getting  
> executed once, a new “unnamed” testsuite gets loaded which combines the  
> test cases in both the scrips and execute them together.  
> I am not sure whether the problem is due to the last piece of code which  
> deals with report generation or is there any other issue ?

Sorry, I don’t know much about Test::Unit::UI:Reporter, maybe someone  
with experience using that can chime in?

Jesus.
