Skip to content

Commit

Permalink
Create files instead of stubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Aug 8, 2024
1 parent e5ad0da commit f403aeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
10 changes: 4 additions & 6 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ def correct_relative_remote_paths
# Detects if the project is a Rails app by looking if the superclass of the main class is `Rails::Application`
sig { returns(T::Boolean) }
def rails_app?
/class .* < Rails::Application/.match?(rails_application_content)
end

sig { returns(T.nilable(String)) }
def rails_application_content
config = Pathname.new("config/application.rb").expand_path
config.read if config.exist?
application_contents = config.read if config.exist?
return false unless application_contents

/class .* < Rails::Application/.match?(application_contents)
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/rails_application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyApp
class Application < Rails::Application
end
end
13 changes: 3 additions & 10 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ def test_creates_custom_bundle_for_a_rails_app
"(bundle check || bundle install) 1>&2",
).returns(true)

# There is some unknown state leak with Bundler which prevents us from creating the
# folder structure ourselves lest we encounter flaky tests
RubyLsp::SetupBundler.any_instance.stubs(:rails_application_content).returns(<<~RUBY)
module MyApp
class Application < Rails::Application
end
end
RUBY

FileUtils.mkdir("config")
FileUtils.cp("test/fixtures/rails_application.rb", "config/application.rb")
Bundler::LockfileParser.any_instance.expects(:dependencies).returns({ "rails" => true }).at_least_once

run_script

assert_path_exists(".ruby-lsp")
Expand All @@ -102,6 +94,7 @@ class Application < Rails::Application
assert_match("ruby-lsp-rails", File.read(".ruby-lsp/Gemfile"))
ensure
FileUtils.rm_r(".ruby-lsp") if Dir.exist?(".ruby-lsp")
FileUtils.rm_rf("config") if Dir.exist?("config")
end

def test_changing_lockfile_causes_custom_bundle_to_be_rebuilt
Expand Down

0 comments on commit f403aeb

Please sign in to comment.