Class: RubyIndexer::ConfigurationTest
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- RubyIndexer::ConfigurationTest
- Defined in:
- lib/ruby_indexer/test/configuration_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_configuration_raises_for_unknown_keys ⇒ Object
- #test_indexables_avoids_duplicates_if_bundle_path_is_inside_project ⇒ Object
- #test_indexables_does_not_include_default_gem_path_when_in_bundle ⇒ Object
- #test_indexables_does_not_include_gems_own_installed_files ⇒ Object
- #test_indexables_does_not_include_non_ruby_files_inside_rubylibdir ⇒ Object
- #test_indexables_includes_default_gems ⇒ Object
- #test_indexables_includes_project_files ⇒ Object
- #test_indexables_only_includes_gem_require_paths ⇒ Object
- #test_load_configuration_executes_configure_block ⇒ Object
- #test_magic_comments_regex ⇒ Object
- #test_paths_are_unique ⇒ Object
Instance Method Details
#setup ⇒ Object
8 9 10 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 8 def setup @config = Configuration.new end |
#test_configuration_raises_for_unknown_keys ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 104 def test_configuration_raises_for_unknown_keys Psych::Nodes::Document.any_instance.expects(:to_ruby).returns({ "unknown_config" => 123 }) assert_raises(ArgumentError) do @config.load_config end end |
#test_indexables_avoids_duplicates_if_bundle_path_is_inside_project ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 66 def test_indexables_avoids_duplicates_if_bundle_path_is_inside_project Bundler.settings.set_global("path", "vendor/bundle") config = Configuration.new config.load_config assert_includes(config.instance_variable_get(:@excluded_patterns), "#{Dir.pwd}/vendor/bundle/**/*.rb") ensure Bundler.settings.set_global("path", nil) end |
#test_indexables_does_not_include_default_gem_path_when_in_bundle ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 37 def test_indexables_does_not_include_default_gem_path_when_in_bundle @config.load_config indexables = @config.indexables assert( indexables.none? { |indexable| indexable.full_path.start_with?("#{RbConfig::CONFIG["rubylibdir"]}/psych") }, ) end |
#test_indexables_does_not_include_gems_own_installed_files ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 76 def test_indexables_does_not_include_gems_own_installed_files @config.load_config indexables = @config.indexables assert( indexables.none? do |indexable| indexable.full_path.start_with?(Bundler.bundle_path.join("gems", "ruby-lsp").to_s) end, ) end |
#test_indexables_does_not_include_non_ruby_files_inside_rubylibdir ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 87 def test_indexables_does_not_include_non_ruby_files_inside_rubylibdir path = Pathname.new(RbConfig::CONFIG["rubylibdir"]).join("extra_file.txt").to_s FileUtils.touch(path) indexables = @config.indexables assert(indexables.none? { |indexable| indexable.full_path == path }) ensure FileUtils.rm(T.must(path)) end |
#test_indexables_includes_default_gems ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 46 def test_indexables_includes_default_gems @config.load_config indexables = @config.indexables.map(&:full_path) assert_includes(indexables, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb") assert_includes(indexables, "#{RbConfig::CONFIG["rubylibdir"]}/ipaddr.rb") assert_includes(indexables, "#{RbConfig::CONFIG["rubylibdir"]}/abbrev.rb") end |
#test_indexables_includes_project_files ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 55 def test_indexables_includes_project_files @config.load_config indexables = @config.indexables.map(&:full_path) Dir.glob("#{Dir.pwd}/lib/**/*.rb").each do |path| next if path.end_with?("_test.rb") assert_includes(indexables, path) end end |
#test_indexables_only_includes_gem_require_paths ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 23 def test_indexables_only_includes_gem_require_paths @config.load_config indexables = @config.indexables Bundler.locked_gems.specs.each do |lazy_spec| next if lazy_spec.name == "ruby-lsp" spec = Gem::Specification.find_by_name(lazy_spec.name) assert(indexables.none? { |indexable| indexable.full_path.start_with?("#{spec.full_gem_path}/test/") }) rescue Gem::MissingSpecError # Transitive dependencies might be missing when running tests on Windows end end |
#test_load_configuration_executes_configure_block ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 12 def test_load_configuration_executes_configure_block @config.load_config indexables = @config.indexables assert(indexables.none? { |indexable| indexable.full_path.include?("test/fixtures") }) assert(indexables.none? { |indexable| indexable.full_path.include?("minitest-reporters") }) assert(indexables.none? { |indexable| indexable.full_path.include?("ansi") }) assert(indexables.any? { |indexable| indexable.full_path.include?("sorbet-runtime") }) assert(indexables.none? { |indexable| indexable.full_path == __FILE__ }) end |
#test_magic_comments_regex ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 112 def test_magic_comments_regex regex = RubyIndexer.configuration.magic_comment_regex [ "# frozen_string_literal:", "# typed:", "# compiled:", "# encoding:", "# shareable_constant_value:", "# warn_indent:", "# rubocop:", "# nodoc:", "# doc:", "# coding:", "# warn_past_scope:", ].each do |comment| assert_match(regex, comment) end end |
#test_paths_are_unique ⇒ Object
97 98 99 100 101 102 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 97 def test_paths_are_unique @config.load_config indexables = @config.indexables assert_equal(indexables.uniq.length, indexables.length) end |