Skip to content
This repository

Re factor compiler specs to use 'let','match_array','expect',be_nil' #968

Merged
merged 1 commit into from 11 months ago

4 participants

Rajarshi Das Hiro Asari Chris Sinjakli jrubyci
Rajarshi Das

fix the should to expect use let use match_array instead of == use be_nil instead of nil also use expect block instead of lamda block

Hiro Asari
Owner

Please change the subject to use imperative; e.g., "Refactor compiler specs to use 'let'"

Rajarshi Das

hi @BanzaiMan not only let but also many other like be_nil inspite of nil and also match_array,expect so in commit message should I mention all these thanks

Rajarshi Das

Done

Thanks you @BanzaiMan

Rajarshi Das

If it is acceptable then I can proceed to modify many other rspec codes which are still written in older style

Thanks

jrubyci jrubyci merged commit 7dbb03e into from
jrubyci jrubyci closed this
Rajarshi Das rajcybage deleted the branch
Chris Sinjakli

Doesn't changing from the == matcher to match_array makes the tests weaker (they no longer assert on array order)? Wouldn't the eq matcher (which is the same as == but works with the new expect syntax) be the better choice?

My other concern is more to do with test readability: moving the array called "expected" all the way up to the top of the file makes it less clear what that assertion is doing.

Edit: Same goes for "base" being extracted to a let. It's no longer local to where it's being used, and it's not shared between examples so there doesn't seem to be any advantage to using a let.

Rajarshi Das

Please look into Expected vs should for better rspec http://betterspecs.org/#expect yes all let for :base are used in local codes rajcybage@7dbb03e#L0R141 to rajcybage@7dbb03e#L0R154

Rajarshi Das

