Permalink
Browse files

make error more like NameError, since this is one

  • Loading branch information...
1 parent c6100f6 commit 720b40b1f442716544b99ebe186467f7402dbc0a @indirect indirect committed Feb 13, 2012
Showing with 8 additions and 14 deletions.
  1. +3 −8 lib/bundler/dsl.rb
  2. +5 −6 spec/bundler/dsl_spec.rb
View
@@ -161,14 +161,9 @@ def env(name)
end
def method_missing(name, *args)
- call = caller[0].split ':'
- line = call[1].to_i
- lines = ([0, line - 3].max)..line + 2
- content = Bundler.read_file(call[0]).lines.to_a[lines].join(' ').strip
-
- raise GemfileError, "The Gemfile doesn't support the method `#{name}`.\n" \
- "Please check your Gemfile's syntax at line #{line}:\n\n" \
- " #{content}\n"
+ location = caller[0].split(':')[0..1].join(':')
+ raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile\n" \
+ " from #{location}"
end
private
View
@@ -22,12 +22,11 @@
describe '#method_missing' do
it 'should raise an error for unknown DSL methods' do
- dsl = Bundler::Dsl.new
- dsl.stub(:caller => ['Gemfile:3'])
- Bundler.should_receive(:read_file).with('Gemfile').and_return("source :rubygems\ngemspec\nunknown")
-
- error_msg = "The Gemfile doesn't support the method `unknown`.\nPlease check your Gemfile's syntax at line 3:\n\n source :rubygems\n gemspec\n unknown\n"
- lambda { dsl.unknown }.should raise_error(Bundler::GemfileError, error_msg)
+ Bundler.should_receive(:read_file).with("Gemfile").and_return("unknown")
+ error_msg = "Undefined local variable or method `unknown'" \
+ " for Gemfile\\s+from Gemfile:1"
+ lambda{ subject.eval_gemfile("Gemfile") }.
+ should raise_error(Bundler::GemfileError, Regexp.new(error_msg))
end
end

0 comments on commit 720b40b

Please sign in to comment.