Commit 88e3efe

mo khan <mo@mokhan.ca>
2026-03-23 20:18:41
test: check of nil command
1 parent 3419a1b
Changed files (2)
lib
spec
lib/elelem/commands.rb
@@ -29,6 +29,8 @@ module Elelem
 
     def command_for(name)
       hash = @registry[name]
+      return if hash.nil?
+
       SlashCommand.new(name, description: hash[:description], completions: hash[:completions], handler: hash[:handler])
     end
 
spec/elelem/commands_spec.rb
@@ -38,9 +38,9 @@ RSpec.describe Elelem::Commands do
   end
 
   describe "#command_for" do
-    context "when the command is registered" do
-      subject(:command) { commands.command_for("raise") }
+    subject(:command) { commands.command_for("raise") }
 
+    context "when the command is registered" do
       before do
         commands.register("raise", description: "Raises an error", completions: ['heck']) do |args|
           raise args.inspect
@@ -52,6 +52,10 @@ RSpec.describe Elelem::Commands do
       it { expect(command&.description).to eq("Raises an error") }
       it { expect(command&.completions).to match_array(['heck']) }
     end
+
+    context "when the command is not registered" do
+      it { expect(command).to be_nil }
+    end
   end
 
   describe "#run" do