Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading Rails or ActiveSupport in tests #510

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Nov 5, 2024

To prevent issues such as #509 we can switch to using Minitest::Test instead of ActiveSupport::TestCase for the test files.

I have temporarily added the test_declarative gem to avoid editing all the test declarations, but if we decide to go ahead then I can do that.

We have one test file (server_test.rb) that does need to load Rails so I have split that out.

There is currently one failing test that I need to look into. fixed

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 5, 2024

@vinistock any thoughts?

@andyw8 andyw8 force-pushed the andyw8/use-minitest branch from 4a88962 to 78f45b1 Compare November 5, 2024 23:23
@andyw8 andyw8 force-pushed the andyw8/use-minitest branch from 553d5c2 to cbc1e25 Compare November 6, 2024 15:27
@andyw8 andyw8 requested a review from vinistock November 6, 2024 18:08

require "test_helper"

require_relative "../test/dummy/config/environment"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the key culprit here. I don't even think we need to switch fully to just Minitest.

As long as we require only the parts of Active Support related to testing, we can continue with the same setup.

But we can't load the dummy app for every test because that will load everything and get us into trouble.

t.test_files = ["test/ruby_lsp_rails/server_test.rb"]
end

task default: [:"db:setup", :test, "test:server"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test if adding a present? in the add-on code breaks when running bundle exec rake?

I think because test:server is last, then the related test helper only gets required at the end, but I'm not 100% sure.

Suggested change
task default: [:"db:setup", :test, "test:server"]
task default: ["db:setup", :test, "test:server"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants