How can I validate exits and aborts in RSpec?

前端 未结 7 903
傲寒
傲寒 2020-12-04 23:57

I am trying to spec behaviors for command line arguments my script receives to ensure that all validation passes. Some of my command line arguments will result in abo

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 00:11

    Its not pretty, but I've been using this:

    begin
      do_something
    rescue SystemExit => e
      expect(e.status).to eq 1 # exited with failure status
      # or
      expect(e.status).to eq 0 # exited with success status
    else
      expect(true).eq false # this should never happen
    end
    

提交回复
热议问题