Skip to content

Commit feef890

Browse files
committed
refactor(spec): update specs to test for exit code
1 parent e7d15a0 commit feef890

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

spec/command_spec.cr

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ errors_command = TestErrorsCommand.new
9494

9595
describe Cling::Command do
9696
it "executes the pre_run only" do
97-
arguments_command.execute %w(--skip)
97+
arguments_command.execute("--skip").should eq 0
9898
end
9999

100100
it "fails on missing arguments" do
@@ -104,13 +104,13 @@ describe Cling::Command do
104104
end
105105

106106
it "executes without errors" do
107-
arguments_command.execute %w(foo bar)
108-
arguments_command.execute %w(foo bar baz qux)
107+
arguments_command.execute("foo bar").should eq 0
108+
arguments_command.execute("foo bar baz qux").should eq 0
109109
end
110110

111111
it "fails on unknown values" do
112112
expect_raises Cling::ValueNotFound do
113-
arguments_command.execute %w(foo)
113+
arguments_command.execute "foo"
114114
end
115115
end
116116

@@ -121,18 +121,18 @@ describe Cling::Command do
121121
end
122122

123123
it "executes without errors" do
124-
options_command.execute %w(--double-foo --bar=true)
124+
options_command.execute("--double-foo --bar=true").should eq 0
125125
end
126126

127127
it "fails on unknown options" do
128128
expect_raises Cling::CommandError do
129-
options_command.execute %w(--double-foo --double-bar)
129+
options_command.execute "--double-foo --double-bar"
130130
end
131131
end
132132

133133
it "fails on invalid options" do
134134
expect_raises Cling::CommandError do
135-
options_command.execute %w(--foo=true --double-foo)
135+
options_command.execute "--foo=true --double-foo"
136136
end
137137

138138
expect_raises Cling::CommandError do
@@ -143,45 +143,44 @@ describe Cling::Command do
143143
it "catches missing required arguments" do
144144
io = IO::Memory.new
145145
hooks_command.stderr = io
146-
hooks_command.execute "--double-foo"
147146

147+
hooks_command.execute("--double-foo").should eq 0
148148
io.to_s.should eq "foo\n"
149149
end
150150

151151
it "catches unknown arguments" do
152152
io = IO::Memory.new
153153
hooks_command.stderr = io
154-
hooks_command.execute "foo --double-foo bar baz"
155154

155+
hooks_command.execute("foo --double-foo bar baz").should eq 0
156156
io.to_s.should eq "bar, baz\n"
157157
end
158158

159159
it "catches an invalid option" do
160160
io = IO::Memory.new
161161
hooks_command.stderr = io
162-
hooks_command.execute "foo --double-foo=true\n"
163162

163+
hooks_command.execute("foo --double-foo=true\n").should eq 1
164164
io.to_s.should eq "Option 'double-foo' takes no arguments\n"
165165
end
166166

167167
it "catches missing required values for options" do
168168
io = IO::Memory.new
169169
hooks_command.stderr = io
170-
hooks_command.execute "foo --double-foo --bar"
171170

171+
hooks_command.execute("foo --double-foo --bar").should eq 1
172172
io.to_s.should eq "Missing required argument for option 'bar'\n"
173173

174174
io.rewind
175-
hooks_command.execute "foo --double-foo -n"
176-
175+
hooks_command.execute("foo --double-foo -n").should eq 1
177176
io.to_s.should eq "Missing required arguments for option 'num'\n"
178177
end
179178

180179
it "catches exceptions for program exit and other errors" do
181-
errors_command.execute %w(--fail-fast)
180+
errors_command.execute("--fail-fast").should eq 1
182181

183182
expect_raises(Exception, "failed slowly") do
184-
errors_command.execute %w()
183+
errors_command.execute ""
185184
end
186185
end
187186
end

spec/helper_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ describe Cling::MainCommand do
4343
it "prints the help message" do
4444
io = IO::Memory.new
4545
command.stdout = io
46-
command.execute ""
4746

47+
command.execute("").should eq 0
4848
io.to_s.chomp.should eq <<-HELP
4949
Runs some Crystal commands
5050
@@ -64,16 +64,16 @@ describe Cling::MainCommand do
6464
it "runs the context command" do
6565
io = IO::Memory.new
6666
command.children["context"].stdout = io
67-
command.execute "context"
6867

68+
command.execute("context").should eq 0
6969
io.to_s.should eq "Fake crystal context command!\n"
7070
end
7171

7272
it "runs the format command" do
7373
io = IO::Memory.new
7474
command.children["format"].stdout = io
75-
command.execute "format"
7675

76+
command.execute("format").should eq 0
7777
io.to_s.should eq "Fake crystal format command!\n"
7878
end
7979
end

spec/main_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe Cling do
3232
it "tests the help command" do
3333
io = IO::Memory.new
3434
command.stdout = io
35-
command.execute ""
3635

36+
command.execute("").should eq 0
3737
io.to_s.should eq <<-HELP
3838
Greets a person
3939
@@ -52,16 +52,16 @@ describe Cling do
5252
it "tests the main command" do
5353
io = IO::Memory.new
5454
command.stdout = io
55-
command.execute %w(Dev)
5655

56+
command.execute("Dev").should eq 0
5757
io.to_s.should eq "Hello, Dev!\n"
5858
end
5959

6060
it "tests the main command with flag" do
6161
io = IO::Memory.new
6262
command.stdout = io
63-
command.execute %w(-c Dev)
6463

64+
command.execute("-c Dev").should eq 0
6565
io.to_s.should eq "HELLO, DEV!\n"
6666
end
6767
end

0 commit comments

Comments
 (0)