Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
make error more like NameError, since this is one
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Feb 13, 2012
1 parent c6100f6 commit 720b40b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 3 additions & 8 deletions lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 720b40b

Please sign in to comment.