Obromios
Obromios

Reputation: 16383

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. 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?

Upvotes: 1

Views: 44

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230346

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

Upvotes: 4

Related Questions