Skip to content

Commit e369f61

Browse files
andrykonchineregon
authored andcommitted
[GR-14806] Update specs
PullRequest: truffleruby/4551
2 parents 7febb68 + 8091b25 commit e369f61

File tree

183 files changed

+750
-526
lines changed

Some content is hidden

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

183 files changed

+750
-526
lines changed

spec/ruby/core/array/fetch_values_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
describe "with unmatched indexes" do
2323
it "raises a index error if no block is provided" do
24-
-> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError)
24+
-> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError, "index 44 outside of array bounds: -3...3")
2525
end
2626

2727
it "returns the default value from block" do
@@ -42,8 +42,14 @@
4242
@array.fetch_values(obj).should == [:c]
4343
end
4444

45+
it "does not support a Range object as argument" do
46+
-> {
47+
@array.fetch_values(1..2)
48+
}.should raise_error(TypeError, "no implicit conversion of Range into Integer")
49+
end
50+
4551
it "raises a TypeError when the passed argument can't be coerced to Integer" do
46-
-> { [].fetch_values("cat") }.should raise_error(TypeError)
52+
-> { [].fetch_values("cat") }.should raise_error(TypeError, "no implicit conversion of String into Integer")
4753
end
4854
end
4955
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22

33
require_relative '../../../spec_helper'
44
require_relative '../fixtures/classes'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

spec/ruby/core/array/pack/shared/float.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22

33
describe :array_pack_float_le, shared: true do
44
it "encodes a positive Float" do

spec/ruby/core/array/pack/shared/integer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22

33
describe :array_pack_16bit_le, shared: true do
44
it "encodes the least significant 16 bits of a positive number" do

spec/ruby/core/array/pack/shared/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
describe :array_pack_string, shared: true do
33
it "adds count bytes of a String to the output" do
44
["abc"].pack(pack_format(2)).should == "ab"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33
require_relative '../fixtures/classes'
44
require_relative 'shared/basic'

spec/ruby/core/data/deconstruct_keys_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
33

4-
describe "Data#deconstruct" do
4+
describe "Data#deconstruct_keys" do
55
it "returns a hash of attributes" do
66
klass = Data.define(:x, :y)
77
d = klass.new(1, 2)
8+
89
d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
910
end
1011

@@ -29,6 +30,7 @@
2930
it "accepts string attribute names" do
3031
klass = Data.define(:x, :y)
3132
d = klass.new(1, 2)
33+
3234
d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
3335
end
3436

@@ -58,6 +60,7 @@
5860
it "returns an empty hash when there are more keys than attributes" do
5961
klass = Data.define(:x, :y)
6062
d = klass.new(1, 2)
63+
6164
d.deconstruct_keys([:x, :y, :x]).should == {}
6265
end
6366

@@ -84,6 +87,28 @@
8487
d.deconstruct_keys(nil).should == {x: 1, y: 2}
8588
end
8689

90+
it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
91+
klass = Data.define(:x, :y)
92+
d = klass.new(1, 2)
93+
94+
key = mock("to_int")
95+
key.should_receive(:to_int).and_return(1)
96+
97+
d.deconstruct_keys([key]).should == { key => 2 }
98+
end
99+
100+
it "raises a TypeError if the conversion with #to_int does not return an Integer" do
101+
klass = Data.define(:x, :y)
102+
d = klass.new(1, 2)
103+
104+
key = mock("to_int")
105+
key.should_receive(:to_int).and_return("not an Integer")
106+
107+
-> {
108+
d.deconstruct_keys([key])
109+
}.should raise_error(TypeError, /can't convert MockObject to Integer/)
110+
end
111+
87112
it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do
88113
klass = Data.define(:x, :y)
89114
d = klass.new(1, 2)

spec/ruby/core/data/fixtures/classes.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,13 @@ def self.name
99
end
1010

1111
class DataSubclass < Data; end
12+
13+
MeasureSubclass = Class.new(Measure) do
14+
def initialize(amount:, unit:)
15+
super
16+
end
17+
end
18+
19+
Empty = Data.define()
1220
end
1321
end

spec/ruby/core/data/initialize_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@
6060
e.message.should.include?("unknown keyword: :system")
6161
}
6262
end
63+
64+
it "supports super from a subclass" do
65+
ms = DataSpecs::MeasureSubclass.new(amount: 1, unit: "km")
66+
67+
ms.amount.should == 1
68+
ms.unit.should == "km"
69+
end
70+
71+
it "supports Data with no fields" do
72+
-> { DataSpecs::Empty.new }.should_not raise_error
73+
end
6374
end

spec/ruby/core/encoding/compatible_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22

33
require_relative '../../spec_helper'
44

@@ -171,7 +171,7 @@
171171
# Use the following script to regenerate the matrix:
172172
#
173173
# ```
174-
# # -*- encoding: binary -*-
174+
# # encoding: binary
175175
#
176176
# ENCODINGS = [
177177
# "US-ASCII",