Please look into the time taken by expect less than should

 Benchmark.bm do |x|
   it "adds an edge to newly created graph" do
    x.report("should"){@graph.edges.size.should be 0}

    x.report("expect"){expect(@graph.edges.size).to eq 0}
  end
 end

  $ rspec spec/ir/directed_graph/directed_graph_spec.rb
                 user     system      total        real
      should  0.004000   0.000000   0.004000 (  0.005000)
      expect  0.003000   0.000000   0.003000 (  0.003000)`
Chris Sinjakli

I'm not disagreeing with the switch from "should" to "expect" (though I wouldn't use that benchmark to justify it, but that's another story*). What I'm saying should be changed is:

  1. Go back from "match_array" to "eq". match_array is the wrong assertion for these tests. The order of the array should be checked.
  2. Get rid of those "let" blocks. They aren't being used to remove repetition of a variable, and moving the example data to the top of the file just makes it less clear what the test is asserting in both cases.

* For those interested in why I don't think those benchmark numbers are a good justification:

  • Even if the numbers are correct, the difference in speed is minimal and unlikely to have a noticeable impact on spec performance.
  • When the time taken the function being benchmarked is so small, you need to run the function many times and take an average of the time taken. There are too many things which could account for a 1ms difference in a function executing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 243 additions and 242 deletions. Show diff stats Hide diff stats

  1. +243 242 spec/compiler/general_spec.rb
485 spec/compiler/general_spec.rb
@@ -41,7 +41,16 @@ def compile_and_run(src)
41 41
42 42 describe "JRuby's compiler" do
43 43 include CompilerTestUtils
44   -
  44 + let(:base){"'0123456789A' =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)/; "}
  45 + let(:expected){[[1, 2, 3, 4, 5, 6, 7, 8],
  46 + [9, 10, 11, 12, 13, 14, 15, 16],
  47 + [17, 18, 19, 20, 21, 22, 23, 24],
  48 + [25, 26, 27, 28, 29, 30, 31, 32],
  49 + [33, 34, 35, 36, 37, 38, 39, 40],
  50 + [41, 42, 43, 44, 45, 46, 47, 48],
  51 + [49, 50, 51, 52, 53, 54, 55, 56],
  52 + [57, 58, 59, 60, 61, 62, 63, 64]]}
  53 +
45 54 StandardASMCompiler = org.jruby.compiler.impl.StandardASMCompiler
46 55 ASTCompiler = is19 ? org.jruby.compiler.ASTCompiler19 : org.jruby.compiler.ASTCompiler
47 56 ASTInspector = org.jruby.compiler.ASTInspector
@@ -49,37 +58,37 @@ def compile_and_run(src)
49 58 IRubyObject = org.jruby.runtime.builtin.IRubyObject
50 59
51 60 it "assigns literal values to locals" do
52   - compile_and_run("a = 5; a").should == 5
53   - compile_and_run("a = 5.5; a").should == 5.5
54   - compile_and_run("a = 'hello'; a").should == 'hello'
55   - compile_and_run("a = :hello; a").should == :hello
56   - compile_and_run("a = 1111111111111111111111111111; a").should == 1111111111111111111111111111
57   - compile_and_run("a = [1, ['foo', :hello]]; a").should == [1, ['foo', :hello]]
58   - compile_and_run("{}").should == {}
59   - compile_and_run("a = {:foo => {:bar => 5.5}}; a").should == {:foo => {:bar => 5.5}}
60   - compile_and_run("a = /foo/; a").should == /foo/
61   - compile_and_run("1..2").should == (1..2)
  61 + expect(compile_and_run("a = 5; a")).to eq 5
  62 + expect(compile_and_run("a = 5.5; a")).to eq 5.5
  63 + expect(compile_and_run("a = 'hello'; a")).to eq 'hello'
  64 + expect(compile_and_run("a = :hello; a")).to eq :hello
  65 + expect(compile_and_run("a = 1111111111111111111111111111; a")).to eq 1111111111111111111111111111
  66 + expect(compile_and_run("a = [1, ['foo', :hello]]; a")).to match_array([1, ['foo', :hello]])
  67 + expect(compile_and_run("{}")).to eq({})
  68 + expect(compile_and_run("a = {:foo => {:bar => 5.5}}; a")).to eq({:foo => {:bar => 5.5}})
  69 + expect(compile_and_run("a = /foo/; a")).to eq(/foo/)
  70 + expect(compile_and_run("1..2")).to eq (1..2)
62 71 end
63 72
64 73 it "compiles interpolated strings" do
65   - compile_and_run('a = "hello#{42}"; a').should == 'hello42'
66   - compile_and_run('i = 1; a = "hello#{i + 42}"; a').should == "hello43"
  74 + expect(compile_and_run('a = "hello#{42}"; a')).to eq('hello42')
  75 + expect(compile_and_run('i = 1; a = "hello#{i + 42}"; a')).to eq("hello43")
67 76 end
68 77
69 78 it "compiles calls" do
70   - compile_and_run("'bar'.capitalize").should == 'Bar'
71   - compile_and_run("rand(10)").class.should == Fixnum
  79 + expect(compile_and_run("'bar'.capitalize")).to eq 'Bar'
  80 + expect(compile_and_run("rand(10)")).to be_a_kind_of Fixnum
72 81 end
73 82
74 83 it "compiles branches" do
75   - compile_and_run("a = 1; if 1 == a; 2; else; 3; end").should == 2
76   - compile_and_run("a = 1; unless 1 == a; 2; else; 3; end").should == 3
77   - compile_and_run("a = 1; while a < 10; a += 1; end; a").should == 10
78   - compile_and_run("a = 1; until a == 10; a += 1; end; a").should == 10
79   - compile_and_run("2 if true").should == 2
80   - compile_and_run("2 if false").should == nil
81   - compile_and_run("2 unless true").should == nil
82   - compile_and_run("2 unless false").should == 2
  84 + expect(compile_and_run("a = 1; if 1 == a; 2; else; 3; end")).to eq 2
  85 + expect(compile_and_run("a = 1; unless 1 == a; 2; else; 3; end")).to eq 3
  86 + expect(compile_and_run("a = 1; while a < 10; a += 1; end; a")).to eq 10
  87 + expect(compile_and_run("a = 1; until a == 10; a += 1; end; a")).to eq 10
  88 + expect(compile_and_run("2 if true")).to eq 2
  89 + expect(compile_and_run("2 if false")).to be_nil
  90 + expect(compile_and_run("2 unless true")).to be_nil
  91 + expect(compile_and_run("2 unless false")).to eq 2
83 92 end
84 93
85 94 it "compiles while loops with no body" do
@@ -87,68 +96,67 @@ def compile_and_run(src)
87 96 end
88 97
89 98 it "compiles boolean operators" do
90   - compile_and_run("1 && 2").should == 2
91   - compile_and_run("nil && 2").should == nil
92   - compile_and_run("nil && fail").should == nil
93   - compile_and_run("1 || 2").should == 1
94   - compile_and_run("nil || 2").should == 2
95   - lambda {compile_and_run(nil || fail)}.should raise_error(RuntimeError)
96   - compile_and_run("1 and 2").should == 2
97   - compile_and_run("1 or 2").should == 1
  99 + expect(compile_and_run("1 && 2")).to eq 2
  100 + expect(compile_and_run("nil && 2")).to be_nil
  101 + expect(compile_and_run("nil && fail")).to be_nil
  102 + expect(compile_and_run("1 || 2")).to eq 1
  103 + expect(compile_and_run("nil || 2")).to eq 2
  104 + expect {compile_and_run(nil || fail)}.to raise_error(RuntimeError)
  105 + expect(compile_and_run("1 and 2")).to eq 2
  106 + expect(compile_and_run("1 or 2")).to eq 1
98 107 end
99 108
100 109 it "compiles begin blocks" do
101   - compile_and_run("begin; a = 4; end; a").should == 4
  110 + expect(compile_and_run("begin; a = 4; end; a")).to eq 4
102 111 end
103 112
104 113 it "compiles regexp matches" do
105   - compile_and_run("/foo/ =~ 'foo'").should == 0
106   - compile_and_run("'foo' =~ /foo/").should == 0
107   - compile_and_run(":aaa =~ /foo/").should == (is19 ? nil : false)
  114 + expect(compile_and_run("/foo/ =~ 'foo'")).to eq 0
  115 + expect(compile_and_run("'foo' =~ /foo/")).to eq 0
  116 + expect(compile_and_run(":aaa =~ /foo/")).to (is19 ? be_nil : be_false)
108 117 end
109 118
110 119 it "compiles method definitions" do
111   - compile_and_run("def foo3(arg); arg + '2'; end; foo3('baz')").should == 'baz2'
112   - compile_and_run("def self.foo3(arg); arg + '2'; end; self.foo3('baz')").should == 'baz2'
  120 + expect(compile_and_run("def foo3(arg); arg + '2'; end; foo3('baz')")).to eq 'baz2'
  121 + expect(compile_and_run("def self.foo3(arg); arg + '2'; end; self.foo3('baz')")).to eq 'baz2'
113 122 end
114 123
115 124 it "compiles calls with closures" do
116   - compile_and_run("def foo2(a); a + yield.to_s; end; foo2('baz') { 4 }").should == 'baz4'
117   - compile_and_run("def foo2(a); a + yield.to_s; end; foo2('baz') {}").should == 'baz'
118   - compile_and_run("def self.foo2(a); a + yield.to_s; end; self.foo2('baz') { 4 }").should == 'baz4'
119   - compile_and_run("def self.foo2(a); a + yield.to_s; end; self.foo2('baz') {}").should == 'baz'
  125 + expect(compile_and_run("def foo2(a); a + yield.to_s; end; foo2('baz') { 4 }")).to eq 'baz4'
  126 + expect(compile_and_run("def foo2(a); a + yield.to_s; end; foo2('baz') {}")).to eq 'baz'
  127 + expect(compile_and_run("def self.foo2(a); a + yield.to_s; end; self.foo2('baz') { 4 }")).to eq 'baz4'
  128 + expect(compile_and_run("def self.foo2(a); a + yield.to_s; end; self.foo2('baz') {}")).to eq 'baz'
120 129 end
121 130
122 131 if is19
123 132 it "compiles strings with encoding" do
124 133 str8bit = '"\300"'
125 134 str8bit_result = compile_and_run(str8bit)
126   - str8bit_result.should == "\300"
127   - str8bit_result.encoding.should == Encoding::ASCII_8BIT
  135 + expect(str8bit_result).to eq "\300"
  136 + expect(str8bit_result.encoding).to eq Encoding::ASCII_8BIT
128 137 end
129 138 end
130 139
131 140 it "compiles backrefs" do
132   - base = "'0123456789A' =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)/; "
133   - compile_and_run(base + "$~").class.should == MatchData
134   - compile_and_run(base + "$`").should == '0'
135   - compile_and_run(base + "$'").should == 'A'
136   - compile_and_run(base + "$+").should == '9'
137   - compile_and_run(base + "$0").should == $0 # main script name, not related to matching
138   - compile_and_run(base + "$1").should == '1'
139   - compile_and_run(base + "$2").should == '2'
140   - compile_and_run(base + "$3").should == '3'
141   - compile_and_run(base + "$4").should == '4'
142   - compile_and_run(base + "$5").should == '5'
143   - compile_and_run(base + "$6").should == '6'
144   - compile_and_run(base + "$7").should == '7'
145   - compile_and_run(base + "$8").should == '8'
146   - compile_and_run(base + "$9").should == '9'
  141 + expect(compile_and_run(base + "$~")).to be_a_kind_of MatchData
  142 + expect(compile_and_run(base + "$`")).to eq '0'
  143 + expect(compile_and_run(base + "$'")).to eq 'A'
  144 + expect(compile_and_run(base + "$+")).to eq '9'
  145 + expect(compile_and_run(base + "$0")).to eq $0 # main script name, not related to matching
  146 + expect(compile_and_run(base + "$1")).to eq '1'
  147 + expect(compile_and_run(base + "$2")).to eq '2'
  148 + expect(compile_and_run(base + "$3")).to eq '3'
  149 + expect(compile_and_run(base + "$4")).to eq '4'
  150 + expect(compile_and_run(base + "$5")).to eq '5'
  151 + expect(compile_and_run(base + "$6")).to eq '6'
  152 + expect(compile_and_run(base + "$7")).to eq '7'
  153 + expect(compile_and_run(base + "$8")).to eq '8'
  154 + expect(compile_and_run(base + "$9")).to eq '9'
147 155 end
148 156
149 157 it "compiles aliases" do
150   - compile_and_run("alias :to_string1 :to_s; defined?(self.to_string1)").should == "method"
151   - compile_and_run("alias to_string2 to_s; defined?(self.to_string2)").should == "method"
  158 + expect(compile_and_run("alias :to_string1 :to_s; defined?(self.to_string1)")).to eq "method"
  159 + expect(compile_and_run("alias to_string2 to_s; defined?(self.to_string2)")).to eq "method"
152 160 end
153 161
154 162 it "compiles block-local variables" do
@@ -176,11 +184,11 @@ def a
176 184 arr << x
177 185 arr
178 186 EOS
179   - compile_and_run(blocks_code).should == [1,2,3,4,5,6]
  187 + expect(compile_and_run(blocks_code)).to match_array([1,2,3,4,5,6])
180 188 end
181 189
182 190 it "compiles yield" do
183   - compile_and_run("def foo; yield 1; end; foo {|a| a + 2}").should == 3
  191 + expect(compile_and_run("def foo; yield 1; end; foo {|a| a + 2}")).to eq 3
184 192
185 193 yield_in_block = <<-EOS
186 194 def foo
@@ -200,34 +208,34 @@ def foo
200 208 p = foo { 1 }
201 209 p.call
202 210 EOS
203   - compile_and_run(yield_in_proc).should == 1
  211 + expect(compile_and_run(yield_in_proc)).to eq 1
204 212 end
205 213
206 214 it "compiles attribute assignment" do
207   - compile_and_run("def a=(x); 2; end; self.a = 1").should == 1
208   - compile_and_run("def a; 1; end; def a=(arg); fail; end; self.a ||= 2").should == 1
209   - compile_and_run("public; def a; @a; end; def a=(arg); @a = arg; 4; end; x = self.a ||= 1; [x, self.a]").should == [1,1]
210   - compile_and_run("def a; nil; end; def a=(arg); fail; end; self.a &&= 2").should == nil
211   - compile_and_run("public; def a; @a; end; def a=(arg); @a = arg; end; @a = 3; x = self.a &&= 1; [x, self.a]").should == [1,1]
  215 + expect(compile_and_run("def a=(x); 2; end; self.a = 1")).to eq 1
  216 + expect(compile_and_run("def a; 1; end; def a=(arg); fail; end; self.a ||= 2")).to eq 1
  217 + expect(compile_and_run("public; def a; @a; end; def a=(arg); @a = arg; 4; end; x = self.a ||= 1; [x, self.a]")).to match_array([1,1])
  218 + expect(compile_and_run("def a; nil; end; def a=(arg); fail; end; self.a &&= 2")).to be_nil
  219 + expect(compile_and_run("public; def a; @a; end; def a=(arg); @a = arg; end; @a = 3; x = self.a &&= 1; [x, self.a]")).to match_array([1,1])
212 220 end
213 221
214 222 it "compiles lastline" do
215   - compile_and_run("def foo; $_ = 1; bar; $_; end; def bar; $_ = 2; end; foo").should == 1
  223 + expect(compile_and_run("def foo; $_ = 1; bar; $_; end; def bar; $_ = 2; end; foo")).to eq 1
216 224 end
217 225
218 226 it "compiles closure arguments" do
219   - compile_and_run("a = 0; [1].each {|a|}; a").should == (is19 ? 0 : 1)
220   - compile_and_run("a = 0; [1].each {|x| a = x}; a").should == 1
  227 + expect(compile_and_run("a = 0; [1].each {|a|}; a")).to is19 ? eq(0) : eq(1)
  228 + expect(compile_and_run("a = 0; [1].each {|x| a = x}; a")).to eq 1
221 229 if !is19
222   - compile_and_run("[1].each {|@a|}; @a").should == 1
223   - compile_and_run("[[1]].each {|@a|}; @a").should == [1]
224   - compile_and_run("1.times {|@@a|}; @@a").should == 0
225   - compile_and_run("a = []; 1.times {|a[0]|}; a[0]").should == 0
226   - compile_and_run("a = Class.new do; attr_accessor :foo; end.new; 1.times {|a.foo|}; a.foo").should == 0
  230 + expect(compile_and_run("[1].each {|@a|}; @a")).to eq 1
  231 + expect(compile_and_run("[[1]].each {|@a|}; @a")).to match_array([1])
  232 + expect(compile_and_run("1.times {|@@a|}; @@a")).to eq 0
  233 + expect(compile_and_run("a = []; 1.times {|a[0]|}; a[0]")).to eq 0
  234 + expect(compile_and_run("a = Class.new do; attr_accessor :foo; end.new; 1.times {|a.foo|}; a.foo")).to eq 0
227 235 end
228   - compile_and_run("[[1,2,3]].each {|x,*y| break y}").should == [2,3]
229   - compile_and_run("1.times {|x,*y| break y}").should == []
230   - compile_and_run("1.times {|x,*|; break x}").should == 0
  236 + expect(compile_and_run("[[1,2,3]].each {|x,*y| break y}")).to match_array([2,3])
  237 + expect(compile_and_run("1.times {|x,*y| break y}")).to match_array([])
  238 + expect(compile_and_run("1.times {|x,*|; break x}")).to eq 0
231 239 end
232 240
233 241 it "compiles class definitions" do
@@ -239,7 +247,7 @@ def foo
239 247 end
240 248 CompiledClass1.new.foo
241 249 EOS
242   - compile_and_run(class_string).should == 'cc1'
  250 + expect(compile_and_run(class_string)).to eq 'cc1'
243 251 end
244 252
245 253 it "compiles module definitions" do
@@ -252,138 +260,138 @@ def self.bar
252 260 CompiledModule1.bar
253 261 EOS
254 262
255   - compile_and_run(module_string).should == 'cm1'
  263 + expect(compile_and_run(module_string)).to eq 'cm1'
256 264 end
257 265
258 266 it "compiles operator assignment" do
259   - compile_and_run("class H; attr_accessor :v; end; H.new.v ||= 1").should == 1
260   - compile_and_run("class H; def initialize; @v = true; end; attr_accessor :v; end; H.new.v &&= 2").should == 2
261   - compile_and_run("class H; def initialize; @v = 1; end; attr_accessor :v; end; H.new.v += 3").should == 4
  267 + expect(compile_and_run("class H; attr_accessor :v; end; H.new.v ||= 1")).to eq 1
  268 + expect(compile_and_run("class H; def initialize; @v = true; end; attr_accessor :v; end; H.new.v &&= 2")).to eq 2
  269 + expect(compile_and_run("class H; def initialize; @v = 1; end; attr_accessor :v; end; H.new.v += 3")).to eq 4
262 270 end
263 271
264 272 it "compiles optional method arguments" do
265   - compile_and_run("def foo(a,b=1);[a,b];end;foo(1)").should == [1,1]
266   - compile_and_run("def foo(a,b=1);[a,b];end;foo(1,2)").should == [1,2]
267   - lambda{compile_and_run("def foo(a,b=1);[a,b];end;foo")}.should raise_error(ArgumentError)
268   - lambda{compile_and_run("def foo(a,b=1);[a,b];end;foo(1,2,3)")}.should raise_error(ArgumentError)
269   - compile_and_run("def foo(a=(b=1));[a,b];end;foo").should == [1,1]
270   - compile_and_run("def foo(a=(b=1));[a,b];end;foo(2)").should == [2,nil]
271   - compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1)").should == [1,1,1]
272   - compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1,2)").should == [1,2,nil]
273   - lambda{compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1,2,3)")}.should raise_error(ArgumentError)
  273 + expect(compile_and_run("def foo(a,b=1);[a,b];end;foo(1)")).to match_array([1,1])
  274 + expect(compile_and_run("def foo(a,b=1);[a,b];end;foo(1,2)")).to match_array([1,2])
  275 + expect{compile_and_run("def foo(a,b=1);[a,b];end;foo")}.to raise_error(ArgumentError)
  276 + expect{compile_and_run("def foo(a,b=1);[a,b];end;foo(1,2,3)")}.to raise_error(ArgumentError)
  277 + expect(compile_and_run("def foo(a=(b=1));[a,b];end;foo")).to match_array([1,1])
  278 + expect(compile_and_run("def foo(a=(b=1));[a,b];end;foo(2)")).to match_array([2,nil])
  279 + expect(compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1)")).to match_array([1,1,1])
  280 + expect(compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1,2)")).to match_array([1,2,nil])
  281 + expect{compile_and_run("def foo(a, b=(c=1));[a,b,c];end;foo(1,2,3)")}.to raise_error(ArgumentError)
274 282 end
275 283
276 284 if is19
277 285 it "compiles grouped and intra-list rest args" do
278 286 result = compile_and_run("def foo(a, (b, *, c), d, *e, f, (g, *h, i), j); [a,b,c,d,e,f,g,h,i,j]; end; foo(1,[2,3,4],5,6,7,8,[9,10,11],12)")
279   - result.should == [1, 2, 4, 5, [6, 7], 8, 9, [10], 11, 12]
  287 + expect(result).to match_array([1, 2, 4, 5, [6, 7], 8, 9, [10], 11, 12])
280 288 end
281 289 end
282 290
283 291 it "compiles splatted values" do
284   - compile_and_run("def foo(a,b,c);[a,b,c];end;foo(1, *[2, 3])").should == [1,2,3]
285   - compile_and_run("class Coercible1;def to_ary;[2,3];end;end; [1, *Coercible1.new]").should == [1,2,3]
  292 + expect(compile_and_run("def foo(a,b,c);[a,b,c];end;foo(1, *[2, 3])")).to match_array([1,2,3])
  293 + expect(compile_and_run("class Coercible1;def to_ary;[2,3];end;end; [1, *Coercible1.new]")).to match_array([1,2,3])
286 294 end
287 295
288 296 it "compiles multiple assignment" do
289   - compile_and_run("a = nil; 1.times { a, b, @c = 1, 2, 3; a = [a, b, @c] }; a").should == [1,2,3]
290   - compile_and_run("a, (b, c) = 1; [a, b, c]").should == [1,nil,nil]
291   - compile_and_run("a, (b, c) = 1, 2; [a, b, c]").should == [1,2,nil]
292   - compile_and_run("a, (b, c) = 1, [2, 3]; [a, b, c]").should == [1,2,3]
293   - compile_and_run("class Coercible2;def to_ary;[2,3]; end; end; a, (b, c) = 1, Coercible2.new; [a, b, c]").should == [1,2,3]
  297 + expect(compile_and_run("a = nil; 1.times { a, b, @c = 1, 2, 3; a = [a, b, @c] }; a")).to match_array([1,2,3])
  298 + expect(compile_and_run("a, (b, c) = 1; [a, b, c]")).to match_array([1,nil,nil])
  299 + expect(compile_and_run("a, (b, c) = 1, 2; [a, b, c]")).to match_array([1,2,nil])
  300 + expect(compile_and_run("a, (b, c) = 1, [2, 3]; [a, b, c]")).to match_array([1,2,3])
  301 + expect(compile_and_run("class Coercible2;def to_ary;[2,3]; end; end; a, (b, c) = 1, Coercible2.new; [a, b, c]")).to match_array([1,2,3])
294 302 if is19
295 303 result = compile_and_run("a, (b, *, c), d, *e, f, (g, *h, i), j = 1,[2,3,4],5,6,7,8,[9,10,11],12; [a,b,c,d,e,f,g,h,i,j]")
296   - result.should == [1, 2, 4, 5, [6, 7], 8, 9, [10], 11, 12]
  304 + expect(result).to match_array([1, 2, 4, 5, [6, 7], 8, 9, [10], 11, 12])
297 305 end
298 306 end
299 307
300 308 it "compiles dynamic regexp" do
301   - compile_and_run('"foo" =~ /#{"foo"}/').should == 0
302   - compile_and_run('ary = []; 2.times {|i| ary << ("foo0" =~ /#{"foo" + i.to_s}/o)}; ary').should == [0, 0]
  309 + expect(compile_and_run('"foo" =~ /#{"foo"}/')).to eq 0
  310 + expect(compile_and_run('ary = []; 2.times {|i| ary << ("foo0" =~ /#{"foo" + i.to_s}/o)}; ary')).to match_array([0, 0])
303 311 end
304 312
305 313 it "compiles implicit and explicit return" do
306   - compile_and_run("def foo; 1; end; foo").should == 1
307   - compile_and_run("def foo; return; end; foo").should == nil
308   - compile_and_run("def foo; return 1; end; foo").should == 1
  314 + expect(compile_and_run("def foo; 1; end; foo")).to eq 1
  315 + expect(compile_and_run("def foo; return; end; foo")).to be_nil
  316 + expect(compile_and_run("def foo; return 1; end; foo")).to eq 1
309 317 end
310 318
311 319 it "compiles class reopening" do
312   - compile_and_run("class Fixnum; def x; 3; end; end; 1.x").should == 3
  320 + expect(compile_and_run("class Fixnum; def x; 3; end; end; 1.x")).to eq 3
313 321 end
314 322
315 323 it "compiles singleton method definitions" do
316   - compile_and_run("a = 'bar'; def a.foo; 'foo'; end; a.foo").should == "foo"
317   - compile_and_run("class Fixnum; def self.foo; 'foo'; end; end; Fixnum.foo").should == "foo"
318   - compile_and_run("def String.foo; 'foo'; end; String.foo").should == "foo"
  324 + expect(compile_and_run("a = 'bar'; def a.foo; 'foo'; end; a.foo")).to eq "foo"
  325 + expect(compile_and_run("class Fixnum; def self.foo; 'foo'; end; end; Fixnum.foo")).to eq "foo"
  326 + expect(compile_and_run("def String.foo; 'foo'; end; String.foo")).to eq "foo"
319 327 end
320 328
321 329 it "compiles singleton class definitions" do
322   - compile_and_run("a = 'bar'; class << a; def bar; 'bar'; end; end; a.bar").should == "bar"
323   - compile_and_run("class Fixnum; class << self; def bar; 'bar'; end; end; end; Fixnum.bar").should == "bar"
  330 + expect(compile_and_run("a = 'bar'; class << a; def bar; 'bar'; end; end; a.bar")).to eq "bar"
  331 + expect(compile_and_run("class Fixnum; class << self; def bar; 'bar'; end; end; end; Fixnum.bar")).to eq "bar"
324 332 result = compile_and_run("class Fixnum; def self.metaclass; class << self; self; end; end; end; Fixnum.metaclass")
325   - result.should == class << Fixnum; self; end
  333 + expect(result).to eq class << Fixnum; self; end
