Skip to content

Commit 1bd82ea

Browse files
committed
[GR-14806] Update specs.
PullRequest: truffleruby/879
2 parents d4d00fa + c26203f commit 1bd82ea

File tree

19 files changed

+118
-111
lines changed

19 files changed

+118
-111
lines changed

spec/mspec/Gemfile.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ PLATFORMS
1919
DEPENDENCIES
2020
rake (~> 10.0)
2121
rspec (~> 2.14.1)
22-
23-
BUNDLED WITH
24-
1.16.1

spec/mspec/lib/mspec/helpers/ruby_exe.rb

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,29 @@
22
require 'mspec/helpers/tmp'
33

44
# The ruby_exe helper provides a wrapper for invoking the
5-
# same Ruby interpreter with the same falgs as the one running
5+
# same Ruby interpreter with the same flags as the one running
66
# the specs and getting the output from running the code.
7+
#
78
# If +code+ is a file that exists, it will be run.
8-
# Otherwise, +code+ should be Ruby code that will be run with
9-
# the -e command line option. For example:
9+
# Otherwise, +code+ will be written to a temporary file and be run.
10+
# For example:
1011
#
1112
# ruby_exe('path/to/some/file.rb')
1213
#
1314
# will be executed as
1415
#
1516
# `#{RUBY_EXE} 'path/to/some/file.rb'`
1617
#
17-
# while
18-
#
19-
# ruby_exe('puts "hello, world."')
20-
#
21-
# will be executed as
22-
#
23-
# `#{RUBY_EXE} -e 'puts "hello, world."'`
24-
#
2518
# The ruby_exe helper also accepts an options hash with three
2619
# keys: :options, :args and :env. For example:
2720
#
2821
# ruby_exe('file.rb', :options => "-w",
29-
# :args => "> file.txt",
22+
# :args => "arg1 arg2",
3023
# :env => { :FOO => "bar" })
3124
#
3225
# will be executed as
3326
#
34-
# `#{RUBY_EXE} -w #{'file.rb'} > file.txt`
27+
# `#{RUBY_EXE} -w file.rb arg1 arg2`
3528
#
3629
# with access to ENV["FOO"] with value "bar".
3730
#
@@ -49,33 +42,11 @@
4942
# The RUBY_EXE constant is setup by mspec automatically
5043
# and is used by ruby_exe and ruby_cmd. The mspec runner script
5144
# will set ENV['RUBY_EXE'] to the name of the executable used
52-
# to invoke the mspec-run script. The value of RUBY_EXE will be
53-
# constructed as follows:
54-
#
55-
# 1. the value of ENV['RUBY_EXE']
56-
# 2. an explicit value based on RUBY_ENGINE
57-
# 3. cwd/(RUBY_ENGINE + $(EXEEXT) || $(exeext) || '')
58-
# 4. $(bindir)/$(RUBY_INSTALL_NAME)
45+
# to invoke the mspec-run script.
5946
#
6047
# The value will only be used if the file exists and is executable.
61-
# The flags will then be appended to the resulting value.
62-
#
63-
# These 4 ways correspond to the following scenarios:
64-
#
65-
# 1. Using the MSpec runner scripts, the name of the
66-
# executable is explicitly passed by ENV['RUBY_EXE']
67-
# so there is no ambiguity.
68-
#
69-
# Otherwise, if using RSpec (or something else)
70-
#
71-
# 2. Running the specs while developing an alternative
72-
# Ruby implementation. This explicitly names the
73-
# executable in the development directory based on
74-
# the value of RUBY_ENGINE.
75-
# 3. Running the specs within the source directory for
76-
# some implementation. (E.g. a local build directory.)
77-
# 4. Running the specs against some installed Ruby
78-
# implementation.
48+
# The flags will then be appended to the resulting value, such that
49+
# the RUBY_EXE constant contains both the executable and the flags.
7950
#
8051
# Additionally, the flags passed to mspec
8152
# (with -T on the command line or in the config with set :flags)
@@ -129,6 +100,10 @@ def resolve_ruby_exe
129100
raise Exception, "Unable to find a suitable ruby executable."
130101
end
131102

103+
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
104+
RUBY_EXE = resolve_ruby_exe
105+
end
106+
132107
def ruby_exe(code = :not_given, opts = {})
133108
if opts[:dir]
134109
raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir"
@@ -180,7 +155,3 @@ def ruby_cmd(code, opts = {})
180155

