Skip to content

Commit eece747

Browse files
committed
chore(spec): update to handle pre-run program exits
1 parent 40e3fe2 commit eece747

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

spec/command_spec.cr

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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
2025
end
2126

2227
private class TestOptionsCommand < Cling::Command
@@ -99,7 +104,9 @@ errors_command = TestErrorsCommand.new
99104

100105
describe 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

spec/helper_spec.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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
3641
end
3742

3843
command = 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

spec/main_spec.cr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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
2833
end
2934

3035
command = 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

0 commit comments

Comments
 (0)