Skip to content

Commit e8b8185

Browse files
committed
Use expect syntax in specs
1 parent 20f5362 commit e8b8185

File tree

2 files changed

+64
-63
lines changed

2 files changed

+64
-63
lines changed

spec/launcher_spec.rb

+63-62
Original file line numberDiff line numberDiff line change
@@ -3,225 +3,226 @@
33

44
describe "JRuby native launcher" do
55
it "should run org.jruby.Main" do
6-
jruby_launcher_args("").last.should == "org/jruby/Main"
6+
expect(jruby_launcher_args("").last).to eq "org/jruby/Main"
77
end
88

99
it "should pass unrecognized arguments to JRuby" do
10-
jruby_launcher_args("-J-Dsome.option -v --help")[-3..-1].should == ["org/jruby/Main", "-v", "--help"]
10+
expect(jruby_launcher_args("-J-Dsome.option -v --help")[-3..-1]).to contain_exactly("org/jruby/Main", "-v", "--help")
1111
end
1212

1313
it "should print help message" do
1414
args = jruby_launcher_args("-Xhelp 2>&1")
15-
args.select {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
16-
args.should include("-X")
15+
expect(args.select {|l| l =~ /JRuby Launcher usage/}).not_to be_empty
16+
expect(args).to include("-X")
1717
args = jruby_launcher_args("-X 2>&1")
18-
args.detect {|l| l =~ /JRuby Launcher usage/}.should_not be_empty
19-
args.should include("-X")
18+
expect(args.detect {|l| l =~ /JRuby Launcher usage/}).not_to be_empty
19+
expect(args).to include("-X")
2020
end
2121

2222
it "should use $JAVACMD when JAVACMD is specified" do
2323
with_environment "JAVACMD" => File.join("jato") do
2424
if windows?
25-
jruby_launcher_args("-v 2>&1").join.should =~ %r{jato}
25+
expect(jruby_launcher_args("-v 2>&1").join).to match %r{jato}
2626
else
27-
jruby_launcher_args("-v").first.should == File.join("jato")
27+
expect(jruby_launcher_args("-v").first).to eq File.join("jato")
2828
end
2929
end
3030
end
3131

3232
it "should use $JAVA_HOME/bin/java when JAVA_HOME is specified" do
3333
with_environment "JAVA_HOME" => File.join("some", "java", "home") do
3434
if windows?
35-
jruby_launcher_args("-v 2>&1").join.should =~ %r{some/java/home}
35+
expect(jruby_launcher_args("-v 2>&1").join).to match %r{some/java/home}
3636
else
37-
jruby_launcher_args("-v").first.should == File.join("some", "java", "home", "bin", "java")
37+
expect(jruby_launcher_args("-v").first).to eq File.join("some", "java", "home", "bin", "java")
3838
end
3939
end
4040
end
4141

4242
it "should use -Xjdkhome argument above JAVA_HOME" do
4343
with_environment "JAVA_HOME" => File.join("env", "java", "home") do
4444
if windows?
45-
jruby_launcher_args("-Xjdkhome some/java/home 2>&1").join.should =~ %r{some/java/home}
45+
expect(jruby_launcher_args("-Xjdkhome some/java/home 2>&1").join).to match %r{some/java/home}
4646
else
47-
jruby_launcher_args("-Xjdkhome some/java/home").first.should == File.join("some", "java", "home", "bin", "java")
47+
expect(jruby_launcher_args("-Xjdkhome some/java/home").first).to eq File.join("some", "java", "home", "bin", "java")
4848
end
4949
end
5050
end
5151

5252
it "should drop the backslashes at the end of JAVA_HOME" do
5353
with_environment "JAVA_HOME" => File.join("some", "java", "home\\\\") do
5454
if windows?
55-
jruby_launcher_args("").join.should =~ %r{some/java/home}
55+
expect(jruby_launcher_args("").join).to match %r{some/java/home}
5656
else
57-
jruby_launcher_args("").first.should == File.join("some", "java", "home", "bin", "java")
57+
expect(jruby_launcher_args("").first).to eq File.join("some", "java", "home", "bin", "java")
5858
end
5959
end
6060
end
6161

6262
it "should complain about a missing log argument" do
63-
jruby_launcher("-Xtrace 2>&1").should =~ /Argument is missing for "-Xtrace"/
64-
jruby_launcher("-Xtrace -- 2>&1").should =~ /Argument is missing for "-Xtrace"/
63+
expect(jruby_launcher("-Xtrace 2>&1")).to match /Argument is missing for "-Xtrace"/
64+
expect(jruby_launcher("-Xtrace -- 2>&1")).to match /Argument is missing for "-Xtrace"/
6565
end
6666

6767
it "should complain about a missing jdkhome argument" do
68-
jruby_launcher("-Xjdkhome 2>&1").should =~ /Argument is missing/
69-
jruby_launcher("-Xjdkhome -- 2>&1").should =~ /Argument is missing/
68+
expect(jruby_launcher("-Xjdkhome 2>&1")).to match /Argument is missing/
69+
expect(jruby_launcher("-Xjdkhome -- 2>&1")).to match /Argument is missing/
7070
end
7171

7272
it "should complain about a missing classpath append argument" do
73-
jruby_launcher("-Xcp:a 2>&1").should =~ /Argument is missing/
74-
jruby_launcher("-Xcp:a -- 2>&1").should =~ /Argument is missing/
73+
expect(jruby_launcher("-Xcp:a 2>&1")).to match /Argument is missing/
74+
expect(jruby_launcher("-Xcp:a -- 2>&1")).to match /Argument is missing/
7575
end
7676

7777
it "should run nailgun server with --ng-server option" do
78-
jruby_launcher_args("--ng-server").last.should == "com/martiansoftware/nailgun/NGServer"
78+
expect(jruby_launcher_args("--ng-server").last).to eq "com/martiansoftware/nailgun/NGServer"
7979
end
8080

8181
it "should run nailgun client with --ng option" do
82-
jruby_launcher_args('--ng -e "puts 1"').should == ["org.jruby.util.NailMain", "-e", "puts 1"]
82+
expect(jruby_launcher_args('--ng -e "puts 1"')).to eq ["org.jruby.util.NailMain", "-e", "puts 1"]
8383
end
8484

8585
it "should handle -J JVM options" do
86-
jruby_launcher_args("-J-Darg1=value1 -J-Darg2=value2").should include("-Darg1=value1", "-Darg2=value2")
86+
expect(jruby_launcher_args("-J-Darg1=value1 -J-Darg2=value2")).to include("-Darg1=value1", "-Darg2=value2")
8787
end
8888

8989
it "should pass -Xprop.erty=value as -J-Djruby.prop.erty=value" do
90-
jruby_launcher_args("-Xprop.erty=value").should include("-Djruby.prop.erty=value")
90+
expect(jruby_launcher_args("-Xprop.erty=value")).to include("-Djruby.prop.erty=value")
9191
end
9292

9393
it "should pass -Xproperties as --properties" do
94-
jruby_launcher_args("-Xproperties").should include("--properties")
94+
expect(jruby_launcher_args("-Xproperties")).to include("--properties")
9595
end
9696

9797
it "should default to 500m max heap" do
98-
jruby_launcher_args("").should include("-Xmx500m")
98+
expect(jruby_launcher_args("")).to include("-Xmx500m")
9999
end
100100

101101
it "should allow max heap to be overridden" do
102-
jruby_launcher_args("-J-Xmx256m").should include("-Xmx256m")
102+
expect(jruby_launcher_args("-J-Xmx256m")).to include("-Xmx256m")
103103
end
104104

105105
it "should default to 2048k max stack" do
106-
jruby_launcher_args("").should include("-Xss2048k")
106+
expect(jruby_launcher_args("")).to include("-Xss2048k")
107107
end
108108

109109
it "should allow max stack to be overridden" do
110-
jruby_launcher_args("-J-Xss512k").should include("-Xss512k")
110+
expect(jruby_launcher_args("-J-Xss512k")).to include("-Xss512k")
111111
end
112112

113113
it "should add the contents of the CLASSPATH environment variable" do
114114
with_environment "CLASSPATH" => "some.jar" do
115-
classpath_arg(jruby_launcher_args("")).should =~ /some.jar/
115+
expect(classpath_arg(jruby_launcher_args(""))).to match /some.jar/
116116
end
117117
end
118118

119119
it "should add the classpath elements in proper order" do
120120
s = File::PATH_SEPARATOR
121121
with_environment "CLASSPATH" => "some-env.jar" do
122122
args = jruby_launcher_args("-Xcp:a some-other.jar -Xcp:p some.jar")
123-
classpath_arg(args).should =~ /some.jar.*#{s}some-env.jar#{s}some-other.jar/
123+
expect(classpath_arg(args)).to match /some.jar.*#{s}some-env.jar#{s}some-other.jar/
124124
end
125125
end
126126

127127
it "should use the --server compiler" do
128-
jruby_launcher_args("--server").should include("-server")
128+
expect(jruby_launcher_args("--server")).to include("-server")
129129
end
130130

131131
it "should use the --client compiler" do
132-
jruby_launcher_args("--client").should include("-client")
132+
expect(jruby_launcher_args("--client")).to include("-client")
133133
end
134134

135135
it "should set the JMX settings when --manage is present" do
136-
jruby_launcher_args("--manage").should include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
136+
expect(jruby_launcher_args("--manage")).to include("-Dcom.sun.management.jmxremote", "-Djruby.management.enabled=true")
137137
end
138138

139139
it "should set the headless flag when --headless is present" do
140-
jruby_launcher_args("--headless").should include("-Djava.awt.headless=true")
140+
expect(jruby_launcher_args("--headless")).to include("-Djava.awt.headless=true")
141141
end
142142

143143
it "should pass -Xprof when --sample is present" do
144-
jruby_launcher_args("--sample").should include("-Xprof")
144+
expect(jruby_launcher_args("--sample")).to include("-Xprof")
145145
end
146146

147147
it "should stop argument processing when a -- is seen" do
148-
jruby_launcher_args("-- -Xhelp -Xtrace --headless").should include("-Xhelp", "-Xtrace", "--headless")
148+
expect(jruby_launcher_args("-- -Xhelp -Xtrace --headless")).to include("-Xhelp", "-Xtrace", "--headless")
149149
end
150150

151151
# JRUBY-4151
152152
it "should properly handle single quotes" do
153-
jruby_launcher_args("-e 'ABC DEF'").should include("ABC DEF")
153+
expect(jruby_launcher_args("-e 'ABC DEF'")).to include("ABC DEF")
154154
end
155155

156156
# JRUBY-4581
157157
it "should prepend JRUBY_OPTS to the start of the argument list to process" do
158158
with_environment "JRUBY_OPTS" => "--server -J-Dsome.key=val -rubygems" do
159-
jruby_launcher_args("-e 'ABC DEF'").should include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
159+
expect(jruby_launcher_args("-e 'ABC DEF'")).to include("-server", "-Dsome.key=val", "-rubygems", "-e", "ABC DEF")
160160
end
161161
end
162162

163163
# JRUBY-4611
164164
it "stops argument processing on first non-option argument" do
165-
jruby_launcher_args("foo.rb --sample")[-2..-1].should == ["foo.rb", "--sample"]
165+
expect(jruby_launcher_args("foo.rb --sample")[-2..-1]).to eq ["foo.rb", "--sample"]
166166
end
167167

168168
# JRUBY-4608
169169
if RbConfig::CONFIG['target_os'] =~ /darwin/i
170170
it "includes file.encoding=UTF-8 on Mac if JAVA_ENCODING is not set" do
171-
jruby_launcher_args("-e true").should include("-Dfile.encoding=UTF-8")
171+
expect(jruby_launcher_args("-e true")).to include("-Dfile.encoding=UTF-8")
172172
with_environment "JAVA_ENCODING" => "MacRoman" do
173-
jruby_launcher_args("-e true").should_not include("-Dfile.encoding=UTF-8")
173+
expect(jruby_launcher_args("-e true")).not_to include("-Dfile.encoding=UTF-8")
174174
end
175175
end
176176
end
177177

178178
it "does not crash on empty args" do
179-
jruby_launcher_args("-e ''").should include("-e")
180-
jruby_launcher("-Xtrace '' 2>&1").should =~ /-Xtrace/
181-
jruby_launcher("-Xjdkhome '' 2>&1").should =~ /-Xjdkhome/
179+
expect(jruby_launcher_args("-e ''")).to include("-e")
180+
expect(jruby_launcher("-Xtrace '' 2>&1")).to match /-Xtrace/
181+
expect(jruby_launcher("-Xjdkhome '' 2>&1")).to match /-Xjdkhome/
182182
end
183183

184184
# JRUBY-4706
185185
it "should put JRuby on regular classpath when -Xnobootclasspath is used" do
186186
args = jruby_launcher_args("-e true")
187-
args.grep(/Xbootclasspath/).should_not be_empty
187+
expect(args.grep(/Xbootclasspath/)).not_to be_empty
188188
args = jruby_launcher_args("-Xnobootclasspath -e true")
189-
args.grep(/Xbootclasspath/).should be_empty
189+
expect(args.grep(/Xbootclasspath/)).to be_empty
190190
end
191191

192192
it "should put JRuby on regular classpath when VERIFY_JRUBY is set" do
193193
with_environment "VERIFY_JRUBY" => "true" do
194194
args = jruby_launcher_args("-e true")
195-
args.grep(/Xbootclasspath/).should be_empty
195+
expect(args.grep(/Xbootclasspath/)).to be_empty
196196
end
197197
end
198198

199199
# JRUBY-4709
200200
it "should include a bare : or ; at the end of the classpath, to include PWD in the path" do
201-
classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true")).should =~
202-
if windows?
203-
/;$/
204-
else
205-
/:$/
206-
end
201+
end_of_path_pattern = if windows?
202+
/;$/
203+
else
204+
/:$/
205+
end
206+
207+
expect(classpath_arg(jruby_launcher_args("-Xnobootclasspath -e true"))).to match end_of_path_pattern
207208
end
208209

209210
# JRUBY-6016
210211
it "should honor JAVA_MEM" do
211212
with_environment "JAVA_MEM" => "-Xmx768m" do
212-
jruby_launcher_args("").should include("-Xmx768m")
213+
expect(jruby_launcher_args("")).to include("-Xmx768m")
213214
end
214215
end
215216

216217
it "should honor JAVA_STACK" do
217218
with_environment "JAVA_STACK" => "-Xss3072k" do
218-
jruby_launcher_args("").should include("-Xss3072k")
219+
expect(jruby_launcher_args("")).to include("-Xss3072k")
219220
end
220221
end
221222

222223
it "should honor JRUBY_HOME" do
223224
with_environment "JRUBY_HOME" => "/tmp" do
224-
jruby_launcher_args("").should include("-Djruby.home=/tmp")
225+
expect(jruby_launcher_args("")).to include("-Djruby.home=/tmp")
225226
end
226227
end
227228

@@ -240,23 +241,23 @@
240241

241242
it "should add jruby.jar to the bootclasspath" do
242243
with_environment "JRUBY_HOME" => jruby_home do
243-
jruby_launcher_args("").should include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
244+
expect(jruby_launcher_args("")).to include("-Xbootclasspath/a:#{jruby_home}/lib/jruby.jar")
244245
end
245246
end
246247
end
247248

248249
it "should place user-supplied options after default options" do
249250
args = jruby_launcher_args("-J-Djruby.home=/tmp")
250251
home_args = args.select {|x| x =~ /^-Djruby\.home/ }
251-
home_args.length.should == 2
252-
home_args.last.should == "-Djruby.home=/tmp"
252+
expect(home_args.length).to eq 2
253+
expect(home_args.last).to eq "-Djruby.home=/tmp"
253254
end
254255

255256
it "should print the version" do
256-
jruby_launcher("-Xversion 2>&1").should =~ /Launcher Version #{JRubyLauncher::VERSION}/
257+
expect(jruby_launcher("-Xversion 2>&1")).to match /Launcher Version #{JRubyLauncher::VERSION}/
257258
end
258259

259260
it "should not crash on format-strings" do
260-
jruby_launcher_args("-e %s%s%s%s%s 2>&1").should include('-e', '%s%s%s%s%s')
261+
expect(jruby_launcher_args("-e %s%s%s%s%s 2>&1")).to include('-e', '%s%s%s%s%s')
261262
end
262263
end

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def windows?
4747

4848
def classpath_arg(args)
4949
index = args.index("-cp")
50-
index.should > 0
50+
expect(index).to be > 0
5151
args[index + 1]
5252
end
5353

0 commit comments

Comments
 (0)