Skip to content

Instantly share code, notes, and snippets.

Last active Dec 10, 2015
What would you like to do?
Exclude gems in heroku Cedar. Heroku will ignore :development and :test by default, but not other groups (such as :cucumber). Previous Bamboo stack let you define BUNDLE_WITHOUT, but it doesn't work anymore on Cedar.
# Put this code in some file and require it at the beginning of your Gemfile
# Then you can list the groups to exclude from heroku. E.g:
# exclude_in_heroku :cucumber, :development, :test
# Based on this post by Matt Campbell:,
# which is based in an idea by @grosser. All the credits to them.
module Bundler
class Dsl
old_group = instance_method(:group)
def exclude_in_heroku(*groups)
@gems_to_exclude = groups
def gems_to_exclude
@gems_to_exclude ||= []
define_method(:group) do |*groups, &block|
should_exclude = groups.find{|group| gems_to_exclude.include?(group)}
groups = (should_exclude && ENV['HOME'].gsub('/', '') == 'app') ? 'test' : groups
old_group.bind(self).(*groups, &block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment