Skip to content

Commit

Permalink
Rename method and reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDaugherty committed Nov 4, 2020
1 parent b95d3c3 commit 6591cf9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
14 changes: 7 additions & 7 deletions lib/better_errors/editor.rb
Expand Up @@ -24,20 +24,14 @@ 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.
#
# @return [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
Expand Down Expand Up @@ -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
Expand Down
106 changes: 53 additions & 53 deletions spec/better_errors/editor_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6591cf9

Please sign in to comment.