Skip to content

Commit 096c2a1

Browse files
committed
Apply new expect_syntax_error helper
1 parent 80f1817 commit 096c2a1

25 files changed

+83
-114
lines changed

language/BEGIN_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
end
1616

1717
it "must appear in a top-level context" do
18-
-> { eval "1.times { BEGIN { 1 } }" }.should raise_error(SyntaxError)
18+
expect_syntax_error("1.times { BEGIN { 1 } }")
1919
end
2020

2121
it "uses top-level for self" do

language/block_spec.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
731731

732732
describe "taking identically-named arguments" do
733733
it "raises a SyntaxError for standard arguments" do
734-
-> { eval "lambda { |x,x| }" }.should raise_error(SyntaxError)
735-
-> { eval "->(x,x) {}" }.should raise_error(SyntaxError)
736-
-> { eval "Proc.new { |x,x| }" }.should raise_error(SyntaxError)
734+
expect_syntax_error("lambda { |x,x| }")
735+
expect_syntax_error("->(x,x) {}")
736+
expect_syntax_error("Proc.new { |x,x| }")
737737
end
738738

739739
it "accepts unnamed arguments" do
@@ -790,26 +790,26 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
790790
end
791791

792792
it "can not have the same name as one of the standard parameters" do
793-
-> { eval "[1].each {|foo; foo| }" }.should raise_error(SyntaxError)
794-
-> { eval "[1].each {|foo, bar; glark, bar| }" }.should raise_error(SyntaxError)
793+
expect_syntax_error("[1].each {|foo; foo| }")
794+
expect_syntax_error("[1].each {|foo, bar; glark, bar| }")
795795
end
796796

797797
it "can not be prefixed with an asterisk" do
798-
-> { eval "[1].each {|foo; *bar| }" }.should raise_error(SyntaxError)
798+
expect_syntax_error("[1].each {|foo; *bar| }")
799799
-> do
800800
eval "[1].each {|foo, bar; glark, *fnord| }"
801801
end.should raise_error(SyntaxError)
802802
end
803803