326 334 end
327 335
328 336 it "compiles loops with flow control" do
329 337 # some loop flow control tests
330   - compile_and_run("a = true; b = while a; a = false; break; end; b").should == nil
331   - compile_and_run("a = true; b = while a; a = false; break 1; end; b").should == 1
332   - compile_and_run("a = 0; while true; a += 1; next if a < 2; break; end; a").should == 2
333   - compile_and_run("a = 0; while true; a += 1; next 1 if a < 2; break; end; a").should == 2
334   - compile_and_run("a = 0; while true; a += 1; redo if a < 2; break; end; a").should == 2
335   - compile_and_run("a = false; b = until a; a = true; break; end; b").should == nil
336   - compile_and_run("a = false; b = until a; a = true; break 1; end; b").should == 1
337   - compile_and_run("a = 0; until false; a += 1; next if a < 2; break; end; a").should == 2
338   - compile_and_run("a = 0; until false; a += 1; next 1 if a < 2; break; end; a").should == 2
339   - compile_and_run("a = 0; until false; a += 1; redo if a < 2; break; end; a").should == 2
  338 + expect(compile_and_run("a = true; b = while a; a = false; break; end; b")).to be_nil
  339 + expect(compile_and_run("a = true; b = while a; a = false; break 1; end; b")).to eq 1
  340 + expect(compile_and_run("a = 0; while true; a += 1; next if a < 2; break; end; a")).to eq 2
  341 + expect(compile_and_run("a = 0; while true; a += 1; next 1 if a < 2; break; end; a")).to eq 2
  342 + expect(compile_and_run("a = 0; while true; a += 1; redo if a < 2; break; end; a")).to eq 2
  343 + expect(compile_and_run("a = false; b = until a; a = true; break; end; b")).to be_nil
  344 + expect(compile_and_run("a = false; b = until a; a = true; break 1; end; b")).to eq 1
  345 + expect(compile_and_run("a = 0; until false; a += 1; next if a < 2; break; end; a")).to eq 2
  346 + expect(compile_and_run("a = 0; until false; a += 1; next 1 if a < 2; break; end; a")).to eq 2
  347 + expect(compile_and_run("a = 0; until false; a += 1; redo if a < 2; break; end; a")).to eq 2
340 348 # same with evals
341   - compile_and_run("a = true; b = while a; a = false; eval 'break'; end; b").should == nil
342   - compile_and_run("a = true; b = while a; a = false; eval 'break 1'; end; b").should == 1
343   - compile_and_run("a = 0; while true; a += 1; eval 'next' if a < 2; eval 'break'; end; a").should == 2
344   - compile_and_run("a = 0; while true; a += 1; eval 'next 1' if a < 2; eval 'break'; end; a").should == 2
345   - compile_and_run("a = 0; while true; a += 1; eval 'redo' if a < 2; eval 'break'; end; a").should == 2
346   - compile_and_run("a = false; b = until a; a = true; eval 'break'; end; b").should == nil
347   - compile_and_run("a = false; b = until a; a = true; eval 'break 1'; end; b").should == 1
348   - compile_and_run("a = 0; until false; a += 1; eval 'next' if a < 2; eval 'break'; end; a").should == 2
349   - compile_and_run("a = 0; until false; a += 1; eval 'next 1' if a < 2; eval 'break'; end; a").should == 2
350   - compile_and_run("a = 0; until false; a += 1; eval 'redo' if a < 2; eval 'break'; end; a").should == 2
  349 + expect(compile_and_run("a = true; b = while a; a = false; eval 'break'; end; b")).to be_nil
  350 + expect(compile_and_run("a = true; b = while a; a = false; eval 'break 1'; end; b")).to eq 1
  351 + expect(compile_and_run("a = 0; while true; a += 1; eval 'next' if a < 2; eval 'break'; end; a")).to eq 2
  352 + expect(compile_and_run("a = 0; while true; a += 1; eval 'next 1' if a < 2; eval 'break'; end; a")).to eq 2
  353 + expect(compile_and_run("a = 0; while true; a += 1; eval 'redo' if a < 2; eval 'break'; end; a")).to eq 2
  354 + expect(compile_and_run("a = false; b = until a; a = true; eval 'break'; end; b")).to be_nil
  355 + expect(compile_and_run("a = false; b = until a; a = true; eval 'break 1'; end; b")).to eq 1
  356 + expect(compile_and_run("a = 0; until false; a += 1; eval 'next' if a < 2; eval 'break'; end; a")).to eq 2
  357 + expect(compile_and_run("a = 0; until false; a += 1; eval 'next 1' if a < 2; eval 'break'; end; a")).to eq 2
  358 + expect(compile_and_run("a = 0; until false; a += 1; eval 'redo' if a < 2; eval 'break'; end; a")).to eq 2
351 359 end
352 360
353 361 it "compiles loops with non-local flow control" do
354 362 # non-local flow control with while loops
355   - compile_and_run("a = 0; 1.times { a += 1; redo if a < 2 }; a").should == 2
356   - compile_and_run("def foo(&b); while true; b.call; end; end; foo { break 3 }").should == 3
  363 + expect(compile_and_run("a = 0; 1.times { a += 1; redo if a < 2 }; a")).to eq 2
  364 + expect(compile_and_run("def foo(&b); while true; b.call; end; end; foo { break 3 }")).to eq 3
357 365 # this one doesn't work normally, so I wouldn't expect it to work here yet
358 366 #compile_and_run("a = 0; 1.times { a += 1; eval 'redo' if a < 2 }; a").should == 2
359   - compile_and_run("def foo(&b); while true; b.call; end; end; foo { eval 'break 3' }").should == 3
  367 + expect(compile_and_run("def foo(&b); while true; b.call; end; end; foo { eval 'break 3' }")).to eq 3
360 368 end
361 369
362 370 it "compiles block passing" do
363 371 # block pass node compilation
364   - compile_and_run("def foo; block_given?; end; p = proc {}; [foo(&nil),foo(&p)]").should == [false, true]
365   - compile_and_run("public; def foo; block_given?; end; p = proc {}; [self.foo(&nil),self.foo(&p)]").should == [false, true]
  372 + expect(compile_and_run("def foo; block_given?; end; p = proc {}; [foo(&nil),foo(&p)]")).to match_array([false, true])
  373 + expect(compile_and_run("public; def foo; block_given?; end; p = proc {}; [self.foo(&nil),self.foo(&p)]")).to match_array([false, true])
366 374 end
367 375
368 376 it "compiles splatted element assignment" do
369   - compile_and_run("a = 'foo'; y = ['o']; a[*y] = 'asdf'; a").should == "fasdfo"
  377 + expect(compile_and_run("a = 'foo'; y = ['o']; a[*y] = 'asdf'; a")).to match "fasdfo"
370 378 end
371 379
372 380 it "compiles constant access" do
373 381 const_code = <<-EOS
374 382 A = 'a'; module X; B = 'b'; end; module Y; def self.go; [A, X::B, ::A]; end; end; Y.go
375 383 EOS
376   - compile_and_run(const_code).should == ["a", "b", "a"]
  384 + expect(compile_and_run(const_code)).to match_array(["a", "b", "a"])
377 385 end
378 386
379 387 it "compiles flip-flop" do
380 388 # flip (taken from http://redhanded.hobix.com/inspect/hopscotchingArraysWithFlipFlops.html)
381   - compile_and_run("s = true; (1..10).reject { true if (s = !s) .. (s) }").should == [1, 3, 5, 7, 9]
382   - compile_and_run("s = true; (1..10).reject { true if (s = !s) .. (s = !s) }").should == [1, 4, 7, 10]
  389 + expect(compile_and_run("s = true; (1..10).reject { true if (s = !s) .. (s) }")).to match_array([1, 3, 5, 7, 9])
  390 + expect(compile_and_run("s = true; (1..10).reject { true if (s = !s) .. (s = !s) }")).to match_array([1, 4, 7, 10])
383 391 big_flip = <<-EOS
384 392 s = true; (1..10).inject([]) do |ary, v|; ary << [] unless (s = !s) .. (s = !s); ary.last << v; ary; end
385 393 EOS
386   - compile_and_run(big_flip).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
  394 + expect(compile_and_run(big_flip)).to match_array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]])
