From 6591cf998872940ae64086444aa59be30f1cbe9c Mon Sep 17 00:00:00 2001 From: Robin Daugherty Date: Wed, 4 Nov 2020 15:16:47 -0500 Subject: [PATCH] Rename method and reorder --- lib/better_errors/editor.rb | 14 ++-- spec/better_errors/editor_spec.rb | 106 +++++++++++++++--------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/lib/better_errors/editor.rb b/lib/better_errors/editor.rb index cc8bf383..06df7f4d 100644 --- a/lib/better_errors/editor.rb +++ b/lib/better_errors/editor.rb @@ -24,12 +24,6 @@ def self.for_proc(url_proc) new url_proc end - def self.for_symbol(symbol) - KNOWN_EDITORS.each do |preset| - return for_formatting_string(preset[:url]) if preset[:symbols].include?(symbol) - end - end - # Automatically sniffs a default editor preset based on # environment variables. # @@ -37,7 +31,7 @@ def self.for_symbol(symbol) def self.default_editor editor_from_environment_formatting_string || editor_from_environment_editor || - for_symbol(:textmate) + editor_from_symbol(:textmate) end def self.editor_from_environment_editor @@ -66,6 +60,12 @@ def self.editor_from_environment_formatting_string for_formatting_string(ENV['BETTER_ERRORS_EDITOR_URL']) end + def self.editor_from_symbol(symbol) + KNOWN_EDITORS.each do |preset| + return for_formatting_string(preset[:url]) if preset[:symbols].include?(symbol) + end + end + def initialize(url_proc) @url_proc = url_proc end diff --git a/spec/better_errors/editor_spec.rb b/spec/better_errors/editor_spec.rb index efc73608..033c05d5 100644 --- a/spec/better_errors/editor_spec.rb +++ b/spec/better_errors/editor_spec.rb @@ -15,59 +15,6 @@ end end - describe ".for_symbol" do - subject { described_class.for_symbol(symbol) } - - [:atom].each do |symbol| - context "when symbol is '#{symbol}'" do - let(:symbol) { symbol } - - it "uses atom:// scheme" do - expect(subject.url("file", 42)).to start_with("atom://") - end - end - end - - [:emacs, :emacsclient].each do |symbol| - context "when symbol is '#{symbol}'" do - let(:symbol) { symbol } - it "uses emacs:// scheme" do - expect(subject.url("file", 42)).to start_with("emacs://") - end - end - end - - [:macvim, :mvim].each do |symbol| - context "when symbol is '#{symbol}'" do - let(:symbol) { symbol } - - it "uses mvim:// scheme" do - expect(subject.url("file", 42)).to start_with("mvim://") - end - end - end - - [:sublime, :subl, :st].each do |symbol| - context "when symbol is '#{symbol}'" do - let(:symbol) { symbol } - - it "uses subl:// scheme" do - expect(subject.url("file", 42)).to start_with("subl://") - end - end - end - - [:textmate, :txmt, :tm].each do |symbol| - context "when symbol is '#{symbol}'" do - let(:symbol) { symbol } - - it "uses txmt:// scheme" do - expect(subject.url("file", 42)).to start_with("txmt://") - end - end - end - end - describe ".default_editor" do subject(:default_editor) { described_class.default_editor } before do @@ -230,4 +177,57 @@ end end end + + describe ".editor_from_symbol" do + subject { described_class.editor_from_symbol(symbol) } + + [:atom].each do |symbol| + context "when symbol is '#{symbol}'" do + let(:symbol) { symbol } + + it "uses atom:// scheme" do + expect(subject.url("file", 42)).to start_with("atom://") + end + end + end + + [:emacs, :emacsclient].each do |symbol| + context "when symbol is '#{symbol}'" do + let(:symbol) { symbol } + it "uses emacs:// scheme" do + expect(subject.url("file", 42)).to start_with("emacs://") + end + end + end + + [:macvim, :mvim].each do |symbol| + context "when symbol is '#{symbol}'" do + let(:symbol) { symbol } + + it "uses mvim:// scheme" do + expect(subject.url("file", 42)).to start_with("mvim://") + end + end + end + + [:sublime, :subl, :st].each do |symbol| + context "when symbol is '#{symbol}'" do + let(:symbol) { symbol } + + it "uses subl:// scheme" do + expect(subject.url("file", 42)).to start_with("subl://") + end + end + end + + [:textmate, :txmt, :tm].each do |symbol| + context "when symbol is '#{symbol}'" do + let(:symbol) { symbol } + + it "uses txmt:// scheme" do + expect(subject.url("file", 42)).to start_with("txmt://") + end + end + end + end end