spec/ruby/core/encoding/converter/convert_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
# frozen_string_literal: true
33
require_relative '../../../spec_helper'
44

spec/ruby/core/encoding/converter/last_error_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33

44
describe "Encoding::Converter#last_error" do

spec/ruby/core/encoding/converter/new_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33

44
describe "Encoding::Converter.new" do

spec/ruby/core/encoding/converter/primitive_convert_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
# frozen_string_literal: false
33
require_relative '../../../spec_helper'
44

spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
# frozen_string_literal: false
33
require_relative '../../../spec_helper'
44

spec/ruby/core/encoding/converter/putback_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33

44
describe "Encoding::Converter#putback" do

spec/ruby/core/encoding/fixtures/classes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
module EncodingSpecs
33
class UndefinedConversionError
44
def self.exception

spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative "../../../spec_helper"
33
require_relative '../fixtures/classes'
44

spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../../spec_helper'
33

44
describe "Encoding::InvalidByteSequenceError#incomplete_input?" do

spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative "../../../spec_helper"
33
require_relative '../fixtures/classes'
44

spec/ruby/core/encoding/replicate_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../spec_helper'
33

44
describe "Encoding#replicate" do

spec/ruby/core/env/element_reference_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- encoding: binary -*-
1+
# encoding: binary
22
require_relative '../../spec_helper'
33
require_relative 'fixtures/common'
44

spec/ruby/core/exception/frozen_error_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def o.x; end
2828

2929
-> {
3030
def object.x; end
31-
}.should raise_error(FrozenError, "can't modify frozen object: #{object.to_s}")
31+
}.should raise_error(FrozenError, "can't modify frozen object: #{object}")
3232

3333
object = [].freeze
3434
-> { object << nil }.should raise_error(FrozenError, "can't modify frozen Array: []")
Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/common'
3+
require_relative 'shared/set_backtrace'
34

45
describe "Exception#set_backtrace" do
5-
it "accepts an Array of Strings" do
6-
err = RuntimeError.new
7-
err.set_backtrace ["unhappy"]
8-
err.backtrace.should == ["unhappy"]
9-
end
10-
116
it "allows the user to set the backtrace from a rescued exception" do
127
bt = ExceptionSpecs::Backtrace.backtrace
138
err = RuntimeError.new
@@ -20,65 +15,9 @@
2015
err.backtrace_locations.should == nil
2116
end
2217

23-
ruby_version_is "3.4" do
24-
it "allows the user to set backtrace locations from a rescued exception" do
25-
bt_locations = ExceptionSpecs::Backtrace.backtrace_locations
26-
err = RuntimeError.new
27-
err.backtrace.should == nil
28-
err.backtrace_locations.should == nil
29-
30-
err.set_backtrace bt_locations
31-
32-
err.backtrace_locations.size.should == bt_locations.size
33-
err.backtrace_locations.each_with_index do |loc, index|
34-
other_loc = bt_locations[index]
35-
36-
loc.path.should == other_loc.path
37-
loc.label.should == other_loc.label
38-
loc.base_label.should == other_loc.base_label
39-
loc.lineno.should == other_loc.lineno
40-
loc.absolute_path.should == other_loc.absolute_path
41-
loc.to_s.should == other_loc.to_s
42-
end
43-
err.backtrace.size.should == err.backtrace_locations.size
44-
end
45-
end
46-
47-
it "accepts an empty Array" do
48-
err = RuntimeError.new
49-
err.set_backtrace []
50-
err.backtrace.should == []
51-
end
52-
53-
it "accepts a String" do
18+
it_behaves_like :exception_set_backtrace, -> backtrace {
5419
err = RuntimeError.new
55-
err.set_backtrace "unhappy"
56-
err.backtrace.should == ["unhappy"]
57-
end
58-
59-
it "accepts nil" do
60-
err = RuntimeError.new
61-
err.set_backtrace nil
62-
err.backtrace.should be_nil
63-
end
64-
65-
it "raises a TypeError when passed a Symbol" do
66-
err = RuntimeError.new
67-
-> { err.set_backtrace :unhappy }.should raise_error(TypeError)
68-
end
69-
70-
it "raises a TypeError when the Array contains a Symbol" do
71-
err = RuntimeError.new
72-
-> { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError)
73-
end
74-
75-
it "raises a TypeError when the array contains nil" do
76-
err = Exception.new
77-
-> { err.set_backtrace ["String", nil] }.should raise_error(TypeError)
78-
end
79-
80-
it "raises a TypeError when the argument is a nested array" do
81-
err = Exception.new
82-
-> { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError)
83-
end
20+
err.set_backtrace(backtrace)
21+
err
22+
}
8423
end

0 commit comments

Comments
 (0)