How can I validate exits and aborts in RSpec?

前端 未结 7 906
傲寒
傲寒 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:05

    try this:

    module MyGem
      describe "CLI" do
        context "execute" do
    
          it "should exit cleanly when -h is used" do
            argv=["-h"]
            out = StringIO.new
            lambda { ::MyGem::CLI.execute( out, argv) }.should raise_error SystemExit
          end
    
        end
      end
    end
    

提交回复
热议问题