If all files are written in Ruby, you can probably require
your test case from your test suite (or vice versa) and call the appropriate methods. However, let’s assume that your test cases are arbitrary executables:
In my test case script, I have a value which is set
true
/false
(pass/fail) as per the test result. I wanttestSuite.rb
script to capture that value …
You could pass this value as an exit status by calling exit
:
# passing_test.rb
exit
# failing_test.rb
exit(false)
# test_suite.rb
system('ruby passing_test.rb') #=> true
system('ruby failing_test.rb') #=> false
Or by printing some value to stdout (use `cmd`
to capture the output):
# passing_test.rb
puts 'passed'
# failing_test.rb
puts 'failed'
# test_suite.rb
`ruby passing_test.rb` #=> "passed\n"
`ruby failing_test.rb` #=> "failed\n"
Or a combination of both. ($?
returns the Process::Status
)
# passing_test.rb
puts 'passed'
exit
# failing_test.rb
puts 'failed'
exit(false)
# test_suite.rb
`ruby passing_test.rb` #=> "passed\n"
$?.success? #=> true
`ruby failing_test.rb` #=> "failed\n"
$?.success? #=> false
3
solved How to get value from another ruby script