File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ private class TestArgsCommand < Cling::Command
1717 arguments.get " first"
1818 arguments.get " second"
1919 end
20+
21+ def on_error (ex : Exception )
22+ # override default behaviour so that it works in specs
23+ raise ex
24+ end
2025end
2126
2227private class TestOptionsCommand < Cling ::Command
@@ -99,7 +104,9 @@ errors_command = TestErrorsCommand.new
99104
100105describe Cling ::Command do
101106 it " executes the pre_run only" do
102- arguments_command.execute %w(--skip)
107+ expect_raises Cling ::ExitProgram do
108+ arguments_command.execute %w(--skip)
109+ end
103110 end
104111
105112 it " fails on missing arguments" do
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ private class CrystalCommand < Cling::MainCommand
3333
3434 def run (arguments : Cling ::Arguments , options : Cling ::Options ) : Nil
3535 end
36+
37+ def on_error (ex : Exception )
38+ # override default behaviour so that it works in specs
39+ raise ex
40+ end
3641end
3742
3843command = CrystalCommand .new
@@ -43,7 +48,7 @@ describe Cling::MainCommand do
4348 it " prints the help message" do
4449 io = IO ::Memory .new
4550 command.stdout = io
46- command.execute " "
51+ command.execute " " rescue nil
4752
4853 io.to_s.chomp.should eq <<-HELP
4954 Runs some Crystal commands
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ private class GreetCommand < Cling::Command
2525 stdout.puts message
2626 end
2727 end
28+
29+ def on_error (ex : Exception )
30+ # override default behaviour so that it works in specs
31+ raise ex
32+ end
2833end
2934
3035command = GreetCommand .new
@@ -33,7 +38,7 @@ describe Cling do
3338 it " tests the help command" do
3439 io = IO ::Memory .new
3540 command.stdout = io
36- command.execute " "
41+ command.execute " " rescue nil
3742
3843 io.to_s.should eq <<-HELP
3944 Greets a person
@@ -53,7 +58,7 @@ describe Cling do
5358 it " tests the main command" do
5459 io = IO ::Memory .new
5560 command.stdout = io
56- command.execute %w(Dev)
61+ command.execute %w(Dev) rescue nil
5762
5863 io.to_s.should eq " Hello, Dev!\n "
5964 end
You can’t perform that action at this time.
0 commit comments