Skip to content

Commit 3fa612b

Browse files
committed
Update specs
PullRequest: truffleruby/507
2 parents 2f4ba36 + 706d0d9 commit 3fa612b

Some content is hidden

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

65 files changed

+1018
-654
lines changed

spec/mspec/lib/mspec/helpers/fs.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Copies a file
22
def cp(source, dest)
3-
File.open(dest, "wb") do |d|
4-
File.open(source, "rb") do |s|
5-
while data = s.read(1024)
6-
d.write data
7-
end
8-
end
9-
end
3+
IO.copy_stream source, dest
104
end
115

126
# Creates each directory in path that does not exist.

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,12 @@ def test_new_specs
160160
require "yaml"
161161
Dir.chdir(SOURCE_REPO) do
162162
versions = YAML.load_file(".travis.yml")
163-
versions = versions["matrix"]["include"].map { |job| job["rvm"] }
164-
versions.delete "ruby-head"
165-
versions.delete "system"
163+
versions = if versions.include? "matrix"
164+
versions["matrix"]["include"].map { |job| job["rvm"] }
165+
else
166+
versions["rvm"]
167+
end
168+
versions = versions.grep(/^\d+\./) # Test on MRI
166169
min_version, max_version = versions.minmax
167170

168171
test_command = MSPEC ? "bundle exec rspec" : "../mspec/bin/mspec -j"

spec/ruby/.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ matrix:
1010
env: MSPEC_OPTS="-R2 -ff"
1111
- rvm: 2.3.8
1212
- rvm: 2.4.5
13+
env: CHECK_LEAKS=true
1314
- rvm: 2.5.3
1415
env: CHECK_LEAKS=true
16+
- rvm: 2.6.0
17+
env: CHECK_LEAKS=true
1518
- rvm: ruby-head
1619
- env: RUBOCOP=true
1720
rvm: 2.4.5
1821
script:
19-
- gem install rubocop -v 0.54.0
22+
- gem install rubocop:0.61.0
2023
- rubocop
2124
allow_failures:
2225
- rvm: ruby-head

spec/ruby/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ ruby/spec is known to be tested in these implementations for every commit:
2828
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
2929
* [Opal](https://github.com/opal/opal/tree/master/spec)
3030

31+
ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
32+
More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.3.x, 2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
33+
3134
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
32-
Each of these repositories has a full copy of the files to ease editing specs.
35+
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
36+
Any of these repositories can be used to add or edit specs, use what is most convenient for you.
3337

34-
ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
35-
More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
36-
(2.3.x, 2.4.x, 2.5.x, etc).
38+
For *testing* a Ruby implementation, one should always test against the implementation's copy of the specs under `spec/ruby`, as that's what the Ruby implementation tests against in their CI.
39+
Also, this repository doesn't always contain the latest spec changes from MRI (it's synchronized monthly), and does not contain tags (specs marked as failing on that Ruby implementation).
40+
Running specs in a Ruby implementation can be done with:
41+
42+
```
43+
$ cd ruby_implementation/spec/ruby
44+
# Add ../ruby_implementation/bin in PATH, or pass -t /path/to/bin/ruby
45+
$ ../mspec/bin/mspec
46+
```
3747

3848
For older specs try these commits:
3949
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
@@ -63,7 +73,7 @@ This will execute all the specs using the executable named `ruby` on your curren
6373
### Running Specs with a Specific Ruby Implementation
6474

6575
Use the `-t` option to specify the Ruby implementation with which to run the specs.
66-
The argument may be a full path to the Ruby binary.
76+
The argument is either a full path to the Ruby binary, or an executable in `$PATH`.
6777

6878
$ ../mspec/bin/mspec -t /path/to/some/bin/ruby
6979

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
require_relative 'shared/difference'
4+
5+
ruby_version_is "2.6" do
6+
describe "Array#difference" do
7+
it_behaves_like :array_binary_difference, :-
8+
9+
it "returns a copy when called without any parameter" do
10+
x = [1, 2, 3, 2]
11+
x.difference.should == x
12+
x.difference.should_not equal x
13+
end
14+
15+
it "does not return subclass instances for Array subclasses" do
16+
ArraySpecs::MyArray[1, 2, 3].difference.should be_an_instance_of(Array)
17+
end
18+
19+
it "accepts multiple arguments" do
20+
x = [1, 2, 3, 1]
21+
x.difference([], [0, 1], [3, 4], [3]).should == [2]
22+
end
23+
end
24+
end

spec/ruby/core/array/minus_spec.rb

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,7 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
3+
require_relative 'shared/difference'
34

