Skip to content

Commit ceac0cf

Browse files
committed
[WIP][GR-14806] Update specs
PullRequest: truffleruby/4308
2 parents cd00aae + a2e4be6 commit ceac0cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+887
-173
lines changed

spec/mspec/lib/mspec/helpers/tmp.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@
3636
end
3737

3838
def tmp(name, uniquify = true)
39-
mkdir_p SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
39+
if Dir.exist? SPEC_TEMP_DIR
40+
stat = File.stat(SPEC_TEMP_DIR)
41+
if stat.world_writable? and !stat.sticky?
42+
raise ArgumentError, "SPEC_TEMP_DIR (#{SPEC_TEMP_DIR}) is world writable but not sticky"
43+
end
44+
else
45+
platform_is_not :windows do
46+
umask = File.umask
47+
if (umask & 0002) == 0 # o+w
48+
raise ArgumentError, "File.umask #=> #{umask.to_s(8)} (world-writable)"
49+
end
50+
end
51+
mkdir_p SPEC_TEMP_DIR
52+
end
4053

4154
if uniquify and !name.empty?
4255
slash = name.rindex "/"

spec/mspec/lib/mspec/runner/formatters/multi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ def aggregate_results(files)
4242
end
4343

4444
def print_exception(exc, count)
45-
print "\n#{count})\n#{exc}\n"
45+
@err.print "\n#{count})\n#{exc}\n"
4646
end
4747
end

spec/ruby/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ describe :kernel_sprintf, shared: true do
277277
end
278278

