Skip to content

Commit 8db4f25

Browse files
committed
1 parent ae650f0 commit 8db4f25

Some content is hidden

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

41 files changed

+820
-55
lines changed

spec/ruby/.mspec.constants

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ CodingUS_ASCII
3939
CodingUTF_8
4040
ComparisonTest
4141
ConstantSpecsIncludedModule
42+
ConstantSpecsTwo
43+
ConstantSpecsThree
4244
ConstantVisibility
4345
Coverage
4446
CoverageSpecs

spec/ruby/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Every example code has a textual description, which presents several advantages:
1818

1919
The specs are written with syntax similar to RSpec 2.
2020
They are run with MSpec, the purpose-built framework for running the Ruby Spec Suite.
21-
For more information, see the [MSpec](http://github.com/ruby/mspec) project.
21+
For more information, see the [MSpec](https://github.com/ruby/mspec) project.
2222

2323
The specs describe the [language syntax](language/), the [core library](core/), the [standard library](library/), the [C API for extensions](optional/capi) and the [command line flags](command_line/).
2424
The language specs are grouped by keyword while the core and standard library specs are grouped by class and method.
2525

2626
ruby/spec is known to be tested in these implementations for every commit:
27-
* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
27+
* [MRI](https://rubyci.org/) on 30 platforms and 4 versions
2828
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
2929
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
3030
* [Opal](https://github.com/opal/opal/tree/master/spec)
@@ -70,7 +70,7 @@ Then move to it:
7070

7171
$ cd spec
7272

73-
Clone [MSpec](http://github.com/ruby/mspec):
73+
Clone [MSpec](https://github.com/ruby/mspec):
7474

7575
$ git clone https://github.com/ruby/mspec.git ../mspec
7676

@@ -152,5 +152,5 @@ This project was originally born from [Rubinius](https://github.com/rubinius/rub
152152
The revision history of these specs is available [here](https://github.com/ruby/spec/blob/2b886623/CHANGES.before-2008-05-10).
153153
These specs were later extracted to their own project, RubySpec, with a specific vision and principles.
154154
At the end of 2014, Brian Shirai, the creator of RubySpec, decided to [end RubySpec](http://rubinius.com/2014/12/31/matz-s-ruby-developers-don-t-use-rubyspec/).
155-
A couple months later, the different repositories were merged and [the project was revived](http://eregon.github.io/rubyspec/2015/07/29/rubyspec-is-reborn.html).
155+
A couple months later, the different repositories were merged and [the project was revived](https://eregon.github.io/rubyspec/2015/07/29/rubyspec-is-reborn.html).
156156
On 12 January 2016, the name was changed to "The Ruby Spec Suite" for clarity and to let the RubySpec ideology rest in peace.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
it "does not add a NULL byte when passed the '*' modifier" do
3232
[].pack("x*").should == ""
33+
[1, 2].pack("Cx*C").should == "\x01\x02"
3334
end
3435
end
3536

spec/ruby/core/array/sample_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
[].sample.should be_nil
2020
end
2121

22+
it "returns nil for an empty array when called without n and a Random is given" do
23+
[].sample(random: Random.new(42)).should be_nil
24+
end
25+
2226
it "returns a single value when not passed a count" do
2327
[4].sample.should equal(4)
2428
end
2529

30+
it "returns a single value when not passed a count and a Random is given" do
31+
[4].sample(random: Random.new(42)).should equal(4)
32+
end
33+
2634
it "returns an empty Array when passed zero" do
2735
[4].sample(0).should == []
2836
end

spec/ruby/core/dir/foreach_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
it "accepts an encoding keyword for the encoding of the entries" do
4343
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
4444
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
45+
46+
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE).to_a.sort
47+
dirs.each {|dir| dir.encoding.should == Encoding::UTF_16LE}
48+
49+
Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE) do |f|
50+
f.encoding.should == Encoding::UTF_16LE
51+
end
4552
end
4653

4754
ruby_version_is ""..."2.7" do

spec/ruby/core/enumerable/shared/inject.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,11 @@
6666
it "returns nil when fails(legacy rubycon)" do
6767
EnumerableSpecs::EachDefiner.new().send(@method) {|acc,x| 999 }.should == nil
6868
end
69+
70+
ruby_bug '#18635', ''...'3.2' do
71+
it "raises an ArgumentError when no parameters or block is given" do
72+
-> { [1,2].send(@method) }.should raise_error(ArgumentError)
73+
-> { {one: 1, two: 2}.send(@method) }.should raise_error(ArgumentError)
74+
end
75+
end
6976
end

spec/ruby/core/enumerator/lazy/with_index_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,13 @@
2626
(0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3)
2727
result.should == [[0,0],[2,1],[4,2]]
2828
end
29+
30+
it "resets after a new call to each" do
31+
enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] }
32+
result = []
33+
enum.each { |i, idx| result << [i, idx] }
34+
enum.each { |i, idx| result << [i, idx] }
35+
result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]]
36+
end
2937
end
3038
end

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515
it "supports :highlight option and adds escape sequences to highlight some strings" do
1616
e = RuntimeError.new("Some runtime error")
1717

18-
full_message = e.full_message(highlight: true, order: :bottom)
19-
full_message.should include "\e[1mTraceback\e[m (most recent call last)"
20-
full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
18+
full_message = e.full_message(highlight: true, order: :top).lines
19+
full_message[0].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
2120

22-
full_message = e.full_message(highlight: false, order: :bottom)
23-
full_message.should include "Traceback (most recent call last)"
24-
full_message.should include "Some runtime error (RuntimeError)"
21+
full_message = e.full_message(highlight: true, order: :bottom).lines
22+
full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n"
23+
full_message[-1].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
24+
25+
full_message = e.full_message(highlight: false, order: :top).lines
26+
full_message[0].should.end_with? "Some runtime error (RuntimeError)\n"
27+
28+
full_message = e.full_message(highlight: false, order: :bottom).lines
29+
full_message[0].should == "Traceback (most recent call last):\n"
30+
full_message[-1].should.end_with? "Some runtime error (RuntimeError)\n"
2531
end
2632

2733
it "supports :order option and places the error message and the backtrace at the top or the bottom" do
@@ -35,22 +41,34 @@
3541
it "shows the caller if the exception has no backtrace" do
3642
e = RuntimeError.new("Some runtime error")
3743
e.backtrace.should == nil
38-
full_message = e.full_message(highlight: false, order: :top)
39-
full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
40-
full_message.should include("': Some runtime error (RuntimeError)\n")
44+
full_message = e.full_message(highlight: false, order: :top).lines
45+
full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in `")
46+
full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n")
4147
end
4248

4349
it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
4450
begin
4551
line = __LINE__; raise "first line\nsecond line"
4652
rescue => e
4753
full_message = e.full_message(highlight: false, order: :top).lines
48-
full_message[0].should include("#{__FILE__}:#{line}:in `")
49-
full_message[0].should include(": first line (RuntimeError)\n")
54+
full_message[0].should.start_with?("#{__FILE__}:#{line}:in `")
55+
full_message[0].should.end_with?(": first line (RuntimeError)\n")
5056
full_message[1].should == "second line\n"
5157
end
5258
end
5359

60+
it "highlights the entire message when the message contains multiple lines" do
61+
begin
62+
line = __LINE__; raise "first line\nsecond line\nthird line"
63+
rescue => e
64+
full_message = e.full_message(highlight: true, order: :top).lines
65+
full_message[0].should.start_with?("#{__FILE__}:#{line}:in `")
66+
full_message[0].should.end_with?(": \e[1mfirst line (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n")
67+
full_message[1].should == "\e[1msecond line\e[m\n"
68+
full_message[2].should == "\e[1mthird line\e[m\n"
69+
end
70+
end
71+
5472
it "contains cause of exception" do
5573
begin
5674
begin

spec/ruby/core/exception/system_exit_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
require_relative '../../spec_helper'
22

33
describe "SystemExit" do
4+
describe "#initialize" do
5+
it "accepts a status and message" do
6+
exc = SystemExit.new(42, "message")
7+
exc.status.should == 42
8+
exc.message.should == "message"
9+
10+
exc = SystemExit.new(true, "message")
11+
exc.status.should == 0
12+
exc.message.should == "message"
13+
14+
exc = SystemExit.new(false, "message")
15+
exc.status.should == 1
16+
exc.message.should == "message"
17+
end
18+
19+
it "accepts a status only" do
20+
exc = SystemExit.new(42)
21+
exc.status.should == 42
22+
exc.message.should == "SystemExit"
23+
24+
exc = SystemExit.new(true)
25+
exc.status.should == 0
26+
exc.message.should == "SystemExit"
27+
28+
exc = SystemExit.new(false)
29+
exc.status.should == 1
30+
exc.message.should == "SystemExit"
31+
end
32+
33+
it "accepts a message only" do
34+
exc = SystemExit.new("message")
35+
exc.status.should == 0
36+
exc.message.should == "message"
37+
end
38+
39+
it "accepts no arguments" do
40+
exc = SystemExit.new
41+
exc.status.should == 0
42+
exc.message.should == "SystemExit"
43+
end
44+
end
45+
446
it "sets the exit status and exits silently when raised" do
547
code = 'raise SystemExit.new(7)'
648
result = ruby_exe(code, args: "2>&1", exit_status: 7)

spec/ruby/core/file/utime_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
File.mtime(@file1).nsec.should.between?(0, 123500000)
7878
end
7979

80+
it "returns the number of filenames in the arguments" do
81+
File.utime(@atime.to_f, @mtime.to_f, @file1, @file2).should == 2
82+
end
83+
8084
platform_is :linux do
8185
platform_is wordsize: 64 do
8286
it "allows Time instances in the far future to set mtime and atime (but some filesystems limit it up to 2446-05-10 or 2038-01-19)" do

0 commit comments

Comments
 (0)