-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from codeclimate/will/resolve-nonexistent-files
FileListResolver: handle non-existent files
- Loading branch information
Showing
5 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require "spec_helper" | ||
require "rubocop" | ||
require "cc/engine/file_list_resolver" | ||
|
||
module CC::Engine | ||
describe FileListResolver do | ||
include FilesystemHelpers | ||
|
||
before { @code = Dir.mktmpdir } | ||
let(:rubocop_config) { RuboCop::ConfigStore.new } | ||
|
||
it "uses default include path" do | ||
Dir.chdir(@code) do | ||
create_source_file("a.rb", "def a; true; end") | ||
create_source_file("not_ruby.txt", "some text") | ||
|
||
resolver = FileListResolver.new(root: @code, engine_config: {}, config_store: rubocop_config) | ||
expect(resolver.expanded_list).to eq [Pathname.new("a.rb").realpath.to_s] | ||
end | ||
end | ||
|
||
it "finds ruby scripts without extensions" do | ||
Dir.chdir(@code) do | ||
create_source_file("a.rb", "def a; true; end") | ||
create_source_file("bin/some_script", "#!/usr/bin/env ruby") | ||
|
||
resolver = FileListResolver.new(root: @code, engine_config: {}, config_store: rubocop_config) | ||
expect(resolver.expanded_list).to eq %w[a.rb bin/some_script].map { |fn| Pathname.new(fn).realpath.to_s } | ||
end | ||
end | ||
|
||
it "respects engine config include_paths" do | ||
Dir.chdir(@code) do | ||
create_source_file("a.rb", "def a; true; end") | ||
create_source_file("src/b.rb", "def a; true; end") | ||
|
||
resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/] }, config_store: rubocop_config) | ||
expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] | ||
end | ||
end | ||
|
||
it "respects rubocop excludes" do | ||
Dir.chdir(@code) do | ||
create_source_file("src/b.rb", "def a; true; end") | ||
create_source_file("src/c.rb", "def a; true; end") | ||
create_source_file(".rubocop.yml", "AllCops:\n Exclude:\n - src/c.rb") | ||
|
||
resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/] }, config_store: rubocop_config) | ||
expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] | ||
end | ||
end | ||
|
||
it "handles missing files" do | ||
Dir.chdir(@code) do | ||
create_source_file("src/b.rb", "def a; true; end") | ||
|
||
resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/ public/assets] }, config_store: rubocop_config) | ||
expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require "rspec" | ||
|
||
Dir.glob("spec/support/**/*.rb").each(&method(:load)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module FilesystemHelpers | ||
def create_source_file(path, content) | ||
abs_path = File.join(@code, path) | ||
FileUtils.mkdir_p(File.dirname(abs_path)) | ||
File.write(abs_path, content) | ||
end | ||
end |