181156
[RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
182157
end
183-
184-
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
185-
RUBY_EXE = resolve_ruby_exe
186-
end

spec/mspec/tool/sync/sync-rubyspec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def verify_commits(impl)
190190
puts "Manually check commit messages:"
191191
print "Press enter >"
192192
STDIN.gets
193-
sh "git", "log", "master..."
193+
system "git", "log", "master..."
194194
end
195195
end
196196

spec/ruby/core/binding/fixtures/irbrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty configuration

spec/ruby/core/binding/irb_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
describe "Binding#irb" do
55
it "creates an IRB session with the binding in scope" do
66
irb_fixture = fixture __FILE__, "irb.rb"
7+
irbrc_fixture = fixture __FILE__, "irbrc"
78

8-
out = IO.popen([*ruby_exe, irb_fixture], "r+") do |pipe|
9+
out = IO.popen([{"IRBRC"=>irbrc_fixture}, *ruby_exe, irb_fixture], "r+") do |pipe|
910
pipe.puts "a ** 2"
1011
pipe.puts "exit"
1112
pipe.readlines.map(&:chomp)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
4+
ruby_version_is "2.7" do
5+
describe "Enumerable#tally" do
6+
before :each do
7+
ScratchPad.record []
8+
end
9+
10+
it "returns a hash with counts according to the value" do
11+
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
12+
enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
13+
end
14+
15+
it "returns a hash without default" do
16+
hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
17+
hash.default_proc.should be_nil
18+
hash.default.should be_nil
19+
end
20+
21+
it "returns an empty hash for empty enumerables" do
22+
EnumerableSpecs::Empty.new.tally.should == {}
23+
end
24+
25+
it "counts values as gathered array when yielded with multiple arguments" do
26+
EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
27+
end
28+
29+
it "does not call given block" do
30+
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
31+
enum.tally { |v| ScratchPad << v }
32+
ScratchPad.recorded.should == []
33+
end
34+
end
35+
end

spec/ruby/core/file/fixtures/file_types.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def self.symlink
5252
end
5353

5454
def self.socket
55-
require 'socket'
56-
name = tmp("ftype_socket.socket")
57-
rm_r name
55+
require_relative '../../../library/socket/fixtures/classes.rb'
56+
57+
name = SocketSpecs.socket_path
5858
socket = UNIXServer.new name
5959
begin
6060
yield name

spec/ruby/core/file/stat/ftype_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
end
5656
end
5757

58-
# This will silently not execute the block if no socket
59-
# can be found. However, if you are running X, there is
60-
# a good chance that if nothing else, at least the X
61-
# Server socket exists.
6258
it "returns 'socket' when the file is a socket" do
6359
FileSpecs.socket do |socket|
6460
File.lstat(socket).ftype.should == 'socket'

spec/ruby/core/process/fixtures/clocks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def self.clock_constants
1111
clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM]
1212
end
1313

14-
clocks.map { |c|
14+
clocks.sort.map { |c|
1515
[c, Process.const_get(c)]
1616
}
1717
end

spec/ruby/core/process/getrlimit_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
end
4242

4343
context "when passed a Symbol" do
44-
Process.constants.grep(/\ARLIMIT_/) do |fullname|
45-
short = $'
46-
it "coerces :#{short} into #{fullname}" do
44+
it "coerces the short name into the full RLIMIT_ prefixed name" do
45+
Process.constants.grep(/\ARLIMIT_/) do |fullname|
46+
short = fullname[/\ARLIMIT_(.+)/, 1]
4747
Process.getrlimit(short.to_sym).should == Process.getrlimit(Process.const_get(fullname))
4848
end
4949
end
@@ -54,9 +54,9 @@
5454
end
5555

5656
context "when passed a String" do
57-
Process.constants.grep(/\ARLIMIT_/) do |fullname|
58-
short = $'
59-
it "coerces '#{short}' into #{fullname}" do
57+
it "coerces the short name into the full RLIMIT_ prefixed name" do
58+
Process.constants.grep(/\ARLIMIT_/) do |fullname|
59+
short = fullname[/\ARLIMIT_(.+)/, 1]
6060
Process.getrlimit(short).should == Process.getrlimit(Process.const_get(fullname))
6161
end
6262
end

0 commit comments

Comments
 (0)