File tree 3 files changed +21
-4
lines changed
3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ private class TestArgsCommand < Cling::Command
17
17
arguments.get " first"
18
18
arguments.get " second"
19
19
end
20
+
21
+ def on_error (ex : Exception )
22
+ # override default behaviour so that it works in specs
23
+ raise ex
24
+ end
20
25
end
21
26
22
27
private class TestOptionsCommand < Cling ::Command
@@ -99,7 +104,9 @@ errors_command = TestErrorsCommand.new
99
104
100
105
describe Cling ::Command do
101
106
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
103
110
end
104
111
105
112
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
33
33
34
34
def run (arguments : Cling ::Arguments , options : Cling ::Options ) : Nil
35
35
end
36
+
37
+ def on_error (ex : Exception )
38
+ # override default behaviour so that it works in specs
39
+ raise ex
40
+ end
36
41
end
37
42
38
43
command = CrystalCommand .new
@@ -43,7 +48,7 @@ describe Cling::MainCommand do
43
48
it " prints the help message" do
44
49
io = IO ::Memory .new
45
50
command.stdout = io
46
- command.execute " "
51
+ command.execute " " rescue nil
47
52
48
53
io.to_s.chomp.should eq <<-HELP
49
54
Runs some Crystal commands
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ private class GreetCommand < Cling::Command
25
25
stdout.puts message
26
26
end
27
27
end
28
+
29
+ def on_error (ex : Exception )
30
+ # override default behaviour so that it works in specs
31
+ raise ex
32
+ end
28
33
end
29
34
30
35
command = GreetCommand .new
@@ -33,7 +38,7 @@ describe Cling do
33
38
it " tests the help command" do
34
39
io = IO ::Memory .new
35
40
command.stdout = io
36
- command.execute " "
41
+ command.execute " " rescue nil
37
42
38
43
io.to_s.should eq <<-HELP
39
44
Greets a person
@@ -53,7 +58,7 @@ describe Cling do
53
58
it " tests the main command" do
54
59
io = IO ::Memory .new
55
60
command.stdout = io
56
- command.execute %w(Dev)
61
+ command.execute %w(Dev) rescue nil
57
62
58
63
io.to_s.should eq " Hello, Dev!\n "
59
64
end
You can’t perform that action at this time.
0 commit comments