279279
describe "Kernel#sprintf" do
280-
it_behaves_like :kernel_sprintf, -> (format, *args) {
280+
it_behaves_like :kernel_sprintf, -> format, *args {
281281
sprintf(format, *args)
282282
}
283283
end
284284

285285
describe "Kernel.sprintf" do
286-
it_behaves_like :kernel_sprintf, -> (format, *args) {
286+
it_behaves_like :kernel_sprintf, -> format, *args {
287287
Kernel.sprintf(format, *args)
288288
}
289289
end

spec/ruby/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ More precisely, every latest stable MRI release should [pass](https://github.com
3535

3636
### Synchronization with Ruby Implementations
3737

38-
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby,
38+
The specs are synchronized both ways around once a month by @andrykonchin between ruby/spec, MRI, JRuby and TruffleRuby,
3939
using [this script](https://github.com/ruby/mspec/blob/master/tool/sync/sync-rubyspec.rb).
4040
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
4141
Any of these repositories can be used to add or edit specs, use what is most convenient for you.

spec/ruby/core/array/each_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Mutating the array while it is being iterated is discouraged as it can result in confusing behavior.
88
# Yet a Ruby implementation must not crash in such a case, and following the simple CRuby behavior makes sense.
99
# CRuby simply reads the array storage and checks the size for every iteration;
10-
# like `i = 0; while i < size; yield self[i]; end`
10+
# like `i = 0; while i < size; yield self[i]; i += 1; end`
1111

1212
describe "Array#each" do
1313
it "yields each element to the block" do

spec/ruby/core/array/plus_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
2222
end
2323

24-
it "raises a Typeerror if the given argument can't be converted to an array" do
24+
it "raises a TypeError if the given argument can't be converted to an array" do
2525
-> { [1, 2, 3] + nil }.should raise_error(TypeError)
2626
-> { [1, 2, 3] + "abc" }.should raise_error(TypeError)
2727
end

spec/ruby/core/dir/chdir_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
end
2020

2121
it "defaults to $HOME with no arguments" do
22-
if ENV['HOME']
23-
Dir.chdir
24-
current_dir = Dir.pwd
22+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
2523

26-
Dir.chdir(ENV['HOME'])
27-
home = Dir.pwd
28-
current_dir.should == home
29-
end
24+
Dir.chdir
25+
current_dir = Dir.pwd
26+
27+
Dir.chdir(ENV['HOME'])
28+
home = Dir.pwd
29+
current_dir.should == home
3030
end
3131

3232
it "changes to the specified directory" do
@@ -70,6 +70,8 @@ def to_str; DirSpecs.mock_dir; end
7070
end
7171

7272
it "defaults to the home directory when given a block but no argument" do
73+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
74+
7375
# Windows will return a path with forward slashes for ENV["HOME"] so we have
7476
# to compare the route representations returned by Dir.chdir.
7577
current_dir = ""

spec/ruby/core/dir/shared/exist.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
end
3535

3636
it "doesn't expand paths" do
37+
skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
3738
Dir.send(@method, File.expand_path('~')).should be_true
3839
Dir.send(@method, '~').should be_false
3940
end

spec/ruby/core/exception/detailed_message_spec.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ def exception.detailed_message(**)
1515
exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
1616
end
1717

18-
it "accepts highlight keyword argument and adds escape control sequences" do
19-
RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
20-
end
21-
22-
it "allows and ignores other keyword arguments" do
23-
RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
24-
end
25-
2618
it "returns just a message if exception class is anonymous" do
2719
Class.new(RuntimeError).new("message").detailed_message.should == "message"
2820
end
@@ -31,13 +23,30 @@ def exception.detailed_message(**)
3123
RuntimeError.new("").detailed_message.should == "unhandled exception"
3224
end
3325

34-
it "returns just class name for an instance of RuntimeError subclass with empty message" do
26+
it "returns just class name for an instance other than RuntimeError with empty message" do
3527
DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
28+
StandardError.new("").detailed_message.should == "StandardError"
3629
end
3730

3831
it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
3932
klass = Class.new(RuntimeError)
4033
klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
4134
end
35+
36+
it "accepts highlight keyword argument and adds escape control sequences" do
37+
RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
38+
end
39+
40+
it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do
41+
RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m"
42+
end
43+
44+
it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do
45+
StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m"
46+
end
47+
48+
it "allows and ignores other keyword arguments" do
49+
RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
50+
end
4251
end
4352
end

spec/ruby/core/hash/replace_spec.rb

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,70 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
3-
require_relative 'shared/replace'
43

54
describe "Hash#replace" do
6-
it_behaves_like :hash_replace, :replace
5+
it "replaces the contents of self with other" do
6+
h = { a: 1, b: 2 }
7+
h.replace(c: -1, d: -2).should equal(h)
8+
h.should == { c: -1, d: -2 }
9+
end
10+
11+
it "tries to convert the passed argument to a hash using #to_hash" do
12+
obj = mock('{1=>2,3=>4}')
13+
obj.should_receive(:to_hash).and_return({ 1 => 2, 3 => 4 })
14+
15+
h = {}
16+
h.replace(obj)
17+
h.should == { 1 => 2, 3 => 4 }
18+
end
19+
20+
it "calls to_hash on hash subclasses" do
21+
h = {}
22+
h.replace(HashSpecs::ToHashHash[1 => 2])
23+
h.should == { 1 => 2 }
24+
end
25+
26+
it "transfers the compare_by_identity flag" do
27+
hash_a = { a: 1 }
28+
hash_b = { b: 2 }
29+
hash_b.compare_by_identity
30+
hash_a.should_not.compare_by_identity?
31+
hash_a.replace(hash_b)
32+
hash_a.should.compare_by_identity?
33+
34+
hash_a = { a: 1 }
35+
hash_b = { b: 2 }
36+
hash_a.compare_by_identity
37+
hash_a.should.compare_by_identity?
38+
hash_a.replace(hash_b)
39+
hash_a.should_not.compare_by_identity?
40+
end
41+
42+
it "does not transfer default values" do
43+
hash_a = {}
44+
hash_b = Hash.new(5)
45+
hash_a.replace(hash_b)
46+
hash_a.default.should == 5
47+
48+
hash_a = {}
49+
hash_b = Hash.new { |h, k| k * 2 }
50+
hash_a.replace(hash_b)
51+
hash_a.default(5).should == 10
52+
53+
hash_a = Hash.new { |h, k| k * 5 }
54+
hash_b = Hash.new(-> { raise "Should not invoke lambda" })
55+
hash_a.replace(hash_b)
56+
hash_a.default.should == hash_b.default
57+
end
58+
59+
it "raises a FrozenError if called on a frozen instance that would not be modified" do
60+
-> do
61+
HashSpecs.frozen_hash.replace(HashSpecs.frozen_hash)
62+
end.should raise_error(FrozenError)
63+
end
64+
65+
it "raises a FrozenError if called on a frozen instance that is modified" do
66+
-> do
67+
HashSpecs.frozen_hash.replace(HashSpecs.empty_frozen_hash)
68+
end.should raise_error(FrozenError)
69+
end
770
end

0 commit comments

Comments
 (0)