Running ruby tests from IntelliJ fails because of teamcity formatter
Hi,
I'm using IntelliJ (2023.3.4) with the ruby plugin, and have a vagrant env setup, and the ruby inside that vagrant as the project's SDK.
When I try to run any test using IntelliJ's run command, I get an error: Unable to load any of [MysqlClient::Adapters::MysqlGem, MysqlClient::Adapters::Mysql2Gem]
If I copy the same command that IntelliJ is running (/vagrant/.rbenv/linux-2.6-libc-2.5-x86_64/versions/2.5.1/bin/ruby /vagrant/.rbenv/linux-2.6-libc-2.5-x86_64/versions/2.5.1/bin/rspec /vagrant/puppet/modules/postgres/spec/integration/import-export/import_tables_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter
) and run it manually inside the vagrant machine, I get the same error, however, if I remove the require and format parts, the test runs fine.
Is there any way to configure IntelliJ to not add that require and formatter? Or alternatively, figure out how to overcome this issue with the formatter? I do not want to install a different mysql gem in that vagrant machine, since it is replicating a production machine.
Thanks,
Ofer
请先登录再写评论。
Hello,
There's no way to remove that from the command being run, but it should not fail with MySQL error. Is your project open source so that it's possible to try to reproduce the problem?
Thanks for the reply.
No, my project is closed source. I'm not sure if mysql is directly connected. It might be required somewhere in one of the helper classes we have, but it's not directly used in the test I'm running here. BTW, this happens with multiple files. Also, the tests we have that do need mysql, pass without a problem when we run them normally without the formatter.
Ofer Zelichover it seems that the problem you're facing is project specific, but it's hard to say which particular part causes it. Could you please take a look at our sample project and change it so that it looks like yours and you get the same behaviour there?
I will try when I have some time, but I doubt I'll be able to reproduce it. The project I'm working on is very large and also uses an old ruby version.
It would be nice if it were just possible to turn off the formatter.
As a workaround you can try creating a corresponding Gem command Run configuration with the necessary parameters.
I'm seeing this too in IntelliJ Ultimate on a Ruby file.
The RSpec runner is adding extra formatting that I don't have:
`--require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter`
```
An error occurred while loading teamcity/spec/runner/formatter/teamcity/formatter.
Failure/Error: raise error
LoadError:
cannot load such file -- teamcity/spec/runner/formatter/teamcity/formatter
```
Could you please provide more details about the issue? Which IDEA version do you use? Do you have the same problem on the latest version (2024.1.1 RC) with our sample app?
For my case, I found out that the formatter is not the issue. You can turn it off by setting a formatter in the runner options, e.g. --format=documentation
This, however, doesn't solve my issue. It seems like IntelliJ is running the test in a shell env that is different from the one I get when I simply log into the container and run the test manually. And that causes some issues with some gems/libraries.
Ofer Zelichover are you using docker Ruby interpreter? You can also check the command being run in the run tool window to compare it.
Olga Kuvardina That sample app is out of date in terms of it's Ruby version and support for a Ruby version that's compatible with Apple Silicon (ARM).
```
WARNING: ruby-2.7.5 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
```
For what it's worth, I got the error with the latest stable IntelliJ Ultimate and Ruby 3.2.2 (using mise), but that shouldn't matter for what the IDE decides to run for flags.
Olga Kuvardina not sure what you mean by “docker Ruby interpreter”. I'm running a vagrant env. that uses virtualbox. That env is set up for the project I'm working on, which unfortunately uses very old Ruby (and I can't change that). When I log into that env. and execute the tests they run fine. I've set up the IntelliJ Project to use the ruby binary inside the vagrant (virtualbox) VM as a remote SDK. It works for some things, but not for running tests.
Jc, we have another sample app with a newer Ruby version. Could you please check it?
Ofer Zelichover in case it uses a very old Ruby (RubyMine works with earlier Ruby MRI versions, from 1.8.7 up to 2.3.0, as is, but there won't be any further updates for them) it might be problematic for us to reproduce the issue. If possible, it'd be great if you could check how it goes with the newer Ruby version and if the problem persists, provide us with steps to reproduce your setup. That would help a lot.