derfred
derfred

Reputation: 19831

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.

Upvotes: 2

Views: 828

Answers (3)

user1252065
user1252065

Reputation:

Try:

cp Gemfile.lock Gemfile.lock.orig
bundle install
diff Gemfile.lock Gemfile.lock.orig && echo "Gemfile.lock matches Gemfile"

Upvotes: 3

Aditya Kapoor
Aditya Kapoor

Reputation: 1570

The Gemfile generally doesnot match with the Gemfile.lock becoz the bunder would resolve all the dependencies of the Gem and would place them under name of the Gem in the tree fashion. Moreover, the purpose of Gemfile.lock is simply to resolve the version numbers and other dependencies in case of any conflict which may arise when Bunder finds a number of compatible gems during bundle install.

When you perform the bundle update command, the Gemfile.lock is removed and a new Gemfile.lock is generated with new dependencies...

Upvotes: -1

NARKOZ
NARKOZ

Reputation: 27901

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.

Upvotes: 4

Related Questions