1

In a ruby file to be run from bash, I want to test that all my rspec tests have passed. So I want something like

test_script.rb

#!/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?

Obromios
  • 15,408
  • 15
  • 72
  • 127

1 Answers1

4

rspec, like a good unix citizen, returns exit code 0 when all was good and a non-zero when there was an error.

You can use system, it translates exit codes for you, and returns a boolean-ish value.

if system('rspec spec')
  # all good
end

Also see this answer for more details: ruby system command check exit code

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367