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 a20372d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 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
15 changes: 9 additions & 6 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def test_creates_custom_bundle_for_a_rails_app

# 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
# 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

Expand All @@ -102,6 +104,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 a20372d

Please sign in to comment.