TL; DR
Yes, use a pessimistic lock ( ~> ) and specify the semantic version for correction ( Major.minor.patch ) for all your gems!
discussion
I am surprised at the lack of clarity on this issue, even "industry experts" told me the other day that Gemfile.lock exists to support gem versions. Wrong!
You want to organize your Gemfile in such a way that you can run bundle update at any time without risking breaking everything. To achieve this:
Specify a patch level version for all your pessimistic blocking gems. This will allow bundle update provide you with fixes, but not make changes.
Specify ref for git gems
The only drawback of this setting is that when a new sweet / main version for the gem comes out, you have to increase the version manually.
Warning script
Think about what happens if you donβt block your gems.
Your gemfile has unlocked gem "rails" for gems, and the version in Gemfile.lock is 4.1.16 . You write code, and at some point you do bundle update . Now your version of Rails switches to 5.2.0 (assuming that some other gems do not interfere with this), and everything breaks.
Do yourself a favor and do not allow it for any gem!
Gemfile Example
# lock that bundler if (version = Gem::Version.new(Bundler::VERSION)) < Gem::Version.new('1.16.3') abort "Bundler version >= 1.16.3 is required. You are running #{version}" end source "http://rubygems.org" # specify explicit ref for git repos gem "entity_validator", git: "https://github.com/plataformatec/devise", ref: "acc45c5a44c45b252ccba65fd169a45af73ff369" # "2018-08-02" # consider hard-lock on gems you do not want to change one bit gem "rails", "5.1.5" # pessimistic lock on your common gems gem "newrelic_rpm", "~> 4.8.0" gem "puma", "~> 3.12.0" group :test do gem "simplecov", "~> 0.16.1", require: false end
Concession
If you are sure that your tests will detect errors caused by changes in the version of the gem, you can try gems with pessimistic blocking in the minor version, and not in the patch.
This will increase the version of the gem within the specified main version, but not in the next.
gem "puma", "~> 3.12"
Epigene Aug 10 '18 at 14:24 2018-08-10 14:24
source share