thoughtbot / appraisal

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

Dependency download per Appraisal doesn't work #172

Closed matiasgarcia closed 3 years ago

matiasgarcia commented 3 years ago

I have the following gemspec:

spec.add_dependency "activesupport", '~> 5.0', '>= 5.0.0'
  spec.add_dependency "activemodel",'~> 5.0', '>= 5.0.0'
  spec.add_dependency "activerecord", '~> 5.0', '>= 5.0.0'

  spec.add_development_dependency "bundler", "~> 1.15"
  spec.add_development_dependency "rake", "~> 10.0"
  spec.add_development_dependency "rspec", "~> 3.0"
  spec.add_development_dependency "sqlite3", "~> 1.0", ">= 1.0.0"
  spec.add_development_dependency "byebug", "~> 6.0", ">= 6.0.0"
  spec.add_development_dependency "appraisal"

And the Appraisals file:

appraise "rails-5.0" do
  gem "activesupport", '~> 5.0', '>= 5.0.0'
  gem "activemodel",'~> 5.0', '>= 5.0.0'
  gem "activerecord", '~> 5.0', '>= 5.0.0'
end

appraise "rails-5.1" do
  gem "activesupport", '~> 5.1', '>= 5.1.0'
  gem "activemodel",'~> 5.1', '>= 5.1.0'
  gem "activerecord", '~> 5.1', '>= 5.1.0'
end

Gemfile is configured as the following:

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in jsonapi_mapper.gemspec
gemspec

I added a test to see if it's using the proper version:

it 'foo' do
    puts "USING AR #{ActiveRecord.gem_version}"
    puts "USING AS #{ActiveSupport.gem_version}"
    puts "USING AM #{ActiveModel.gem_version}"
  end

However in both runs I get:

USING AR 5.2.4.4
USING AS 5.2.4.4
USING AM 5.2.4.4

I read in the README.md that it seems that things like rbenv won't work nice with Appraisal, so I decided to test this on CircleCI since we are using that as our CI.

I am using the following circle.yml:

version: 2.1

orbs:
  ruby: circleci/ruby@1.0
  slack: circleci/slack@3.4.2

jobs:
  build:
    docker:
      - image: circleci/ruby:2.5.7-node-browsers
        environment:
          BUNDLE_JOBS: 4
          BUNDLE_RETRY: 4
          BUNDLE_PATH: vendor/bundle
          RAILS_ENV: test
          RACK_ENV: test
          IN_CIRCLE: true
    steps:
      - checkout
      - ruby/install-deps:
          bundler-version: 1.17.3
          with-cache: false
      - run:
          name: Install appraisal
          command: bundle exec appraisal install
      - run:
          name: Run specs
          command: bundle exec appraisal rake spec
      - store_artifacts:
          path: /tmp/artifacts
      - slack/status:
          channel: devs-alerts
          fail_only: true
  notify:
    docker:
      - image: circleci/ruby:2.5.7-node-browsers
    steps:
      - slack/status:
          channel: devs-alerts

workflows:
  version: 2
  build:
    jobs:
      - build
      - notify:
          requires:
            - build

Still, in both runs I get the same output:

bundle exec appraisal rake spec
true
>> BUNDLE_GEMFILE=/home/circleci/project/gemfiles/rails_5.0.gemfile bundle exec rake spec
/usr/local/bin/ruby -I/home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.10.0/lib:/home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.0/lib /home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.10.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Reads documents into models
USING AR 5.2.4.4
USING AS 5.2.4.4
USING AM 5.2.4.4
  foo

true
>> BUNDLE_GEMFILE=/home/circleci/project/gemfiles/rails_5.1.gemfile bundle exec rake spec
/usr/local/bin/ruby -I/home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.10.0/lib:/home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.0/lib /home/circleci/project/gemfiles/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.10.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Reads documents into models
USING AR 5.2.4.4
USING AS 5.2.4.4
USING AM 5.2.4.4
  foo

What am I doing wrong?

natematykiewicz commented 3 years ago

The versions in your Appraisal file don't do what you think they do.

gem "activesupport", '~> 5.0', '>= 5.0.0'

~> 5.0 means >= 5.0 and < 6 >= 5.0.0 means 5.0.0 or higher (Rails 6 included).

It's going to install the highest version of the gem that matches all of your criteria (both '~> 5.0' and '>= 5.0.0'), which is going to be the biggest version of 5 that's less than 6, which is 5.2.4.4.

Something I think you should know is: ~> 5.0.0 means >= 5.0.0 and < 5.1 Likewise, ~> 5.0.3 means >= 5.0.3 and < 5.1

I think what you really want is:

appraise "rails-5.0" do
  gem "activesupport", '~> 5.0.0'
  gem "activemodel", '~> 5.0.0'
  gem "activerecord", '~> 5.0.0'
end

appraise "rails-5.1" do
  gem "activesupport", '~> 5.1.0'
  gem "activemodel", '~> 5.1.0'
  gem "activerecord", '~> 5.1.0'
end

This should install 5.0.7.2 in the rails-5.0 appraisal, and 5.1.7 in the rails-5.1 appraisal.

matiasgarcia commented 3 years ago

Thanks @natematykiewicz