Permalink
Browse files

Print useful warnings when deprecated options are used

  • Loading branch information...
1 parent e465ed1 commit 5894862b9b38373e6f6231d99ef6cf370594df7c Yehuda Katz committed Feb 4, 2010
Showing with 72 additions and 5 deletions.
  1. +7 −5 lib/bundler.rb
  2. +29 −0 lib/bundler/dsl.rb
  3. +36 −0 spec/install/deprecated_spec.rb
View
12 lib/bundler.rb
@@ -31,11 +31,13 @@ def status_code
end
end
- class GemfileNotFound < BundlerError; status_code(10) ; end
- class GemNotFound < BundlerError; status_code(7) ; end
- class VersionConflict < BundlerError; status_code(6) ; end
- class GemfileError < BundlerError; status_code(4) ; end
- class GitError < BundlerError; status_code(11) ; end
+ class GemfileNotFound < BundlerError; status_code(10) ; end
+ class GemNotFound < BundlerError; status_code(7) ; end
+ class VersionConflict < BundlerError; status_code(6) ; end
+ class GemfileError < BundlerError; status_code(4) ; end
+ class GitError < BundlerError; status_code(11) ; end
+ class DeprecatedMethod < BundlerError; status_code(12) ; end
+ class DeprecatedOption < BundlerError; status_code(12) ; end
class << self
attr_writer :ui, :bundle_path
View
29 lib/bundler/dsl.rb
@@ -18,6 +18,7 @@ def gem(name, *args)
options = Hash === args.last ? args.pop : {}
version = args.last || ">= 0"
+ _deprecated_options(options)
_normalize_options(name, version, options)
@dependencies << Dependency.new(name, version, options)
@@ -53,6 +54,22 @@ def group(name, options = {}, &blk)
@group = old
end
+ # Deprecated methods
+
+ def self.deprecate(name)
+ define_method(name) do |*|
+ raise DeprecatedMethod, "#{name} is removed. See the README for more information"
+ end
+ end
+
+ deprecate :only
+ deprecate :except
+ deprecate :disable_system_gems
+ deprecate :disable_rubygems
+ deprecate :clear_sources
+ deprecate :bundle_path
+ deprecate :bin_path
+
private
def _version?(version)
@@ -83,5 +100,17 @@ def _normalize_options(name, version, opts)
opts["group"] = group
end
+
+ def _deprecated_options(options)
+ if options.include?(:require_as)
+ raise DeprecatedOption, "Please replace :require_as with :require"
+ elsif options.include?(:vendored_at)
+ raise DeprecatedOption, "Please replace :vendored_at with :path"
+ elsif options.include?(:only)
+ raise DeprecatedOption, "Please replace :only with :group"
+ elsif options.include?(:except)
+ raise DeprecatedOption, "The :except option is no longer supported"
+ end
+ end
end
end
View
36 spec/install/deprecated_spec.rb
@@ -0,0 +1,36 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe "gemfile install with gem sources" do
+ before :each do
+ in_app_root
+ end
+
+ %w( only except disable_system_gems disable_rubygems
+ clear_sources bundle_path bin_path ).each do |deprecated|
+
+ it "reports that #{deprecated} is deprecated" do
+ gemfile <<-G
+ #{deprecated}
+ G
+
+ bundle :install
+ out.should =~ /#{deprecated} is removed. See the README for more information/
+ end
+
+ end
+
+
+ %w( require_as vendored_at only except ).each do |deprecated|
+
+ it "reports that :#{deprecated} is deprecated" do
+ gemfile <<-G
+ gem "rack", :#{deprecated} => true
+ G
+
+ bundle :install
+ out.should =~ /Please replace :#{deprecated}|The :#{deprecated} option is no longer supported/
+ end
+
+ end
+
+end

0 comments on commit 5894862

Please sign in to comment.