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

Appraisal evaluates require statement in Gemfile #151

Closed drwl closed 5 years ago

drwl commented 5 years ago

Running bundle exec appraisal install on a gem file that has a conditional is evaluated instead of being copied to the appraisal generated gem file.

# Gemfile
gem 'appraisal'

source('https://rubygems.org') do
  gem 'pry', '~> 0.12.2', require: !ENV['VAR_TO_SET'] <~
end
# This file was generated by Appraisal

gem "appraisal"
gem "awesome_print"

source "https://rubygems.org" do
  gem "pry", "~> 0.12.2", require: true <~
end
BrianHawley commented 5 years ago

This is because the appraisal DSL is a normal Ruby instance_eval with a different evaluation context, rather than using a parser like Ripper and regenerating from the parse tree. Fixing this issue would require rewriting appraisal pretty much from scratch.

One workaround for this that's worked for me is to generate the gemfiles in the same environment that they're used, in the setup code. The gemfile generation is quick, so there's no need to keep the generated files in your repo when you can recreate them all in less than a second in your test setup code. You can add the entire gemfiles directory to your .gitignore with no loss of functionality.

drwl commented 5 years ago

That makes sense. Thanks for the explanation, really appreciate you going in depth! Closing the issue.