Sha256: aec5eeb4e870f3e748fa1b10e42477804c0de132d61a75cec13c50fe2830f99a

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

require "test_helper"
require "rubycritic/source_locator"

describe Rubycritic::SourceLocator do
  before do
    @original_dir = Dir.getwd
    Dir.chdir("test/samples/location")
  end

  describe "#paths" do
    it "finds a single file" do
      paths = ["file0.rb"]
      Rubycritic::SourceLocator.new(paths).paths.must_equal paths
    end

    it "finds files through multiple paths" do
      paths = ["dir1/file1.rb", "file0.rb"]
      Rubycritic::SourceLocator.new(paths).paths.must_equal paths
    end

    it "finds all the files inside a given directory" do
      initial_paths = ["dir1"]
      final_paths = ["dir1/file1.rb"]
      Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
    end

    it "finds all the files" do
      initial_paths = ["."]
      final_paths = ["dir1/file1.rb", "file0.rb"]
      Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
    end

    it "cleans paths of consecutive slashes and useless dots" do
      initial_paths = [".//file0.rb"]
      final_paths = ["file0.rb"]
      Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
    end

    it "ignores paths to non-existent files" do
      initial_paths = ["non_existent_dir1/non_existent_file1.rb", "non_existent_file0.rb"]
      final_paths = []
      Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
    end

    it "ignores paths to files that do not match the Ruby extension" do
      initial_paths = ["file_with_no_extension", "file_with_different_extension.py"]
      final_paths = []
      Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
    end
  end

  describe "#pathnames" do
    it "finds a single file" do
      initial_paths = ["file0.rb"]
      final_pathnames = [Pathname.new("file0.rb")]
      Rubycritic::SourceLocator.new(initial_paths).pathnames.must_equal final_pathnames
    end
  end

  after do
    Dir.chdir(@original_dir)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubycritic-1.0.2 test/lib/rubycritic/source_locator_test.rb
rubycritic-1.0.1 test/lib/rubycritic/source_locator_test.rb
rubycritic-1.0.0 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.16 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.15 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.14 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.13 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.12 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.11 test/lib/rubycritic/source_locator_test.rb
rubycritic-0.0.10 test/lib/rubycritic/source_locator_test.rb