387 395 big_triple_flip = <<-EOS
388 396 s = true
389 397 (1..64).inject([]) do |ary, v|
@@ -394,27 +402,19 @@ def self.bar
394 402 ary
395 403 end
396 404 EOS
397   - expected = [[1, 2, 3, 4, 5, 6, 7, 8],
398   - [9, 10, 11, 12, 13, 14, 15, 16],
399   - [17, 18, 19, 20, 21, 22, 23, 24],
400   - [25, 26, 27, 28, 29, 30, 31, 32],
401   - [33, 34, 35, 36, 37, 38, 39, 40],
402   - [41, 42, 43, 44, 45, 46, 47, 48],
403   - [49, 50, 51, 52, 53, 54, 55, 56],
404   - [57, 58, 59, 60, 61, 62, 63, 64]]
405   - compile_and_run(big_triple_flip).should == expected
  405 + expect(compile_and_run(big_triple_flip)).to match_array(expected)
406 406 end
407 407
408 408 it "gracefully handles named captures when there's no match" do
409   - lambda do
  409 + expect do
410 410 compile_and_run('/(?<a>.+)/ =~ ""')
411   - end.should_not raise_error
  411 + end.to_not raise_error
412 412 end
413 413
414 414 it "handles module/class opening from colon2 with non-method, non-const LHS" do
415   - lambda do
  415 + expect do
416 416 compile_and_run('m = Object; class m::FOOCLASS1234; end; module m::FOOMOD1234; end')
417   - end.should_not raise_error
  417 + end.to_not raise_error
418 418 end
419 419
420 420 it "properly handles non-local flow for a loop inside an ensure (JRUBY-6836)" do
@@ -436,7 +436,7 @@ def main
436 436
437 437 main'
438 438
439   - result.should == [1,2,3]
  439 + expect(result).to match_array([1,2,3])
440 440 end
441 441
442 442 if is19
@@ -449,7 +449,7 @@ def foo
449 449
450 450 foo]
451 451
452   - result.should == '/Users/headius/projects/jruby/tmp/perfer/examples/file_stat.rb'
  452 + expect(result).to eq '/Users/headius/projects/jruby/tmp/perfer/examples/file_stat.rb'
453 453 end
454 454 end
455 455
@@ -466,7 +466,7 @@ class AttrAccessorUnassigned
466 466 ary
467 467 EOC
468 468
469   - result.should == [nil, 1]
  469 + expect(result).to match_array([nil, 1])
470 470 end
471 471
472 472 if is19
@@ -480,7 +480,7 @@ def foo
480 480 foo
481 481 EOC
482 482
483   - result.should == ["0.1+0i", "1/10"]
  483 + expect(result).to match_array(["0.1+0i", "1/10"])
484 484 end
485 485 end
486 486
@@ -501,7 +501,7 @@ def foo
501 501 end
502 502 EOC
503 503
504   - result.should == 42
  504 + expect(result).to eq 42
505 505 end
506 506
507 507 it "matches any true value for a caseless case/when with > 3 args" do
@@ -512,130 +512,130 @@ def foo
512 512 end
513 513 EOC
514 514
515   - result.should == 42
  515 + expect(result).to eq 42
516 516 end
517 517
518 518 it "properly handles method-root rescue logic with returns (GH\#733)" do
519   - compile_and_run("def foo; return 1; rescue; return 2; else; return 3; end; foo").should == 1
520   - compile_and_run("def foo; 1; rescue; return 2; else; return 3; end; foo").should == 3
521   - compile_and_run("def foo; raise; rescue; return 2; else; return 3; end; foo").should == 2
  519 + expect(compile_and_run("def foo; return 1; rescue; return 2; else; return 3; end; foo")).to eq 1
  520 + expect(compile_and_run("def foo; 1; rescue; return 2; else; return 3; end; foo")).to eq 3
  521 + expect(compile_and_run("def foo; raise; rescue; return 2; else; return 3; end; foo")).to eq 2
522 522 end
523 523
524 524 it "does a bunch of other stuff" do
525 525 silence_warnings {
526 526 # bug 1305, no values yielded to single-arg block assigns a null into the arg
527   - compile_and_run("def foo; yield; end; foo {|x| x.class}").should == NilClass
  527 + expect(compile_and_run("def foo; yield; end; foo {|x| x.class}")).to eq NilClass
528 528 }
529 529
530 530 # ensure that invalid classes and modules raise errors
531 531 AFixnum = 1;
532   - lambda { compile_and_run("class AFixnum; end")}.should raise_error(TypeError)
533   - lambda { compile_and_run("class B < AFixnum; end")}.should raise_error(TypeError)
534   - lambda { compile_and_run("module AFixnum; end")}.should raise_error(TypeError)
  532 + expect { compile_and_run("class AFixnum; end")}.to raise_error(TypeError)
  533 + expect { compile_and_run("class B < AFixnum; end")}.to raise_error(TypeError)
  534 + expect { compile_and_run("module AFixnum; end")}.to raise_error(TypeError)
535 535
536 536 # attr assignment in multiple assign
537   - compile_and_run("a = Object.new; class << a; attr_accessor :b; end; a.b, a.b = 'baz','bar'; a.b").should == "bar"
538   - compile_and_run("a = []; a[0], a[1] = 'foo','bar'; a").should == ["foo", "bar"]
  537 + expect(compile_and_run("a = Object.new; class << a; attr_accessor :b; end; a.b, a.b = 'baz','bar'; a.b")).to eq "bar"
  538 + expect(compile_and_run("a = []; a[0], a[1] = 'foo','bar'; a")).to match_array(["foo", "bar"])
539 539
540 540 # for loops
541   - compile_and_run("a = []; for b in [1, 2, 3]; a << b * 2; end; a").should == [2, 4, 6]
542   - compile_and_run("a = []; for b, c in {:a => 1, :b => 2, :c => 3}; a << c; end; a.sort").should == [1, 2, 3]
  541 + expect(compile_and_run("a = []; for b in [1, 2, 3]; a << b * 2; end; a")).to match_array([2, 4, 6])
  542 + expect(compile_and_run("a = []; for b, c in {:a => 1, :b => 2, :c => 3}; a << c; end; a.sort")).to match_array([1, 2, 3])
543 543
544 544 # ensure blocks
545   - compile_and_run("a = 2; begin; a = 3; ensure; a = 1; end; a").should == 1
546   - compile_and_run("$a = 2; def foo; return; ensure; $a = 1; end; foo; $a").should == 1
  545 + expect(compile_and_run("a = 2; begin; a = 3; ensure; a = 1; end; a")).to eq 1
  546 + expect(compile_and_run("$a = 2; def foo; return; ensure; $a = 1; end; foo; $a")).to eq 1
547 547
548 548 # op element assign
549   - compile_and_run("a = []; [a[0] ||= 4, a[0]]").should == [4, 4]
550   - compile_and_run("a = [4]; [a[0] ||= 5, a[0]]").should == [4, 4]
551   - compile_and_run("a = [1]; [a[0] += 3, a[0]]").should == [4, 4]
552   - compile_and_run("a = {}; a[0] ||= [1]; a[0]").should == [1]
553   - compile_and_run("a = [1]; a[0] &&= 2; a[0]").should == 2
  549 + expect(compile_and_run("a = []; [a[0] ||= 4, a[0]]")).to match_array([4, 4])
  550 + expect(compile_and_run("a = [4]; [a[0] ||= 5, a[0]]")).to match_array([4, 4])
  551 + expect(compile_and_run("a = [1]; [a[0] += 3, a[0]]")).to match_array([4, 4])
  552 + expect(compile_and_run("a = {}; a[0] ||= [1]; a[0]")).to match_array([1])
  553 + expect(compile_and_run("a = [1]; a[0] &&= 2; a[0]")).to eq 2