45
describe "Array#-" do
5-
it "creates an array minus any items from other array" do
6-
([] - [ 1, 2, 4 ]).should == []
7-
([1, 2, 4] - []).should == [1, 2, 4]
8-
([ 1, 2, 3, 4, 5 ] - [ 1, 2, 4 ]).should == [3, 5]
9-
end
10-
11-
it "removes multiple items on the lhs equal to one on the rhs" do
12-
([1, 1, 2, 2, 3, 3, 4, 5] - [1, 2, 4]).should == [3, 3, 5]
13-
end
14-
15-
it "properly handles recursive arrays" do
16-
empty = ArraySpecs.empty_recursive_array
17-
(empty - empty).should == []
18-
19-
([] - ArraySpecs.recursive_array).should == []
20-
21-
array = ArraySpecs.recursive_array
22-
(array - array).should == []
23-
end
24-
25-
it "tries to convert the passed arguments to Arrays using #to_ary" do
26-
obj = mock('[2,3,3,4]')
27-
obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
28-
([1, 1, 2, 2, 3, 4] - obj).should == [1, 1]
29-
end
30-
31-
it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
32-
obj = mock('not an array')
33-
lambda { [1, 2, 3] - obj }.should raise_error(TypeError)
34-
end
35-
36-
it "does not return subclass instance for Array subclasses" do
37-
(ArraySpecs::MyArray[1, 2, 3] - []).should be_an_instance_of(Array)
38-
(ArraySpecs::MyArray[1, 2, 3] - ArraySpecs::MyArray[]).should be_an_instance_of(Array)
39-
([1, 2, 3] - ArraySpecs::MyArray[]).should be_an_instance_of(Array)
40-
end
41-
42-
it "does not call to_ary on array subclasses" do
43-
([5, 6, 7] - ArraySpecs::ToAryArray[7]).should == [5, 6]
44-
end
45-
46-
it "removes an item identified as equivalent via #hash and #eql?" do
47-
obj1 = mock('1')
48-
obj2 = mock('2')
49-
obj1.stub!(:hash).and_return(0)
50-
obj2.stub!(:hash).and_return(0)
51-
obj1.should_receive(:eql?).at_least(1).and_return(true)
52-
53-
([obj1] - [obj2]).should == []
54-
([obj1, obj1, obj2, obj2] - [obj2]).should == []
55-
end
56-
57-
it "doesn't remove an item with the same hash but not #eql?" do
58-
obj1 = mock('1')
59-
obj2 = mock('2')
60-
obj1.stub!(:hash).and_return(0)
61-
obj2.stub!(:hash).and_return(0)
62-
obj1.should_receive(:eql?).at_least(1).and_return(false)
63-
64-
([obj1] - [obj2]).should == [obj1]
65-
([obj1, obj1, obj2, obj2] - [obj2]).should == [obj1, obj1]
66-
end
67-
68-
it "removes an identical item even when its #eql? isn't reflexive" do
69-
x = mock('x')
70-
x.stub!(:hash).and_return(42)
71-
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
72-
73-
([x] - [x]).should == []
74-
end
75-
76-
it "is not destructive" do
77-
a = [1, 2, 3]
78-
a - []
79-
a.should == [1, 2, 3]
80-
a - [1]
81-
a.should == [1, 2, 3]
82-
a - [1,2,3]
83-
a.should == [1, 2, 3]
84-
a - [:a, :b, :c]
85-
a.should == [1, 2, 3]
86-
end
6+
it_behaves_like :array_binary_difference, :-
877
end

spec/ruby/core/array/pack/l_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
it_behaves_like :array_pack_32bit_be, 'L>'
3030
end
3131

32-
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
32+
platform_is wordsize: 32 do
3333
describe "with modifier '<' and '_'" do
3434
it_behaves_like :array_pack_32bit_le, 'L<_'
3535
it_behaves_like :array_pack_32bit_le, 'L_<'
@@ -51,7 +51,7 @@
5151
end
5252
end
5353

54-
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
54+
platform_is wordsize: 64 do
5555
describe "with modifier '<' and '_'" do
5656
it_behaves_like :array_pack_64bit_le, 'L<_'
5757
it_behaves_like :array_pack_64bit_le, 'L_<'
@@ -83,7 +83,7 @@
8383
it_behaves_like :array_pack_32bit_be, 'l>'
8484
end
8585

86-
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
86+
platform_is wordsize: 32 do
8787
describe "with modifier '<' and '_'" do
8888
it_behaves_like :array_pack_32bit_le, 'l<_'
8989
it_behaves_like :array_pack_32bit_le, 'l_<'
@@ -105,7 +105,7 @@
105105
end
106106
end
107107