804804
it "can not be prefixed with an ampersand" do
805-
-> { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
805+
expect_syntax_error("[1].each {|foo; &bar| }")
806806
-> do
807807
eval "[1].each {|foo, bar; glark, &fnord| }"
808808
end.should raise_error(SyntaxError)
809809
end
810810

811811
it "can not be assigned default values" do
812-
-> { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
812+
expect_syntax_error("[1].each {|foo; bar=1| }")
813813
-> do
814814
eval "[1].each {|foo, bar; glark, fnord=:fnord| }"
815815
end.should raise_error(SyntaxError)
@@ -821,8 +821,8 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
821821
end
822822

823823
it "only allow a single semi-colon in the parameter list" do
824-
-> { eval "[1].each {|foo; bar; glark| }" }.should raise_error(SyntaxError)
825-
-> { eval "[1].each {|; bar; glark| }" }.should raise_error(SyntaxError)
824+
expect_syntax_error("[1].each {|foo; bar; glark| }")
825+
expect_syntax_error("[1].each {|; bar; glark| }")
826826
end
827827

828828
it "override shadowed variables from the outer scope" do
@@ -963,9 +963,7 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
963963
ruby_version_is ""..."3.4" do
964964
it "raises a SyntaxError if using the argument in its default value" do
965965
a = 1
966-
-> {
967-
eval "proc { |a=a| a }"
968-
}.should raise_error(SyntaxError)
966+
expect_syntax_error "proc { |a=a| a }"
969967
end
970968
end
971969

@@ -1011,7 +1009,7 @@ def c(&); yield :non_null end
10111009
end
10121010

10131011
it "requires the anonymous block parameter to be declared if directly passing a block" do
1014-
-> { eval "def a; b(&); end; def b; end" }.should raise_error(SyntaxError)
1012+
expect_syntax_error("def a; b(&); end; def b; end")
10151013
end
10161014

10171015
it "works when it's the only declared parameter" do

language/break_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,17 @@ def mid(&b)
254254

255255
describe "The break statement in a method" do
256256
it "is invalid and raises a SyntaxError" do
257-
-> {
258-
eval("def m; break; end")
259-
}.should raise_error(SyntaxError)
257+
expect_syntax_error("def m; break; end")
260258
end
261259
end
262260

263261
describe "The break statement in a module literal" do
264262
it "is invalid and raises a SyntaxError" do
265-
code = <<~RUBY
263+
expect_syntax_error <<~RUBY
266264
module BreakSpecs:ModuleWithBreak
267265
break
268266
end
269267
RUBY
270-
271-
-> { eval(code) }.should raise_error(SyntaxError)
272268
end
273269
end
274270

language/case_spec.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,22 @@ def bar; @calls << :bar; end
261261
end
262262

263263
it "raises a SyntaxError when 'else' is used when no 'when' is given" do
264-
-> {
265-
eval <<-CODE
264+
expect_syntax_error <<-CODE
266265
case 4
267266
else
268267
true
269268
end
270-
CODE
271-
}.should raise_error(SyntaxError)
269+
CODE
272270
end
273271

274272
it "raises a SyntaxError when 'else' is used before a 'when' was given" do
275-
-> {
276-
eval <<-CODE
273+
expect_syntax_error <<-CODE
277274
case 4
278275
else
279276
true
280277
when 4; false
281278
end
282-
CODE
283-
}.should raise_error(SyntaxError)
279+
CODE
284280
end
285281

286282
it "supports nested case statements" do

language/def_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def foo(a, b, c, d, e, *f); [a, b, c, d, e, f]; end
133133
end
134134

135135
it "allows only a single * argument" do
136-
-> { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError)
136+
expect_syntax_error('def foo(a, *b, *c); end')
137137
end
138138

139139
it "requires the presence of any arguments that precede the *" do
@@ -199,11 +199,11 @@ def foo(a, b = 2, *args)
199199

200200
ruby_version_is ""..."3.4" do
201201
it "raises a SyntaxError if using the argument in its default value" do
202-
-> {
203-
eval "def foo(bar = bar)
202+
expect_syntax_error <<~RUBY
203+
def foo(bar = bar)
204204
bar
205-
end"
206-
}.should raise_error(SyntaxError)
205+
end
206+
RUBY
207207
end
208208
end
209209

language/encoding_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
end
3232

3333
it "raises a SyntaxError if assigned to" do
34-
-> { eval("__ENCODING__ = 1") }.should raise_error(SyntaxError)
34+
expect_syntax_error("__ENCODING__ = 1")
3535
end
3636
end

language/ensure_spec.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,12 @@ class EnsureInClassExample
240240

241241
describe "An ensure block inside {} block" do
242242
it "is not allowed" do
243-
-> {
244-
eval <<-ruby
245-
lambda {
246-
raise
247-
ensure
248-
}
249-
ruby
250-
}.should raise_error(SyntaxError)
243+
expect_syntax_error <<-ruby
244+
lambda {
245+
raise
246+
ensure
247+
}
248+
ruby
251249
end
252250
end
253251

language/file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe "The __FILE__ pseudo-variable" do
66
it "raises a SyntaxError if assigned to" do
7-
-> { eval("__FILE__ = 1") }.should raise_error(SyntaxError)
7+
expect_syntax_error("__FILE__ = 1")
88
end
99

1010
ruby_version_is ""..."3.3" do

language/hash_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
end
8484

8585
it "with '==>' in the middle raises SyntaxError" do
86-
-> { eval("{:a ==> 1}") }.should raise_error(SyntaxError)
86+
expect_syntax_error("{:a ==> 1}")
8787
end
8888

8989
it "recognizes '!' at the end of the key" do
@@ -95,7 +95,7 @@
9595
end
9696

9797
it "raises a SyntaxError if there is no space between `!` and `=>`" do
98-
-> { eval("{:a!=> 1}") }.should raise_error(SyntaxError)
98+
expect_syntax_error("{:a!=> 1}")
9999
end
100100

101101
it "recognizes '?' at the end of the key" do
@@ -107,7 +107,7 @@
107107
end
108108

109109
it "raises a SyntaxError if there is no space between `?` and `=>`" do
110-
-> { eval("{:a?=> 1}") }.should raise_error(SyntaxError)
110+
expect_syntax_error("{:a?=> 1}")
111111
end
112112

113113
it "constructs a new hash with the given elements" do

language/heredoc_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@
6060
end
6161

6262
it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do
63-
-> {
64-
eval %{<<"HERE\n"\nraises syntax error\nHERE}
65-
}.should raise_error(SyntaxError)
63+
expect_syntax_error %{<<"HERE\n"\nraises syntax error\nHERE}
6664
end
6765

6866
it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do

0 commit comments

Comments
 (0)