How to call ruby script from another ruby script

1,769 views
Skip to first unread message

al3kc

unread,
Oct 15, 2008, 10:20:31 AM10/15/08
to Watir General
I want to run certain ruby script from another script. I tried to run
it like

it "step1" do
require "test/script.rb"
end

it "step2" do
#other actions
end

but it always fails actions from step2 and then execute script.rb from
step1.

wesley chen

unread,
Oct 15, 2008, 9:03:15 PM10/15/08
to watir-...@googlegroups.com
1. Create rb file 1: test1.rb
class Test1
    def get_s(str)
        puts str
    end
end
test1=Test1.new
test1.get_s("test1 rb")

2. Create rb file 2: test2.rb
require 'watir'
class Test2
    def test2(str)
        puts str
    end
end
test2=Test2.new
test2.test2("In test2")

3. Create rb file 3: test3.rb
require 'watir'
path1= File.dirname(__FILE__)+'/test1.rb'
path2= File.dirname(__FILE__)+'/test2.rb'
system("ruby #{path1}")
system("ruby #{path2}")

Attention: test1.rb, test2.rb and test3.rb should be in the same directory.
In test3.rb, you just need to assign the right file directory, you can use system("ruby #{path}") to run the script you want.

Expect it could help.

Wesley
Man should be hard to himself, but tolerant to others.
Reply all
Reply to author
Forward
0 new messages