5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/spec_guardian/file_path_resolver.rb', line 5
def self.resolve(file_path, framework)
file_path = file_path.sub(%r{^\./}, '')
relative_path = if file_path.start_with?('app/')
file_path.sub(%r{^app/}, '')
else
file_path
end
test_dir = framework == :rspec ? 'spec' : 'test'
if relative_path.start_with?('models/')
"#{test_dir}/#{relative_path.sub(/\.rb$/, '_spec.rb')}"
elsif relative_path.start_with?('controllers/')
"#{test_dir}/#{relative_path.sub(/\.rb$/, '_spec.rb')}"
elsif relative_path.start_with?('views/')
view_path = relative_path.sub(%r{^views/}, '')
"#{test_dir}/views/#{view_path.sub(/\.\w+\.erb$/, '.html_spec.rb')}"
else
"#{test_dir}/#{relative_path.sub(/\.rb$/, '_spec.rb')}"
end
end
|