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_files_to_index_avoids_duplicates_if_bundle_path_is_inside_project ⇒ Object
- #test_files_to_index_does_not_include_default_gem_path_when_in_bundle ⇒ Object
- #test_files_to_index_does_not_include_gems_own_installed_files ⇒ Object
- #test_files_to_index_includes_default_gems ⇒ Object
- #test_files_to_index_includes_project_files ⇒ Object
- #test_files_to_index_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
86 87 88 89 90 91 92 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 86 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_files_to_index_avoids_duplicates_if_bundle_path_is_inside_project ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 62 def test_files_to_index_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_files_to_index_does_not_include_default_gem_path_when_in_bundle ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 35 def test_files_to_index_does_not_include_default_gem_path_when_in_bundle @config.load_config files_to_index = @config.files_to_index assert(files_to_index.none? { |path| path.start_with?("#{RbConfig::CONFIG["rubylibdir"]}/psych") }) end |
#test_files_to_index_does_not_include_gems_own_installed_files ⇒ Object
72 73 74 75 76 77 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 72 def test_files_to_index_does_not_include_gems_own_installed_files @config.load_config files_to_index = @config.files_to_index assert(files_to_index.none? { |path| path.start_with?(Bundler.bundle_path.join("gems", "ruby-lsp").to_s) }) end |
#test_files_to_index_includes_default_gems ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 42 def test_files_to_index_includes_default_gems @config.load_config files_to_index = @config.files_to_index assert_includes(files_to_index, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb") assert_includes(files_to_index, "#{RbConfig::CONFIG["rubylibdir"]}/ipaddr.rb") assert_includes(files_to_index, "#{RbConfig::CONFIG["rubylibdir"]}/abbrev.rb") end |
#test_files_to_index_includes_project_files ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 51 def test_files_to_index_includes_project_files @config.load_config files_to_index = @config.files_to_index Dir.glob("#{Dir.pwd}/lib/**/*.rb").each do |path| next if path.end_with?("_test.rb") assert_includes(files_to_index, path) end end |
#test_files_to_index_only_includes_gem_require_paths ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 21 def test_files_to_index_only_includes_gem_require_paths @config.load_config files_to_index = @config.files_to_index 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(files_to_index.none? { |path| 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 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 12 def test_load_configuration_executes_configure_block @config.load_config files_to_index = @config.files_to_index assert(files_to_index.none? { |path| path.include?("test/fixtures") }) assert(files_to_index.none? { |path| path.include?("minitest-reporters") }) assert(files_to_index.none? { |path| path == __FILE__ }) end |
#test_magic_comments_regex ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 94 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
79 80 81 82 83 84 |
# File 'lib/ruby_indexer/test/configuration_test.rb', line 79 def test_paths_are_unique @config.load_config files_to_index = @config.files_to_index assert_equal(files_to_index.uniq.length, files_to_index.length) end |