summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pry/prompt.rb14
-rw-r--r--spec/prompt_spec.rb21
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb
index 6696b71d..ea71b346 100644
--- a/lib/pry/prompt.rb
+++ b/lib/pry/prompt.rb
@@ -154,6 +154,20 @@ module Pry::Prompt
prompt.proc_array, prompt_name]
end
+ #
+ # @param [String] alias_name
+ # Name of a prompt alias.
+ #
+ # @return [Integer]
+ # Returns the number of removed aliases.
+ #
+ def remove_alias(alias_name)
+ alias_name = alias_name.to_s
+ all_prompts.count do |prompt|
+ PROMPT_MAP[prompt.alias_for].delete(prompt) if prompt.alias? and prompt.name == alias_name
+ end
+ end
+
add_prompt "default",
"The default Pry prompt. Includes information about the\n" \
"current expression number, evaluation context, and nesting\n" \
diff --git a/spec/prompt_spec.rb b/spec/prompt_spec.rb
index 097adfec..55692703 100644
--- a/spec/prompt_spec.rb
+++ b/spec/prompt_spec.rb
@@ -42,6 +42,12 @@ RSpec.describe Pry::Prompt do
described_class.remove_prompt 'prompt-name'
expect(pry_eval("list-prompts")).to_not include("prompt-name")
end
+
+ specify "does not remove aliases" do
+ described_class.alias_prompt "prompt-name", "prompt-alias"
+ described_class.remove_prompt 'prompt-alias'
+ expect(described_class['prompt-alias']).to_not be_nil
+ end
end
describe ".alias_prompt" do
@@ -61,6 +67,21 @@ RSpec.describe Pry::Prompt do
expect(pry_eval("change-prompt prompt-alias", "_pry_.prompt")).to eq(described_class['prompt-name'])
end
end
+
+ describe ".remove_alias" do
+ before do
+ described_class.alias_prompt "prompt-name", "prompt-alias"
+ end
+
+ specify "returns number of removed aliases" do
+ expect(described_class.remove_alias("prompt-alias")).to eq(1)
+ end
+
+ specify "removes alias from Pry::Prompt" do
+ expect(described_class.remove_alias("prompt-alias")).to eq(1)
+ expect(described_class['prompt-alias']).to eq(nil)
+ end
+ end
end
describe "Prompts" do