Skip to content

Commit 7849c33

Browse files
committed
Apply new expect_syntax_error helper
1 parent 80f1817 commit 7849c33

26 files changed

+87
-124
lines changed

language/BEGIN_spec.rb

+1-1
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

+15-23
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,29 +790,23 @@ 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)
799-
-> do
800-
eval "[1].each {|foo, bar; glark, *fnord| }"
801-
end.should raise_error(SyntaxError)
798+
expect_syntax_error("[1].each {|foo; *bar| }")
799+
expect_syntax_error("[1].each {|foo, bar; glark, *fnord| }")
802800
end
803801

804802
it "can not be prefixed with an ampersand" do
805-
-> { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
806-
-> do
807-
eval "[1].each {|foo, bar; glark, &fnord| }"
808-
end.should raise_error(SyntaxError)
803+
expect_syntax_error("[1].each {|foo; &bar| }")
804+
expect_syntax_error("[1].each {|foo, bar; glark, &fnord| }")
809805
end
810806

811807
it "can not be assigned default values" do
812-
-> { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
813-
-> do
814-
eval "[1].each {|foo, bar; glark, fnord=:fnord| }"
815-
end.should raise_error(SyntaxError)
808+
expect_syntax_error("[1].each {|foo; bar=1| }")
809+
expect_syntax_error("[1].each {|foo, bar; glark, fnord=:fnord| }")
816810
end
817811

818812
it "need not be preceded by standard parameters" do
@@ -821,8 +815,8 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
821815
end
822816

823817
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)
818+
expect_syntax_error("[1].each {|foo; bar; glark| }")
819+
expect_syntax_error("[1].each {|; bar; glark| }")
826820
end
827821

828822
it "override shadowed variables from the outer scope" do
@@ -963,9 +957,7 @@ def obj.to_ary; raise "Exception raised in #to_ary" end
963957
ruby_version_is ""..."3.4" do
964958
it "raises a SyntaxError if using the argument in its default value" do
965959
a = 1
966-
-> {
967-
eval "proc { |a=a| a }"
968-
}.should raise_error(SyntaxError)
960+
expect_syntax_error "proc { |a=a| a }"
969961
end
970962
end
971963

@@ -1011,7 +1003,7 @@ def c(&); yield :non_null end
10111003
end
10121004

10131005
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)
1006+
expect_syntax_error("def a; b(&); end; def b; end")
10151007
end
10161008

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

language/break_spec.rb

+2-6
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

+4-8
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

+5-5
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

+1-1
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

+6-8
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

+1-1
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

+3-3
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

+1-3
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

language/lambda_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ def create_lambda
266266
ruby_version_is ""..."3.4" do
267267
it "raises a SyntaxError if using the argument in its default value" do
268268
a = 1
269-
-> {
270-
eval "-> (a=a) { a }"
271-
}.should raise_error(SyntaxError)
269+
expect_syntax_error("-> (a=a) { a }")
272270
end
273271
end
274272

language/line_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

1010
before :each do

language/method_spec.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,8 @@ def n(value, &block)
12301230

12311231
context "when the argument looks like an argument list" do
12321232
it "raises a syntax error" do
1233-
-> {
1234-
eval("m (1, 2)")
1235-
}.should raise_error(SyntaxError)
1236-
1237-
-> {
1238-
eval("m (1, 2, 3)")
1239-
}.should raise_error(SyntaxError)
1233+
expect_syntax_error("m (1, 2)")
1234+
expect_syntax_error("m (1, 2, 3)")
12401235
end
12411236
end
12421237

language/next_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def self.enclosing_method
109109
describe "The next statement" do
110110
describe "in a method" do
111111
it "is invalid and raises a SyntaxError" do
112-
-> {
113-
eval("def m; next; end")
114-
}.should raise_error(SyntaxError)
112+
expect_syntax_error("def m; next; end")
115113
end
116114
end
117115
end

language/numbers_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
it "must have a digit before the decimal point" do
2222
0.75.should == 0.75
23-
-> { eval(".75") }.should raise_error(SyntaxError)
24-
-> { eval("-.75") }.should raise_error(SyntaxError)
23+
expect_syntax_error(".75")
24+
expect_syntax_error("-.75")
2525
end
2626

