|
| 1 | +require "spec_helper" |
| 2 | +require "rubocop" |
| 3 | +require "cc/engine/file_list_resolver" |
| 4 | + |
| 5 | +module CC::Engine |
| 6 | + describe FileListResolver do |
| 7 | + include FilesystemHelpers |
| 8 | + |
| 9 | + before { @code = Dir.mktmpdir } |
| 10 | + let(:rubocop_config) { RuboCop::ConfigStore.new } |
| 11 | + |
| 12 | + it "uses default include path" do |
| 13 | + Dir.chdir(@code) do |
| 14 | + create_source_file("a.rb", "def a; true; end") |
| 15 | + create_source_file("not_ruby.txt", "some text") |
| 16 | + |
| 17 | + resolver = FileListResolver.new(root: @code, engine_config: {}, config_store: rubocop_config) |
| 18 | + expect(resolver.expanded_list).to eq [Pathname.new("a.rb").realpath.to_s] |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + it "finds ruby scripts without extensions" do |
| 23 | + Dir.chdir(@code) do |
| 24 | + create_source_file("a.rb", "def a; true; end") |
| 25 | + create_source_file("bin/some_script", "#!/usr/bin/env ruby") |
| 26 | + |
| 27 | + resolver = FileListResolver.new(root: @code, engine_config: {}, config_store: rubocop_config) |
| 28 | + expect(resolver.expanded_list).to eq %w[a.rb bin/some_script].map { |fn| Pathname.new(fn).realpath.to_s } |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + it "respects engine config include_paths" do |
| 33 | + Dir.chdir(@code) do |
| 34 | + create_source_file("a.rb", "def a; true; end") |
| 35 | + create_source_file("src/b.rb", "def a; true; end") |
| 36 | + |
| 37 | + resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/] }, config_store: rubocop_config) |
| 38 | + expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + it "respects rubocop excludes" do |
| 43 | + Dir.chdir(@code) do |
| 44 | + create_source_file("src/b.rb", "def a; true; end") |
| 45 | + create_source_file("src/c.rb", "def a; true; end") |
| 46 | + create_source_file(".rubocop.yml", "AllCops:\n Exclude:\n - src/c.rb") |
| 47 | + |
| 48 | + resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/] }, config_store: rubocop_config) |
| 49 | + expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + it "handles missing files" do |
| 54 | + Dir.chdir(@code) do |
| 55 | + create_source_file("src/b.rb", "def a; true; end") |
| 56 | + |
| 57 | + resolver = FileListResolver.new(root: @code, engine_config: { "include_paths" => %w[src/ public/assets] }, config_store: rubocop_config) |
| 58 | + expect(resolver.expanded_list).to eq [Pathname.new("src/b.rb").realpath.to_s] |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments