Skip to content

Commit

Permalink
Add SyntaxError#path
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek authored and andrykonchin committed Mar 29, 2024
1 parent 786d24a commit 4303919
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/exception/fixtures/syntax_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1+1=2
26 changes: 26 additions & 0 deletions core/exception/syntax_error_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../../spec_helper'


ruby_version_is "3.2" do
describe "SyntaxError#path" do
it "returns the file path provided to eval" do
expected = 'speccing.rb'
-> {
eval('if true', TOPLEVEL_BINDING, expected)
}.should raise_error(SyntaxError) { |e|
e.path.should == expected
}
end

it "returns the file path that raised an exception" do
expected_path = fixture(__FILE__, 'syntax_error.rb')
-> {
require_relative 'fixtures/syntax_error'
}.should raise_error(SyntaxError) {|e| e.path.should == expected_path }
end

it "returns nil when constructed directly" do
SyntaxError.new.path.should == nil
end
end
end
4 changes: 2 additions & 2 deletions core/kernel/eval_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
it "includes file and line information in syntax error" do
expected = 'speccing.rb'
-> {
eval('if true',TOPLEVEL_BINDING, expected)
eval('if true', TOPLEVEL_BINDING, expected)
}.should raise_error(SyntaxError) { |e|
e.message.should =~ /#{expected}:1:.+/
}
Expand All @@ -144,7 +144,7 @@
it "evaluates string with given filename and negative linenumber" do
expected_file = 'speccing.rb'
-> {
eval('if true',TOPLEVEL_BINDING, expected_file, -100)
eval('if true', TOPLEVEL_BINDING, expected_file, -100)
}.should raise_error(SyntaxError) { |e|
e.message.should =~ /#{expected_file}:-100:.+/
}
Expand Down

0 comments on commit 4303919

Please sign in to comment.