Appraisal is often used for testing multiple versions of a Ruby gem's dependencies at once. When authoring a gem that requires compatibility with Rails 4 and 5, appraisal is often used to make this easier:
# Appraisals
appraisal 'rails-4' do
gem 'rails', '~> 4'
end
appraisal 'rails-5' do
gem 'rails', '~> 5'
end
# Install both rails4 and rails5
bundle exec appraisal install
# Run rspec against a certain version of Rails
bundle exec appraisal rails-4 rspec
bundle exec appraisal rails-5 rspec
However, it doesn't seem like Appraisals supports multiple Ruby versions very well. For instance, sprockets's v4 has dropped support for Ruby 2.4. If you would like to test both sprockets v3 and v4, you may need multiple Ruby versions. Consider a setup like this:
# Appraisals
appraisal 'rails-4' do
gem 'rails', '~> 4.0'
gem 'sprockets', '~> 3.0'
end
appraisal 'rails-5' do
gem 'rails', '>= 5.0'
gem 'sprockets', '~> 4.0`
end
When running bundle exec appraisal install
in Ruby 2.4, Appraisal will try to install Sprockets v4 and fail.
Fetching gem metadata from https://rubygems.org/............
sprockets-4.0.0 requires ruby version >= 2.5.0, which is incompatible with the
current version, ruby 2.4.10p364
To support multiple sets of gems with multiple versions of Ruby, maintaining multiple Gemfiles might be a better option than Appraisal.
# Gemfile (the default)
source 'https://rubygems.org'
ruby '~> 2.6.5'
gemspec
gem 'rails', '>= 5'
# Gemfile-legacy (legacy)
source 'https://rubygems.org'
ruby '~> 2.4.5'
gemspec
gem 'rails', '< 5'
gem 'sprockets', '< 4'
# Generates Gemfile.lock
rbenv local 2.6.5
bundle install
# Generates Gemfile-legacy.lock
rbenv local 2.4.10
BUNDLE_GEMFILE=Gemfile-legacy bundle install