How to add Mac-specific gems to bundle on Mac but not on Linux?

后端 未结 5 1633
感动是毒
感动是毒 2020-12-15 04:04

I\'m developing a Rails app on a Mac, and I\'m new to testing, so I just added these gems to my Gemfile:

group :test, :development do
  gem          


        
5条回答
  •  情歌与酒
    2020-12-15 04:41

    The Bundler wiki has a method that adds all gems to Gemfile.lock regardless of platform. It sets require => false depending on the system so you don't need to be able to actually run the gems:

    gem 'rb-inotify', :require => RUBY_PLATFORM.include?('linux') && 'rb-inotify'
    

    And they provide helper methods to make this clean:

    def os_is(re)
      RbConfig::CONFIG['host_os'] =~ re
    end
    
    gem 'rb-fsevent', "~> 0.9.3", platforms: :ruby, install_if: os_is(/darwin/)
    gem 'rb-inotify', "~> 0.8.8", platforms: :ruby, install_if: os_is(/linux/)
    gem 'wdm',        "~> 0.1.0", platforms: [:mswin, :mingw. :x64_mingw], install_if: os_is(/mingw|mswin/i)
    

    On my Windows 7 x64 system running Ubuntu 12.04 in a Vagrant VM, this worked fine, but the :platforms setting was required - the Linux bundler choked on the 'win32console' gem:

    Console.c:1:21: fatal error: windows.h: No such file or directory
    

提交回复
热议问题