Skip to content

Commit 6591cf9

Browse files
Rename method and reorder
1 parent b95d3c3 commit 6591cf9

File tree

2 files changed

+60
-60
lines changed

2 files changed

+60
-60
lines changed

lib/better_errors/editor.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@ def self.for_proc(url_proc)
2424
new url_proc
2525
end
2626

27-
def self.for_symbol(symbol)
28-
KNOWN_EDITORS.each do |preset|
29-
return for_formatting_string(preset[:url]) if preset[:symbols].include?(symbol)
30-
end
31-
end
32-
3327
# Automatically sniffs a default editor preset based on
3428
# environment variables.
3529
#
3630
# @return [Symbol]
3731
def self.default_editor
3832
editor_from_environment_formatting_string ||
3933
editor_from_environment_editor ||
40-
for_symbol(:textmate)
34+
editor_from_symbol(:textmate)
4135
end
4236

4337
def self.editor_from_environment_editor
@@ -66,6 +60,12 @@ def self.editor_from_environment_formatting_string
6660
for_formatting_string(ENV['BETTER_ERRORS_EDITOR_URL'])
6761
end
6862

63+
def self.editor_from_symbol(symbol)
64+
KNOWN_EDITORS.each do |preset|
65+
return for_formatting_string(preset[:url]) if preset[:symbols].include?(symbol)
66+
end
67+
end
68+
6969
def initialize(url_proc)
7070
@url_proc = url_proc
7171
end

spec/better_errors/editor_spec.rb

+53-53
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,6 @@
1515
end
1616
end
1717

18-
describe ".for_symbol" do
19-
subject { described_class.for_symbol(symbol) }
20-
21-
[:atom].each do |symbol|
22-
context "when symbol is '#{symbol}'" do
23-
let(:symbol) { symbol }
24-
25-
it "uses atom:// scheme" do
26-
expect(subject.url("file", 42)).to start_with("atom://")
27-
end
28-
end
29-
end
30-
31-
[:emacs, :emacsclient].each do |symbol|
32-
context "when symbol is '#{symbol}'" do
33-
let(:symbol) { symbol }
34-
it "uses emacs:// scheme" do
35-
expect(subject.url("file", 42)).to start_with("emacs://")
36-
end
37-
end
38-
end
39-
40-
[:macvim, :mvim].each do |symbol|
41-
context "when symbol is '#{symbol}'" do
42-
let(:symbol) { symbol }
43-
44-
it "uses mvim:// scheme" do
45-
expect(subject.url("file", 42)).to start_with("mvim://")
46-
end
47-
end
48-
end
49-
50-
[:sublime, :subl, :st].each do |symbol|
51-
context "when symbol is '#{symbol}'" do
52-
let(:symbol) { symbol }
53-
54-
it "uses subl:// scheme" do
55-
expect(subject.url("file", 42)).to start_with("subl://")
56-
end
57-
end
58-
end
59-
60-
[:textmate, :txmt, :tm].each do |symbol|
61-
context "when symbol is '#{symbol}'" do
62-
let(:symbol) { symbol }
63-
64-
it "uses txmt:// scheme" do
65-
expect(subject.url("file", 42)).to start_with("txmt://")
66-
end
67-
end
68-
end
69-
end
70-
7118
describe ".default_editor" do
7219
subject(:default_editor) { described_class.default_editor }
7320
before do
@@ -230,4 +177,57 @@
230177
end
231178
end
232179
end
180+
181+
describe ".editor_from_symbol" do
182+
subject { described_class.editor_from_symbol(symbol) }
183+
184+
[:atom].each do |symbol|
185+
context "when symbol is '#{symbol}'" do
186+
let(:symbol) { symbol }
187+
188+
it "uses atom:// scheme" do
189+
expect(subject.url("file", 42)).to start_with("atom://")
190+
end
191+
end
192+
end
193+
194+
[:emacs, :emacsclient].each do |symbol|
195+
context "when symbol is '#{symbol}'" do
196+
let(:symbol) { symbol }
197+
it "uses emacs:// scheme" do
198+
expect(subject.url("file", 42)).to start_with("emacs://")
199+
end
200+
end
201+
end
202+
203+
[:macvim, :mvim].each do |symbol|
204+
context "when symbol is '#{symbol}'" do
205+
let(:symbol) { symbol }
206+
207+
it "uses mvim:// scheme" do
208+
expect(subject.url("file", 42)).to start_with("mvim://")
209+
end
210+
end
211+
end
212+
213+
[:sublime, :subl, :st].each do |symbol|
214+
context "when symbol is '#{symbol}'" do
215+
let(:symbol) { symbol }
216+
217+
it "uses subl:// scheme" do
218+
expect(subject.url("file", 42)).to start_with("subl://")
219+
end
220+
end
221+
end
222+
223+
[:textmate, :txmt, :tm].each do |symbol|
224+
context "when symbol is '#{symbol}'" do
225+
let(:symbol) { symbol }
226+
227+
it "uses txmt:// scheme" do
228+
expect(subject.url("file", 42)).to start_with("txmt://")
229+
end
230+
end
231+
end
232+
end
233233
end

0 commit comments

Comments
 (0)