554 554
555 555 # non-local return
556   - compile_and_run("def foo; loop {return 3}; return 4; end; foo").should == 3
  556 + expect(compile_and_run("def foo; loop {return 3}; return 4; end; foo")).to eq 3
557 557
558 558 # class var declaration
559   - compile_and_run("class Foo; @@foo = 3; end").should == 3
560   - compile_and_run("class Bar; @@bar = 3; def self.bar; @@bar; end; end; Bar.bar").should == 3
  559 + expect(compile_and_run("class Foo; @@foo = 3; end")).to eq 3
  560 + expect(compile_and_run("class Bar; @@bar = 3; def self.bar; @@bar; end; end; Bar.bar")).to eq 3
561 561
562 562 # rescue
563   - compile_and_run("x = begin; 1; raise; rescue; 2; end").should == 2
564   - compile_and_run("x = begin; 1; raise; rescue TypeError; 2; rescue; 3; end").should == 3
565   - compile_and_run("x = begin; 1; rescue; 2; else; 4; end").should == 4
566   - compile_and_run("def foo; begin; return 4; rescue; end; return 3; end; foo").should == 4
  563 + expect(compile_and_run("x = begin; 1; raise; rescue; 2; end")).to eq 2
  564 + expect(compile_and_run("x = begin; 1; raise; rescue TypeError; 2; rescue; 3; end")).to eq 3
  565 + expect(compile_and_run("x = begin; 1; rescue; 2; else; 4; end")).to eq 4
  566 + expect(compile_and_run("def foo; begin; return 4; rescue; end; return 3; end; foo")).to eq 4
567 567
568 568 # test that $! is getting reset/cleared appropriately
569 569 $! = nil
570   - compile_and_run("begin; raise; rescue; end; $!").should == nil
571   - compile_and_run("1.times { begin; raise; rescue; next; end }; $!").should == nil
572   - compile_and_run("begin; raise; rescue; begin; raise; rescue; end; $!; end").should_not == nil
573   - compile_and_run("begin; raise; rescue; 1.times { begin; raise; rescue; next; end }; $!; end").should_not == nil
  570 + expect(compile_and_run("begin; raise; rescue; end; $!")).to be_nil
  571 + expect(compile_and_run("1.times { begin; raise; rescue; next; end }; $!")).to be_nil
  572 + expect(compile_and_run("begin; raise; rescue; begin; raise; rescue; end; $!; end")).to_not be_nil
  573 + expect(compile_and_run("begin; raise; rescue; 1.times { begin; raise; rescue; next; end }; $!; end")).to_not be_nil
574 574
575 575 # break in a while in an ensure
576   - compile_and_run("begin; x = while true; break 5; end; ensure; end").should == 5
  576 + expect(compile_and_run("begin; x = while true; break 5; end; ensure; end")).to eq 5
577 577
578 578 # JRUBY-1388, Foo::Bar broke in the compiler
579   - compile_and_run("module Foo2; end; Foo2::Foo3 = 5; Foo2::Foo3").should == 5
  579 + expect(compile_and_run("module Foo2; end; Foo2::Foo3 = 5; Foo2::Foo3")).to eq 5
580 580
581   - compile_and_run("def foo; yield; end; x = false; foo { break 5 if x; begin; ensure; x = true; redo; end; break 6}").should == 5
  581 + expect(compile_and_run("def foo; yield; end; x = false; foo { break 5 if x; begin; ensure; x = true; redo; end; break 6}")).to eq 5
582 582
583 583 # END block
584   - lambda { compile_and_run("END {}") }.should_not raise_error
  584 + expect { compile_and_run("END {}") }.to_not raise_error
585 585
586 586 # BEGIN block
587   - compile_and_run("BEGIN { $begin = 5 }; $begin").should == 5
  587 + expect(compile_and_run("BEGIN { $begin = 5 }; $begin")).to eq 5
588 588
589 589 # nothing at all!
590   - compile_and_run("").should == nil
  590 + expect(compile_and_run("")).to be_nil
591 591
592 592 # JRUBY-2043
593   - compile_and_run("def foo; 1.times { a, b = [], 5; a[1] = []; return b; }; end; foo").should == 5
594   - compile_and_run("def foo; x = {1 => 2}; x.inject({}) do |hash, (key, value)|; hash[key.to_s] = value; hash; end; end; foo").should == {"1" => 2}
  593 + expect(compile_and_run("def foo; 1.times { a, b = [], 5; a[1] = []; return b; }; end; foo")).to eq 5
  594 + expect(compile_and_run("def foo; x = {1 => 2}; x.inject({}) do |hash, (key, value)|; hash[key.to_s] = value; hash; end; end; foo")).to eq({"1" => 2})
595 595
596 596 # JRUBY-2246
597 597 long_src = "a = 1\n"
598 598 5000.times { long_src << "a += 1\n" }
599   - compile_and_run(long_src).should == 5001
  599 + expect(compile_and_run(long_src)).to eq 5001
600 600
601 601 # variable assignment of various types from loop results
602   - compile_and_run("a = while true; break 1; end; a").should == 1
603   - compile_and_run("@a = while true; break 1; end; @a").should == 1
604   - compile_and_run("@@a = while true; break 1; end; @@a").should == 1
605   - compile_and_run("$a = while true; break 1; end; $a").should == 1
606   - compile_and_run("a = until false; break 1; end; a").should == 1
607   - compile_and_run("@a = until false; break 1; end; @a").should == 1
608   - compile_and_run("@@a = until false; break 1; end; @@a").should == 1
609   - compile_and_run("$a = until false; break 1; end; $a").should == 1
  602 + expect(compile_and_run("a = while true; break 1; end; a")).to eq 1
  603 + expect(compile_and_run("@a = while true; break 1; end; @a")).to eq 1
  604 + expect(compile_and_run("@@a = while true; break 1; end; @@a")).to eq 1
  605 + expect(compile_and_run("$a = while true; break 1; end; $a")).to eq 1
  606 + expect(compile_and_run("a = until false; break 1; end; a")).to eq 1
  607 + expect(compile_and_run("@a = until false; break 1; end; @a")).to eq 1
  608 + expect(compile_and_run("@@a = until false; break 1; end; @@a")).to eq 1
  609 + expect(compile_and_run("$a = until false; break 1; end; $a")).to eq 1
