[英]Test that all rspec tests have passed from a ruby file
In a ruby file to be run from bash, I want to test that all my rspec
tests have passed. 在要从bash运行的ruby文件中,我想测试我所有的
rspec
测试都通过了。 So I want something like 所以我想要像
#!/usr/bin/env ruby
ls = `rspec spec`
if ls == 'passed' then do something
Is there an rspec
option or some other way to do this? 是否有
rspec
选项或其他某种方式?
rspec
, like a good unix citizen, returns exit code 0 when all was good and a non-zero when there was an error. rspec
像一个良好的unix公民一样,当一切都很好时,返回退出代码0,而在出现错误时返回非零退出代码。
You can use system
, it translates exit codes for you, and returns a boolean-ish value. 您可以使用
system
,它为您转换退出代码,并返回布尔值。
if system('rspec spec')
# all good
end
Also see this answer for more details: ruby system command check exit code 另请参阅此答案以获取更多详细信息: ruby系统命令检查退出代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.