thoughtbot / appraisal

A Ruby library for testing your library against different versions of dependencies.
https://thoughtbot.com
MIT License
1.26k stars 107 forks source link

Support for multiple rubies? #182

Closed etagwerker closed 1 year ago

etagwerker commented 3 years ago

Hi there,

First of all thanks a lot for building and maintaining appraisal! Secondly, I was wondering if there is a "best practice" for using the gem with multiple rubies?

In rubycritic we are using this gem but don't want certain rubies to run rake test with appraisal because it's a known issue that the gem doesn't have a passing test suite with some combinations of simplecov and ruby 3.0 and ruby 2.4: https://github.com/whitesmith/rubycritic/blob/main/travis_scripts/script.sh#L4-L8

I was wondering if you had any suggestions for appraising certain gemfiles with certain rubies.

Maybe it's a matter of documenting this issue in the README.md so it guides users into doing the right thing? Maybe you can set up your CI configuration to do something like this:

# for ruby 2.7
bundle exec appraisal gemset-4 gemset-5 rake test
# for ruby 3.0
bundle exec appraisal gemset-5 gemset-6 rake test

I'm not sure if that is possible with the current version.

Another way to support multiple rubies could be something like this:

# ...
# 
appraise "gemset-4", rubies: 2.5..2.7 do
  gem "rails", "~>6.0.0"
end

appraise "gemset-5",  rubies: 2.7..3.0 do
  gem "rails", "~>6.1.0"
end

That way, when you run bundle exec appraisal rake test the gem knows what gemsets to appraise based on the current ruby version.

Please let me know your thoughts on this.

Thanks!

adrianthedev commented 3 years ago

I was just about to post the same question.

In https://github.com/avo-hq/avo/ we want to test the package against a few ruby 2.x versions and 3.0. We are using the https://github.com/ddnexus/pagy gem and they use different versions for ruby 2.x and 3.x.

Thank you for your support!

adrianthedev commented 3 years ago

Not sure how this would work. I am on 2.7 and when I run this script it raises an error that it can't install pagy 4 on ruby <2.7 (the host's ruby).

Just as a clarification pagy 3 is for ruby <3.x and pagy 4 for ruby >=3.0.

["6.0", "6.1"].each do |rails_version|
  appraise "rails-#{rails_version}-ruby-2.6" do
    gem "rails", "~> #{rails_version}.0"
  end

  appraise "rails-#{rails_version}-ruby-2.7" do
    gem "rails", "~> #{rails_version}.0"
  end

  appraise "rails-#{rails_version}-ruby-3.0" do
    ruby "3.0"

    gem "rails", "~> #{rails_version}.0"
    gem "pagy", "~> 4.0"
  end
end
n-rodriguez commented 3 years ago

@etagwerker you can also try https://github.com/thoughtbot/appraisal/pull/176

n-rodriguez commented 3 years ago

@adrianthedev you can also try https://github.com/thoughtbot/appraisal/pull/176

nickcharlton commented 3 years ago

My immediate feeling is that #176 would be the right way to do this (I'm going to look at this once I fix several bundler compatibility issues we currently have as I write this).

On projects with multiple Rubies and Appraisal, I typically do this instead: https://github.com/thoughtbot/administrate/blob/main/.circleci/config.yml (see https://github.com/thoughtbot/administrate/pull/1932 for using GitHub Actions instead)

So unlike in your examples, we're running a different Ruby version per container and keep the same Appraisal per Ruby version.

nickcharlton commented 1 year ago

I'm going to close this as it's not moved along in a long time — and hopefully #176 if good enough as a solution for most cases.