summaryrefslogtreecommitdiff
path: root/spec/ruby/core/struct/new_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/struct/new_spec.rb')
-rw-r--r--spec/ruby/core/struct/new_spec.rb62
1 files changed, 31 insertions, 31 deletions
diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb
index 741d6889af..b3ece2efed 100644
--- a/spec/ruby/core/struct/new_spec.rb
+++ b/spec/ruby/core/struct/new_spec.rb
@@ -38,19 +38,19 @@ describe "Struct.new" do
it "creates a new anonymous class with nil first argument" do
struct = Struct.new(nil, :foo)
struct.new("bar").foo.should == "bar"
- struct.should be_kind_of(Class)
- struct.name.should be_nil
+ struct.should.is_a?(Class)
+ struct.name.should == nil
end
it "creates a new anonymous class with symbol arguments" do
struct = Struct.new(:make, :model)
- struct.should be_kind_of(Class)
+ struct.should.is_a?(Class)
struct.name.should == nil
end
it "does not create a constant with symbol as first argument" do
Struct.new(:Animal2, :name, :legs, :eyeballs)
- Struct.const_defined?("Animal2").should be_false
+ Struct.const_defined?("Animal2").should == false
end
it "allows non-ASCII member name" do
@@ -60,42 +60,42 @@ describe "Struct.new" do
end
it "fails with invalid constant name as first argument" do
- -> { Struct.new('animal', :name, :legs, :eyeballs) }.should raise_error(NameError)
+ -> { Struct.new('animal', :name, :legs, :eyeballs) }.should.raise(NameError)
end
it "raises a TypeError if object doesn't respond to to_sym" do
- -> { Struct.new(:animal, mock('giraffe')) }.should raise_error(TypeError)
- -> { Struct.new(:animal, 1.0) }.should raise_error(TypeError)
- -> { Struct.new(:animal, Time.now) }.should raise_error(TypeError)
- -> { Struct.new(:animal, Class) }.should raise_error(TypeError)
- -> { Struct.new(:animal, nil) }.should raise_error(TypeError)
- -> { Struct.new(:animal, true) }.should raise_error(TypeError)
- -> { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError)
+ -> { Struct.new(:animal, mock('giraffe')) }.should.raise(TypeError)
+ -> { Struct.new(:animal, 1.0) }.should.raise(TypeError)
+ -> { Struct.new(:animal, Time.now) }.should.raise(TypeError)
+ -> { Struct.new(:animal, Class) }.should.raise(TypeError)
+ -> { Struct.new(:animal, nil) }.should.raise(TypeError)
+ -> { Struct.new(:animal, true) }.should.raise(TypeError)
+ -> { Struct.new(:animal, ['chris', 'evan']) }.should.raise(TypeError)
end
it "raises a TypeError if passed a Hash with an unknown key" do
- -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError)
+ -> { Struct.new(:animal, { name: 'chris' }) }.should.raise(TypeError)
end
it "works when not provided any arguments" do
c = Struct.new
- c.should be_kind_of(Class)
+ c.should.is_a?(Class)
c.superclass.should == Struct
end
it "raises ArgumentError when there is a duplicate member" do
- -> { Struct.new(:foo, :foo) }.should raise_error(ArgumentError, "duplicate member: foo")
+ -> { Struct.new(:foo, :foo) }.should.raise(ArgumentError, "duplicate member: foo")
end
it "raises a TypeError if object is not a Symbol" do
obj = mock(':ruby')
def obj.to_sym() :ruby end
- -> { Struct.new(:animal, obj) }.should raise_error(TypeError)
+ -> { Struct.new(:animal, obj) }.should.raise(TypeError)
end
it "processes passed block with instance_eval" do
klass = Struct.new(:something) { @something_else = 'something else entirely!' }
- klass.instance_variables.should include(:@something_else)
+ klass.instance_variables.should.include?(:@something_else)
end
context "with a block" do
@@ -116,7 +116,7 @@ describe "Struct.new" do
klass = Struct.new(:attr) do |block_parameter|
given = block_parameter
end
- klass.should equal(given)
+ klass.should.equal?(given)
end
end
@@ -133,17 +133,17 @@ describe "Struct.new" do
end
it "creates reader methods" do
- StructClasses::Ruby.new.should have_method(:version)
- StructClasses::Ruby.new.should have_method(:platform)
+ StructClasses::Ruby.new.should.respond_to?(:version)
+ StructClasses::Ruby.new.should.respond_to?(:platform)
end
it "creates writer methods" do
- StructClasses::Ruby.new.should have_method(:version=)
- StructClasses::Ruby.new.should have_method(:platform=)
+ StructClasses::Ruby.new.should.respond_to?(:version=)
+ StructClasses::Ruby.new.should.respond_to?(:platform=)
end
it "fails with too many arguments" do
- -> { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
+ -> { StructClasses::Ruby.new('2.0', 'i686', true) }.should.raise(ArgumentError)
end
it "accepts keyword arguments to initialize" do
@@ -182,7 +182,7 @@ describe "Struct.new" do
it "raises ArgumentError when all struct attribute values are specified" do
type = Struct.new(:a, :b)
- -> { type.new("a", "b", c: "c") }.should raise_error(ArgumentError, "struct size differs")
+ -> { type.new("a", "b", c: "c") }.should.raise(ArgumentError, "struct size differs")
end
end
end
@@ -199,7 +199,7 @@ describe "Struct.new" do
end
it "raises when there is a duplicate member" do
- -> { Struct.new(:foo, :foo, keyword_init: true) }.should raise_error(ArgumentError, "duplicate member: foo")
+ -> { Struct.new(:foo, :foo, keyword_init: true) }.should.raise(ArgumentError, "duplicate member: foo")
end
describe "new class instantiation" do
@@ -212,31 +212,31 @@ describe "Struct.new" do
it "allows missing arguments" do
obj = @struct_with_kwa.new(name: "elefant")
obj.name.should == "elefant"
- obj.legs.should be_nil
+ obj.legs.should == nil
end
it "allows no arguments" do
obj = @struct_with_kwa.new
- obj.name.should be_nil
- obj.legs.should be_nil
+ obj.name.should == nil
+ obj.legs.should == 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/)
+ }.should.raise(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/)
+ }.should.raise(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/)
+ }.should.raise(ArgumentError, /wrong number of arguments/)
end
end
end