传递一个bash脚本错误到控制台在rails中

问题描述:

我有一个shell脚本为我正在处理的应用程序运行一些验收测试。脚本运行测试,检查是否有错误,然后以0(成功)或1(失败)退出。传递一个bash脚本错误到控制台在rails中

我有一个rake任务调用shell脚本,然后得到结果。我遇到的问题是,如何将结果传递到rails控制台,以便当echo $?与shell脚本返回的值相等时?

我当前的代码如下:

def acceptance_tests 
    system("./run_tests.sh"); 
    error_code = $?.success? ? 0 : 1 

    result = error_code == 0 ? 'passed' : 'failed' 
    puts ("The acceptance tests have #{result}.") 

    SystemExit.new(error_code) 
end 

测试通过/如预期,当我运行他们失败了,但他们都完成后,我运行echo $?它总是等于0

有关我在做什么错的任何想法?

+0

你确定你需要你自己定制的测试基础架构吗?当Ruby有很多好的库来完成这个任务吗? – tokland 2011-06-09 14:34:43

最后,改变SystemExit.new()exit()为我工作。

def acceptance_tests 
    system("./run_tests.sh"); 
    error_code = $?.success? ? 0 : 1 

    result = error_code == 0 ? 'passed' : 'failed' 
    puts ("The acceptance tests have #{result}.") 

    exit(error_code) 
end 

SystemExit是个例外,所以提出来:

$ echo "raise SystemExit.new(5)" | ruby; echo $? 
5