2727
it "can have an exponent" do

language/precedence_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ def >=(a); 0; end;
251251
end
252252

253253
it "<=> == === != =~ !~ are non-associative" do
254-
-> { eval("1 <=> 2 <=> 3") }.should raise_error(SyntaxError)
255-
-> { eval("1 == 2 == 3") }.should raise_error(SyntaxError)
256-
-> { eval("1 === 2 === 3") }.should raise_error(SyntaxError)
257-
-> { eval("1 != 2 != 3") }.should raise_error(SyntaxError)
258-
-> { eval("1 =~ 2 =~ 3") }.should raise_error(SyntaxError)
259-
-> { eval("1 !~ 2 !~ 3") }.should raise_error(SyntaxError)
254+
expect_syntax_error("1 <=> 2 <=> 3")
255+
expect_syntax_error("1 == 2 == 3")
256+
expect_syntax_error("1 === 2 === 3")
257+
expect_syntax_error("1 != 2 != 3")
258+
expect_syntax_error("1 =~ 2 =~ 3")
259+
expect_syntax_error("1 !~ 2 !~ 3")
260260
end
261261

262262
it "<=> == === != =~ !~ have higher precedence than &&" do
@@ -290,8 +290,8 @@ class FalseClass; undef_method :=~; end
290290
end
291291

292292
it ".. ... are non-associative" do
293-
-> { eval("1..2..3") }.should raise_error(SyntaxError)
294-
-> { eval("1...2...3") }.should raise_error(SyntaxError)
293+
expect_syntax_error("1..2..3")
294+
expect_syntax_error("1...2...3")
295295
end
296296

297297
it ".. ... have higher precedence than ? :" do

language/predefined_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ def obj.foo2; yield; end
11001100
end
11011101

11021102
it "raises a SyntaxError if assigned to" do
1103-
-> { eval("nil = true") }.should raise_error(SyntaxError)
1103+
expect_syntax_error("nil = true")
11041104
end
11051105
end
11061106

@@ -1110,7 +1110,7 @@ def obj.foo2; yield; end
11101110
end
11111111

11121112
it "raises a SyntaxError if assigned to" do
1113-
-> { eval("true = false") }.should raise_error(SyntaxError)
1113+
expect_syntax_error("true = false")
11141114
end
11151115
end
11161116

@@ -1120,13 +1120,13 @@ def obj.foo2; yield; end
11201120
end
11211121

11221122
it "raises a SyntaxError if assigned to" do
1123-
-> { eval("false = nil") }.should raise_error(SyntaxError)
1123+
expect_syntax_error("false = nil")
11241124
end
11251125
end
11261126

11271127
describe "The self pseudo-variable" do
11281128
it "raises a SyntaxError if assigned to" do
1129-
-> { eval("self = 1") }.should raise_error(SyntaxError)
1129+
expect_syntax_error("self = 1")
11301130
end
11311131
end
11321132

language/redo_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858

5959
describe "in a method" do
6060
it "is invalid and raises a SyntaxError" do
61-
-> {
62-
eval("def m; redo; end")
63-
}.should raise_error(SyntaxError)
61+
expect_syntax_error("def m; redo; end")
6462
end
6563
end
6664
end

language/regexp/character_classes_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
/[^[:lower:]A-C]+/.match("abcABCDEF123def").to_a.should == ["DEF123"] # negated character class
9090
/[:alnum:]+/.match("a:l:n:u:m").to_a.should == ["a:l:n:u:m"] # should behave like regular character class composed of the individual letters
9191
/[\[:alnum:]+/.match("[:a:l:n:u:m").to_a.should == ["[:a:l:n:u:m"] # should behave like regular character class composed of the individual letters
92-
-> { eval('/[[:alpha:]-[:digit:]]/') }.should raise_error(SyntaxError) # can't use character class as a start value of range
92+
expect_syntax_error('/[[:alpha:]-[:digit:]]/')
9393
end
9494

9595
it "matches ASCII characters with [[:ascii:]]" do

0 commit comments

Comments
 (0)