Check if Gemfile.lock matches Gemfile
I want to write a unit test to check if the Gemfile.lock in my project matches the Gemfile in case I forget to call bundle before committing.
Is there an option for the bundle command (or another method) to check this?
Note that bundle check does not suit this purpose. It checks to see if all gems in the Gemfile are installed on the local system, but it does not check the Gemfile.lock. Therefore the bundle install --deployment command on the server can fail even if bundle check succeeds on the development machine or in CI.
cp Gemfile.lock Gemfile.lock.orig bundle install diff Gemfile.lock Gemfile.lock.orig && echo "Gemfile.lock matches Gemfile"
Use bundle check command
Check searches the local machine for each of the gems requested in the Gemfile. If all gems are found, Bundler prints a success message and exits with a status of 0. If not, the first missing gem is listed and Bundler exits status 1.