How can I validate exits and aborts in RSpec?

前端 未结 7 904
傲寒
傲寒 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:16

    There's no need for custom matchers or rescue blocks, simply:

    expect { exit 1 }.to raise_error(SystemExit) do |error|
      expect(error.status).to eq(1)
    end
    

    I'd argue that this is superior because it's explicit and plain Rspec.

提交回复
热议问题