Andrew Grimm
Andrew Grimm

Reputation: 81520

How to check from the command line if a gem is in the bundle

My question is like Programmatically check if gem in bundle? , except that I'm wanting to check from the command line, not from within the program.

I've set up CI with codeship for a Rails project, and one of my tests involves running haml-lint. Today, I got a failure because an old branch of the project that doesn't have haml-lint installed was pushed to the repository. I want to be able to test whether haml-lint is installed, so that I won't try running it if it isn't installed.

I could do

bundle exec haml-lint --version

or possibly bundle list plus some text handling, but I want to know if there's something more concise and intention-revealing.

Upvotes: 1

Views: 1836

Answers (2)

dimitry_n
dimitry_n

Reputation: 3019

You can do gem('haml-lint') in from the console, or you can grep for a string in the command line with grep 'haml-lint' Gemfile.

Upvotes: 0

Sergey Moiseev
Sergey Moiseev

Reputation: 2963

Running

bundle list | grep haml-lint 

will work for you. But implementing program code for that is a clear abuse of Rails-way. For avoiding things like that you just better keep Gemfile.lock in your repository and make it fail in case you removed needed gems for some unknown reason. Because how things are handled in Rails and it's why we need CI, to avoid things like that before hitting production. Building additional code to avoid that kill off all bonuses of that.

Upvotes: 1

Related Questions