108-
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
108+
platform_is wordsize: 64 do
109109
describe "with modifier '<' and '_'" do
110110
it_behaves_like :array_pack_64bit_le, 'l<_'
111111
it_behaves_like :array_pack_64bit_le, 'l_<'
@@ -137,7 +137,7 @@
137137
it_behaves_like :array_pack_32bit_le, 'l'
138138
end
139139

140-
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
140+
platform_is wordsize: 32 do
141141
describe "Array#pack with format 'L' with modifier '_'" do
142142
it_behaves_like :array_pack_32bit_le, 'L_'
143143
end
@@ -155,7 +155,7 @@
155155
end
156156
end
157157

158-
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
158+
platform_is wordsize: 64 do
159159
describe "Array#pack with format 'L' with modifier '_'" do
160160
it_behaves_like :array_pack_64bit_le, 'L_'
161161
end
@@ -183,7 +183,7 @@
183183
it_behaves_like :array_pack_32bit_be, 'l'
184184
end
185185

186-
guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
186+
platform_is wordsize: 32 do
187187
describe "Array#pack with format 'L' with modifier '_'" do
188188
it_behaves_like :array_pack_32bit_be, 'L_'
189189
end
@@ -201,7 +201,7 @@
201201
end
202202
end
203203

204-
guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
204+
platform_is wordsize: 64 do
205205
describe "Array#pack with format 'L' with modifier '_'" do
206206
it_behaves_like :array_pack_64bit_be, 'L_'
207207
end
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
describe :array_binary_difference, shared: true do
2+
it "creates an array minus any items from other array" do
3+
[].send(@method, [ 1, 2, 4 ]).should == []
4+
[1, 2, 4].send(@method, []).should == [1, 2, 4]
5+
[ 1, 2, 3, 4, 5 ].send(@method, [ 1, 2, 4 ]).should == [3, 5]
6+
end
7+
8+
it "removes multiple items on the lhs equal to one on the rhs" do
9+
[1, 1, 2, 2, 3, 3, 4, 5].send(@method, [1, 2, 4]).should == [3, 3, 5]
10+
end
11+
12+
it "properly handles recursive arrays" do
13+
empty = ArraySpecs.empty_recursive_array
14+
empty.send(@method, empty).should == []
15+
16+
[].send(@method, ArraySpecs.recursive_array).should == []
17+
18+
array = ArraySpecs.recursive_array
19+
array.send(@method, array).should == []
20+
end
21+
22+
it "tries to convert the passed arguments to Arrays using #to_ary" do
23+
obj = mock('[2,3,3,4]')
24+
obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
25+
[1, 1, 2, 2, 3, 4].send(@method, obj).should == [1, 1]
26+
end
27+
28+
it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
29+
obj = mock('not an array')
30+
lambda { [1, 2, 3].send(@method, obj) }.should raise_error(TypeError)
31+
end
32+
33+
it "does not return subclass instance for Array subclasses" do
34+
ArraySpecs::MyArray[1, 2, 3].send(@method, []).should be_an_instance_of(Array)
35+
ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[]).should be_an_instance_of(Array)
36+
[1, 2, 3].send(@method, ArraySpecs::MyArray[]).should be_an_instance_of(Array)
37+
end
38+
39+
it "does not call to_ary on array subclasses" do
40+
[5, 6, 7].send(@method, ArraySpecs::ToAryArray[7]).should == [5, 6]
41+
end
42+
43+
it "removes an item identified as equivalent via #hash and #eql?" do
44+
obj1 = mock('1')
45+
obj2 = mock('2')
46+
obj1.stub!(:hash).and_return(0)
47+
obj2.stub!(:hash).and_return(0)
48+
obj1.should_receive(:eql?).at_least(1).and_return(true)
49+
50+
[obj1].send(@method, [obj2]).should == []
51+
[obj1, obj1, obj2, obj2].send(@method, [obj2]).should == []
52+
end
53+
54+
it "doesn't remove an item with the same hash but not #eql?" do
55+
obj1 = mock('1')
56+
obj2 = mock('2')
57+
obj1.stub!(:hash).and_return(0)
58+
obj2.stub!(:hash).and_return(0)
59+
obj1.should_receive(:eql?).at_least(1).and_return(false)
60+
61+
[obj1].send(@method, [obj2]).should == [obj1]
62+
[obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1, obj1]
63+
end
64+
65+
it "removes an identical item even when its #eql? isn't reflexive" do
66+
x = mock('x')
67+
x.stub!(:hash).and_return(42)
68+
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
69+
70+
[x].send(@method, [x]).should == []
71+
end
72+
73+
it "is not destructive" do
74+
a = [1, 2, 3]
75+
a.send(@method, [1])
76+
a.should == [1, 2, 3]
77+
end
78+
end

0 commit comments

Comments
 (0)