Home > Blockchain >  Rails 7 - Difference between "Rails test" and "bundle exec rake test"
Rails 7 - Difference between "Rails test" and "bundle exec rake test"

Time:07-08

I'm starting a new Rails 7 app and have about 150 tests on Minitest.

I've seen in some places people using in the terminal of command rails test and other places recommending bundle exec rake test

I have some basic tests and when I run both commands in my terminal, the same exact things appear and I have the same amount of tests with the same test results.

So I'm wondering if there is any difference between the two on Rails 7?

CodePudding user response:

The difference between those commands is from where rails is called.

Running commands with bundler allows you to execute them without having the packages installed in your system.

For example, if you don't have rails installed globally you couldn't run commands using rails directly

rails test will raise the following error:

Rails is not currently installed on this system. To get the latest version, simply type:

$ sudo gem install rails

You can then rerun your "rails" command.

But if you run bundle exec rails test instead you should run your test suite perfectly because you're calling rails through bundle.

In your case using bundle exec rake test will ensure that you're using the same version of your Gemfile.lock.

  • Related