Commit 88e3efe
Changed files (2)
lib
elelem
spec
elelem
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