Skip to content

Commit 2ebb18b

Browse files
committed
1 parent fb48371 commit 2ebb18b

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

spec/mspec/spec/helpers/ruby_exe_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class RubyExeSpecs
145145
stub_const 'RUBY_EXE', 'ruby_spec_exe -w -Q'
146146

147147
@script = RubyExeSpecs.new
148-
allow(@script).to receive(:`).and_return('OUTPUT')
148+
allow(IO).to receive(:popen).and_return('OUTPUT')
149149

150150
status_successful = double(Process::Status, exited?: true, exitstatus: 0)
151151
allow(Process).to receive(:last_status).and_return(status_successful)
@@ -155,7 +155,7 @@ class RubyExeSpecs
155155
code = "code"
156156
options = {}
157157
output = "output"
158-
allow(@script).to receive(:`).and_return(output)
158+
expect(IO).to receive(:popen).and_return(output)
159159

160160
expect(@script.ruby_exe(code, options)).to eq output
161161
end
@@ -168,7 +168,7 @@ class RubyExeSpecs
168168
code = "code"
169169
options = {}
170170
expect(@script).to receive(:ruby_cmd).and_return("ruby_cmd")
171-
expect(@script).to receive(:`).with("ruby_cmd")
171+
expect(IO).to receive(:popen).with("ruby_cmd")
172172
@script.ruby_exe(code, options)
173173
end
174174

@@ -227,7 +227,7 @@ class RubyExeSpecs
227227
expect(ENV).to receive(:[]=).with("ABC", "xyz")
228228
expect(ENV).to receive(:[]=).with("ABC", "123")
229229

230-
expect(@script).to receive(:`).and_raise(Exception)
230+
expect(IO).to receive(:popen).and_raise(Exception)
231231
expect do
232232
@script.ruby_exe nil, :env => { :ABC => "xyz" }
233233
end.to raise_error(Exception)
@@ -248,7 +248,7 @@ class RubyExeSpecs
248248

249249
it "does not raise exception when command ends with expected status" do
250250
output = "output"
251-
allow(@script).to receive(:`).and_return(output)
251+
expect(IO).to receive(:popen).and_return(output)
252252

253253
expect(@script.ruby_exe("path", exit_status: 4)).to eq output
254254
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env ruby
2+
3+
# This script is used to check that each *_spec.rb file has
4+
# a relative_require for spec_helper which should live higher
5+
# up in the ruby/spec repo directory tree.
6+
#
7+
# Prints errors to $stderr and returns a non-zero exit code when
8+
# errors are found.
9+
#
10+
# Related to https://github.com/ruby/spec/pull/992
11+
12+
def check_file(fn)
13+
File.foreach(fn) do |line|
14+
return $1 if line =~ /^\s*require_relative\s*['"](.*spec_helper)['"]/
15+
end
16+
nil
17+
end
18+
19+
rootdir = ARGV[0] || "."
20+
fglob = File.join(rootdir, "**", "*_spec.rb")
21+
specfiles = Dir.glob(fglob)
22+
raise "No spec files found in #{fglob.inspect}. Give an argument to specify the root-directory of ruby/spec" if specfiles.empty?
23+
24+
errors = 0
25+
specfiles.sort.each do |fn|
26+
result = check_file(fn)
27+
if result.nil?
28+
warn "Missing require_relative for *spec_helper for file: #{fn}"
29+
errors += 1
30+
end
31+
end
32+
33+
puts "# Found #{errors} files with require_relative spec_helper issues."
34+
exit 1 if errors > 0

0 commit comments

Comments
 (0)