610 610
611 611 # same assignments but loop is within a begin
612   - compile_and_run("a = begin; while true; break 1; end; end; a").should == 1
613   - compile_and_run("@a = begin; while true; break 1; end; end; @a").should == 1
614   - compile_and_run("@@a = begin; while true; break 1; end; end; @@a").should == 1
615   - compile_and_run("$a = begin; while true; break 1; end; end; $a").should == 1
616   - compile_and_run("a = begin; until false; break 1; end; end; a").should == 1
617   - compile_and_run("@a = begin; until false; break 1; end; end; @a").should == 1
618   - compile_and_run("@@a = begin; until false; break 1; end; end; @@a").should == 1
619   - compile_and_run("$a = begin; until false; break 1; end; end; $a").should == 1
  612 + expect(compile_and_run("a = begin; while true; break 1; end; end; a")).to eq 1
  613 + expect(compile_and_run("@a = begin; while true; break 1; end; end; @a")).to eq 1
  614 + expect(compile_and_run("@@a = begin; while true; break 1; end; end; @@a")).to eq 1
  615 + expect(compile_and_run("$a = begin; while true; break 1; end; end; $a")).to eq 1
  616 + expect(compile_and_run("a = begin; until false; break 1; end; end; a")).to eq 1
  617 + expect(compile_and_run("@a = begin; until false; break 1; end; end; @a")).to eq 1
  618 + expect(compile_and_run("@@a = begin; until false; break 1; end; end; @@a")).to eq 1
  619 + expect(compile_and_run("$a = begin; until false; break 1; end; end; $a")).to eq 1
620 620
621 621 # other contexts that require while to preserve stack
622   - compile_and_run("1 + while true; break 1; end").should == 2
623   - compile_and_run("1 + begin; while true; break 1; end; end").should == 2
624   - compile_and_run("1 + until false; break 1; end").should == 2
625   - compile_and_run("1 + begin; until false; break 1; end; end").should == 2
626   - compile_and_run("def foo(a); a; end; foo(while false; end)").should == nil
627   - compile_and_run("def foo(a); a; end; foo(until true; end)").should == nil
  622 + expect(compile_and_run("1 + while true; break 1; end")).to eq 2
  623 + expect(compile_and_run("1 + begin; while true; break 1; end; end")).to eq 2
  624 + expect(compile_and_run("1 + until false; break 1; end")).to eq 2
  625 + expect(compile_and_run("1 + begin; until false; break 1; end; end")).to eq 2
  626 + expect(compile_and_run("def foo(a); a; end; foo(while false; end)")).to be_nil
  627 + expect(compile_and_run("def foo(a); a; end; foo(until true; end)")).to be_nil
628 628
629 629 # test that 100 symbols compiles ok; that hits both types of symbol caching/creation
630 630 syms = [:a]
631 631 99.times {|i| syms << ('foo' + i.to_s).intern }
632 632 # 100 first instances of a symbol
633   - compile_and_run(syms.inspect).should == syms
  633 + expect(compile_and_run(syms.inspect)).to eq syms
634 634 # 100 first instances and 100 second instances (caching)
635   - compile_and_run("[#{syms.inspect},#{syms.inspect}]").should == [syms,syms]
  635 + expect(compile_and_run("[#{syms.inspect},#{syms.inspect}]")).to match_array([syms,syms])
636 636
637 637 # class created using local var as superclass
638   - compile_and_run(<<-EOS).should == 'AFromLocal'
  638 + expect(compile_and_run(<<-EOS)).to eq 'AFromLocal'
639 639 a = Object
640 640 class AFromLocal < a
641 641 end
@@ -656,20 +656,21 @@ def self_check; if self; true; else; false; end; end
656 656 large_hash = large_array.clone
657 657 large_hash.gsub!('[', '{')
658 658 large_hash.gsub!(']', '}')
659   - compile_and_run(large_array).should == eval(large_array)
660   - compile_and_run(large_hash).should == eval(large_hash) unless is19 # invalid syntax in 1.9
  659 + expect(compile_and_run(large_array)).to eq(eval(large_array))
  660 + expect(compile_and_run(large_hash)).to eq(eval(large_hash)) unless is19 # invalid syntax in 1.9
661 661
662 662 if is19 # block arg spreading cases
663   - compile_and_run("def foo; a = [1]; yield a; end; foo {|a| a}").should == [1]
664   - compile_and_run("x = nil; [[1]].each {|a| x = a}; x").should == [1]
665   - compile_and_run("def foo; yield [1, 2]; end; foo {|x, y| [x, y]}").should == [1,2]
  663 + expect(compile_and_run("def foo; a = [1]; yield a; end; foo {|a| a}")).to match_array([1])
  664 + expect(compile_and_run("x = nil; [[1]].each {|a| x = a}; x")).to match_array([1])
  665 + expect(compile_and_run("def foo; yield [1, 2]; end; foo {|x, y| [x, y]}")).to match_array([1,2])
666 666 end
667 667
668 668 # non-expr case statement with return with if modified with call
669 669 # broke in 1.9 compiler due to null "else" node pushing a nil when non-expr
670   - compile_and_run("def foo; case 0; when 1; return 2 if self.nil?; end; return 3; end; foo").should == 3
  670 + expect(compile_and_run("def foo; case 0; when 1; return 2 if self.nil?; end; return 3; end; foo")).to eq 3
671 671
672 672 if is19 # named groups with capture
  673 + expect(
673 674 compile_and_run("
674 675 def foo
675 676 ary = []
@@ -684,11 +685,11 @@ def foo
684 685 ary << b
685 686 ary
686 687 end
687   - foo").should == [nil,'ell', 'o', 'ell']
  688 + foo")).to match_array([nil,'ell', 'o', 'ell'])
688 689 end
689 690
690 691 if is19 # chained argscat and argspush
691   - compile_and_run("a=[1,2];b=[4,5];[*a,3,*a,*b]").should == [1,2,3,1,2,4,5]
  692 + expect(compile_and_run("a=[1,2];b=[4,5];[*a,3,*a,*b]")).to match_array([1,2,3,1,2,4,5])
692 693 end
693 694
694 695 # JRUBY-5840
@@ -699,7 +700,7 @@ def foo
699 700 '
700 701 old_kcode = $KCODE
701 702 $KCODE = 'UTF-8'
702   - compile_and_run(test).should == eval(test)
  703 + expect(compile_and_run(test)).to eq(eval(test))
703 704 $KCODE = old_kcode
704 705 end
705 706
@@ -707,7 +708,7 @@ def foo
707 708 test = '
708 709 %w[foo bar].__send__ :to_enum, *[], &nil
709 710 '
710   - compile_and_run(test).map {|line| line + 'yum'}.should == ["fooyum", "baryum"]
  711 + expect(compile_and_run(test).map {|line| line + 'yum'}).to match_array(["fooyum", "baryum"])
711 712
712 713 # These two cases triggered ArgumentError when Enumerator was fixed to enforce
713 714 # 3 required along its varargs path. Testing both here to ensure super/zsuper
@@ -721,9 +722,9 @@ def initialize(x, y, *z)
721 722 end
722 723 "
723 724
724   - lambda {
  725 + expect {
725 726 JRuby5871A.new("foo", :each_byte)
726   - }.should_not raise_error
  727 + }.to_not raise_error
727 728
728 729 compile_and_run "
729 730 class JRuby5871B < #{enumerable}
@@ -733,16 +734,16 @@ def initialize(x, y, *z)
733 734 end
734 735 "
735 736
736   - lambda {
  737 + expect {
737 738 JRuby5871B.new("foo", :each_byte)
738   - }.should_not raise_error
  739 + }.to_not raise_error
739 740
740 741 class JRUBY4925
741 742 end
742 743
743 744 x = compile_and_run 'JRUBY4925::BLAH, a = 1, 2'
744   - JRUBY4925::BLAH.should == 1
  745 + expect(JRUBY4925::BLAH).to eq 1
745 746 x = compile_and_run '::JRUBY4925_BLAH, a = 1, 2'
746   - JRUBY4925_BLAH.should == 1
  747 + expect(JRUBY4925_BLAH).to eq 1
747 748 end
748 749 end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.