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

install_if is missing #131

Closed philsturgeon closed 3 years ago

philsturgeon commented 6 years ago

It seems like the BundlerDSL is missing install_if.

undefined method `install_if' for #<Appraisal::Group:0x007fa8301d82a8> (NoMethodError)
Did you mean?  instance_of?
    from /Users/psturgeon/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/appraisal-2.2.0/lib/appraisal/bundler_dsl.rb:25:in `instance_exec'

I'm working on a PR to typhoeus (https://github.com/typhoeus/typhoeus/pull/583) which uses a lot of if's in the Gemfile.

When I run appraisal generate it's running the conditions at the time and building the gemfiles/* with whatever gems it should have based on my ruby version or my ENV vars. This is failing everything when it runs on travis.

If appraisal could support install_if then it would evaluate when bundle check --gemfile=gemfiles/foo || bundle check --gemfile=gemfiles/foo is run instead.

I'll try and get a PR done for this, but im 5 levels deep on this yak shave already.

BrianHawley commented 5 years ago

I've used install_if before, even having to fix it in bundler to get it to work. I'll use an example from that to demonstrate a workaround.

In Gemfile:

if respond_to?(:install_if)
  install_if -> { !ENV['DISPLAY'] && RUBY_PLATFORM =~ /linux/ } do
    gem "headless"
  end
end

Then in Appraisals, at the end of the file:

if !ENV['DISPLAY'] && RUBY_PLATFORM =~ /linux/
  each do |spec|
    spec.gem "headless"
  end
end

Normal if works for the appraisal evaluator, and since it doesn't respond to install_if the guard in Gemfile works.

Note that #151 applies here as well, so if you're doing this trick then make sure to generate the appraisal gemfiles right before you use them, in the same context in which you're going to use them.

n-rodriguez commented 3 years ago

I've made a PR for this issue : https://github.com/thoughtbot/appraisal/pull/176