3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/splot/corresponding_file.rb', line 3
def self.fetch(file)
catch :test_file do
root_path = Pathname.new File.expand_path Dir.pwd
file_path = Pathname.new File.expand_path file
relative_path = file_path.relative_path_from(root_path).to_s
if %r{\Alib/(?<bit>.*)\.rb} =~ relative_path
['test', 'spec'].each do |e|
try_file "#{e}/lib/#{bit}_#{e}.rb"
try_file "#{e}/#{bit}_#{e}.rb"
end
end
if %r{\Aapp/(?<subdir>[a-z_]+)/(?<bit>.*)\.rb} =~ relative_path
['test', 'spec'].each do |e|
alternate_subdir = {
models: "unit",
controllers: "functional",
}[subdir.to_sym]
try_file "#{e}/#{subdir}/#{bit}_#{e}.rb"
try_file "#{e}/#{alternate_subdir}/#{bit}_#{e}.rb" if alternate_subdir
end
end
file
end
end
|