summaryrefslogtreecommitdiff
path: root/spec/ruby/core/struct
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-08 19:43:27 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-01 15:36:20 +0900
commit826f44834fe11f3f9c52343443a15b6c83466889 (patch)
treef2c2abed62db1c750515cd8b0fbac6442b6d4200 /spec/ruby/core/struct
parent3a2073e61b6ccce6d07d31ebd89d4c385b9a55f2 (diff)
Drop support for ruby 2.4 from ruby/spec
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2892
Diffstat (limited to 'spec/ruby/core/struct')
-rw-r--r--spec/ruby/core/struct/hash_spec.rb14
-rw-r--r--spec/ruby/core/struct/new_spec.rb112
2 files changed, 57 insertions, 69 deletions
diff --git a/spec/ruby/core/struct/hash_spec.rb b/spec/ruby/core/struct/hash_spec.rb
index 5ed4ace489..545929e402 100644
--- a/spec/ruby/core/struct/hash_spec.rb
+++ b/spec/ruby/core/struct/hash_spec.rb
@@ -25,14 +25,12 @@ describe "Struct#hash" do
s1.hash.should_not == s2.hash
end
- ruby_version_is "2.5" do
- it "returns different hashes for structs with different values when using keyword_init: true" do
- key = :"1 non symbol member"
- struct_class = Struct.new(key, keyword_init: true)
- t1 = struct_class.new(key => 1)
- t2 = struct_class.new(key => 2)
- t1.hash.should_not == t2.hash
- end
+ it "returns different hashes for structs with different values when using keyword_init: true" do
+ key = :"1 non symbol member"
+ struct_class = Struct.new(key, keyword_init: true)
+ t1 = struct_class.new(key => 1)
+ t2 = struct_class.new(key => 2)
+ t1.hash.should_not == t2.hash
end
it "allows for overriding methods in an included module" do
diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb
index 071aa38d25..bb814e7cd1 100644
--- a/spec/ruby/core/struct/new_spec.rb
+++ b/spec/ruby/core/struct/new_spec.rb
@@ -62,16 +62,8 @@ describe "Struct.new" do
-> { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError)
end
- ruby_version_is ""..."2.5" do
- it "raises a TypeError if an argument is a Hash" do
- -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.5" do
- it "raises a ArgumentError if passed a Hash with an unknown key" do
- -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(ArgumentError)
- end
+ it "raises a ArgumentError if passed a Hash with an unknown key" do
+ -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(ArgumentError)
end
it "raises ArgumentError when there is a duplicate member" do
@@ -147,71 +139,69 @@ describe "Struct.new" do
end
end
- ruby_version_is "2.5" do
- context "keyword_init: true option" do
- before :all do
- @struct_with_kwa = Struct.new(:name, :legs, keyword_init: true)
- end
+ context "keyword_init: true option" do
+ before :all do
+ @struct_with_kwa = Struct.new(:name, :legs, keyword_init: true)
+ end
+
+ it "creates a class that accepts keyword arguments to initialize" do
+ obj = @struct_with_kwa.new(name: "elefant", legs: 4)
+ obj.name.should == "elefant"
+ obj.legs.should == 4
+ end
+
+ it "raises when there is a duplicate member" do
+ -> { Struct.new(:foo, :foo, keyword_init: true) }.should raise_error(ArgumentError, "duplicate member: foo")
+ end
- it "creates a class that accepts keyword arguments to initialize" do
- obj = @struct_with_kwa.new(name: "elefant", legs: 4)
+ describe "new class instantiation" do
+ it "accepts arguments as hash as well" do
+ obj = @struct_with_kwa.new({name: "elefant", legs: 4})
obj.name.should == "elefant"
obj.legs.should == 4
end
- it "raises when there is a duplicate member" do
- -> { Struct.new(:foo, :foo, keyword_init: true) }.should raise_error(ArgumentError, "duplicate member: foo")
+ it "allows missing arguments" do
+ obj = @struct_with_kwa.new(name: "elefant")
+ obj.name.should == "elefant"
+ obj.legs.should be_nil
end
- describe "new class instantiation" do
- it "accepts arguments as hash as well" do
- obj = @struct_with_kwa.new({name: "elefant", legs: 4})
- obj.name.should == "elefant"
- obj.legs.should == 4
- end
-
- it "allows missing arguments" do
- obj = @struct_with_kwa.new(name: "elefant")
- obj.name.should == "elefant"
- obj.legs.should be_nil
- end
-
- it "allows no arguments" do
- obj = @struct_with_kwa.new
- obj.name.should be_nil
- obj.legs.should be_nil
- end
+ it "allows no arguments" do
+ obj = @struct_with_kwa.new
+ obj.name.should be_nil
+ obj.legs.should be_nil
+ end
- it "raises ArgumentError when passed not declared keyword argument" do
- -> {
- @struct_with_kwa.new(name: "elefant", legs: 4, foo: "bar")
- }.should raise_error(ArgumentError, /unknown keywords: foo/)
- end
+ it "raises ArgumentError when passed not declared keyword argument" do
+ -> {
+ @struct_with_kwa.new(name: "elefant", legs: 4, foo: "bar")
+ }.should raise_error(ArgumentError, /unknown keywords: foo/)
+ end
- it "raises ArgumentError when passed a list of arguments" do
- -> {
- @struct_with_kwa.new("elefant", 4)
- }.should raise_error(ArgumentError, /wrong number of arguments/)
- end
+ it "raises ArgumentError when passed a list of arguments" do
+ -> {
+ @struct_with_kwa.new("elefant", 4)
+ }.should raise_error(ArgumentError, /wrong number of arguments/)
+ end
- it "raises ArgumentError when passed a single non-hash argument" do
- -> {
- @struct_with_kwa.new("elefant")
- }.should raise_error(ArgumentError, /wrong number of arguments/)
- end
+ it "raises ArgumentError when passed a single non-hash argument" do
+ -> {
+ @struct_with_kwa.new("elefant")
+ }.should raise_error(ArgumentError, /wrong number of arguments/)
end
end
+ end
- context "keyword_init: false option" do
- before :all do
- @struct_without_kwa = Struct.new(:name, :legs, keyword_init: false)
- end
+ context "keyword_init: false option" do
+ before :all do
+ @struct_without_kwa = Struct.new(:name, :legs, keyword_init: false)
+ end
- it "behaves like it does without :keyword_init option" do
- obj = @struct_without_kwa.new("elefant", 4)
- obj.name.should == "elefant"
- obj.legs.should == 4
- end
+ it "behaves like it does without :keyword_init option" do
+ obj = @struct_without_kwa.new("elefant", 4)
+ obj.name.should == "elefant"
+ obj.legs.should == 4
end
end
end