summaryrefslogtreecommitdiff
path: root/spec/ruby/library/openstruct
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/openstruct')
-rw-r--r--spec/ruby/library/openstruct/delete_field_spec.rb6
-rw-r--r--spec/ruby/library/openstruct/equal_value_spec.rb22
-rw-r--r--spec/ruby/library/openstruct/frozen_spec.rb14
-rw-r--r--spec/ruby/library/openstruct/initialize_spec.rb2
-rw-r--r--spec/ruby/library/openstruct/marshal_load_spec.rb4
-rw-r--r--spec/ruby/library/openstruct/method_missing_spec.rb35
-rw-r--r--spec/ruby/library/openstruct/new_spec.rb4
-rw-r--r--spec/ruby/library/openstruct/shared/inspect.rb2
-rw-r--r--spec/ruby/library/openstruct/to_h_spec.rb62
9 files changed, 64 insertions, 87 deletions
diff --git a/spec/ruby/library/openstruct/delete_field_spec.rb b/spec/ruby/library/openstruct/delete_field_spec.rb
index 9ac80196cc..12fed6c90d 100644
--- a/spec/ruby/library/openstruct/delete_field_spec.rb
+++ b/spec/ruby/library/openstruct/delete_field_spec.rb
@@ -8,12 +8,12 @@ describe "OpenStruct#delete_field" do
it "removes the named field from self's method/value table" do
@os.delete_field(:name)
- @os[:name].should be_nil
+ @os[:name].should == nil
end
it "does remove the accessor methods" do
@os.delete_field(:name)
- @os.respond_to?(:name).should be_false
- @os.respond_to?(:name=).should be_false
+ @os.respond_to?(:name).should == false
+ @os.respond_to?(:name=).should == false
end
end
diff --git a/spec/ruby/library/openstruct/equal_value_spec.rb b/spec/ruby/library/openstruct/equal_value_spec.rb
index 103ac13588..c72c09ce14 100644
--- a/spec/ruby/library/openstruct/equal_value_spec.rb
+++ b/spec/ruby/library/openstruct/equal_value_spec.rb
@@ -8,21 +8,21 @@ describe "OpenStruct#==" do
end
it "returns false when the passed argument is no OpenStruct" do
- (@os == Object.new).should be_false
- (@os == "Test").should be_false
- (@os == 10).should be_false
- (@os == :sym).should be_false
+ (@os == Object.new).should == false
+ (@os == "Test").should == false
+ (@os == 10).should == false
+ (@os == :sym).should == false
end
it "returns true when self and other are equal method/value wise" do
- (@os == @os).should be_true
- (@os == OpenStruct.new(name: "John")).should be_true
- (@os == OpenStructSpecs::OpenStructSub.new(name: "John")).should be_true
+ (@os == @os).should == true
+ (@os == OpenStruct.new(name: "John")).should == true
+ (@os == OpenStructSpecs::OpenStructSub.new(name: "John")).should == true
- (@os == OpenStruct.new(name: "Jonny")).should be_false
- (@os == OpenStructSpecs::OpenStructSub.new(name: "Jonny")).should be_false
+ (@os == OpenStruct.new(name: "Jonny")).should == false
+ (@os == OpenStructSpecs::OpenStructSub.new(name: "Jonny")).should == false
- (@os == OpenStruct.new(name: "John", age: 20)).should be_false
- (@os == OpenStructSpecs::OpenStructSub.new(name: "John", age: 20)).should be_false
+ (@os == OpenStruct.new(name: "John", age: 20)).should == false
+ (@os == OpenStructSpecs::OpenStructSub.new(name: "John", age: 20)).should == false
end
end
diff --git a/spec/ruby/library/openstruct/frozen_spec.rb b/spec/ruby/library/openstruct/frozen_spec.rb
index 142adcb278..c37fd18c8c 100644
--- a/spec/ruby/library/openstruct/frozen_spec.rb
+++ b/spec/ruby/library/openstruct/frozen_spec.rb
@@ -9,28 +9,30 @@ describe "OpenStruct.new when frozen" do
# method_missing case handled in method_missing_spec.rb
#
it "is still readable" do
- @os.age.should eql(70)
- @os.pension.should eql(300)
+ @os.age.should.eql?(70)
+ @os.pension.should.eql?(300)
@os.name.should == "John Smith"
end
it "is not writable" do
- lambda{ @os.age = 42 }.should raise_error( RuntimeError )
+ ->{ @os.age = 42 }.should.raise( RuntimeError )
end
it "cannot create new fields" do
- lambda{ @os.state = :new }.should raise_error( RuntimeError )
+ ->{ @os.state = :new }.should.raise( RuntimeError )
end
it "creates a frozen clone" do
f = @os.clone
+ f.frozen?.should == true
f.age.should == 70
- lambda{ f.age = 0 }.should raise_error( RuntimeError )
- lambda{ f.state = :newer }.should raise_error( RuntimeError )
+ ->{ f.age = 0 }.should.raise( RuntimeError )
+ ->{ f.state = :newer }.should.raise( RuntimeError )
end
it "creates an unfrozen dup" do
d = @os.dup
+ d.frozen?.should == false
d.age.should == 70
d.age = 42
d.age.should == 42
diff --git a/spec/ruby/library/openstruct/initialize_spec.rb b/spec/ruby/library/openstruct/initialize_spec.rb
index dee5de48c6..52304cf780 100644
--- a/spec/ruby/library/openstruct/initialize_spec.rb
+++ b/spec/ruby/library/openstruct/initialize_spec.rb
@@ -3,6 +3,6 @@ require 'ostruct'
describe "OpenStruct#initialize" do
it "is private" do
- OpenStruct.should have_private_instance_method(:initialize)
+ OpenStruct.private_instance_methods(false).should.include?(:initialize)
end
end
diff --git a/spec/ruby/library/openstruct/marshal_load_spec.rb b/spec/ruby/library/openstruct/marshal_load_spec.rb
index e07c4cef05..a8cdda3b43 100644
--- a/spec/ruby/library/openstruct/marshal_load_spec.rb
+++ b/spec/ruby/library/openstruct/marshal_load_spec.rb
@@ -4,9 +4,9 @@ require "ostruct"
describe "OpenStruct#marshal_load when passed [Hash]" do
it "defines methods based on the passed Hash" do
os = OpenStruct.new
- os.marshal_load(age: 20, name: "John")
+ os.send :marshal_load, age: 20, name: "John"
- os.age.should eql(20)
+ os.age.should.eql?(20)
os.name.should == "John"
end
end
diff --git a/spec/ruby/library/openstruct/method_missing_spec.rb b/spec/ruby/library/openstruct/method_missing_spec.rb
index eefe30661a..cf6734d629 100644
--- a/spec/ruby/library/openstruct/method_missing_spec.rb
+++ b/spec/ruby/library/openstruct/method_missing_spec.rb
@@ -7,41 +7,18 @@ describe "OpenStruct#method_missing when called with a method name ending in '='
end
it "raises an ArgumentError when not passed any additional arguments" do
- lambda { @os.method_missing(:test=) }.should raise_error(ArgumentError)
- end
-
- it "raises a TypeError when self is frozen" do
- @os.freeze
- lambda { @os.method_missing(:test=, "test") }.should raise_error(RuntimeError)
- end
-
- it "creates accessor methods" do
- @os.method_missing(:test=, "test")
- @os.respond_to?(:test=).should be_true
- @os.respond_to?(:test).should be_true
-
- @os.test.should == "test"
- @os.test = "changed"
- @os.test.should == "changed"
- end
-
- it "updates the method/value table with the passed method/value" do
- @os.method_missing(:test=, "test")
- @os.send(:table)[:test].should == "test"
+ -> { @os.send(:test=) }.should.raise(ArgumentError)
end
end
describe "OpenStruct#method_missing when passed additional arguments" do
- it "raises a NoMethodError" do
+ it "raises a NoMethodError when the key does not exist" do
os = OpenStruct.new
- lambda { os.method_missing(:test, 1, 2, 3) }.should raise_error(NoMethodError)
+ -> { os.test(1, 2, 3) }.should.raise(NoMethodError)
end
-end
-describe "OpenStruct#method_missing when not passed any additional arguments" do
- it "returns the value for the passed method from the method/value table" do
- os = OpenStruct.new(age: 20)
- os.method_missing(:age).should eql(20)
- os.method_missing(:name).should be_nil
+ it "raises an ArgumentError when the key exists" do
+ os = OpenStruct.new(test: 20)
+ -> { os.test(1, 2, 3) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/openstruct/new_spec.rb b/spec/ruby/library/openstruct/new_spec.rb
index 5d2cacea40..9e53948c82 100644
--- a/spec/ruby/library/openstruct/new_spec.rb
+++ b/spec/ruby/library/openstruct/new_spec.rb
@@ -7,8 +7,8 @@ describe "OpenStruct.new when passed [Hash]" do
end
it "creates an attribute for each key of the passed Hash" do
- @os.age.should eql(70)
- @os.pension.should eql(300)
+ @os.age.should.eql?(70)
+ @os.pension.should.eql?(300)
@os.name.should == "John Smith"
end
end
diff --git a/spec/ruby/library/openstruct/shared/inspect.rb b/spec/ruby/library/openstruct/shared/inspect.rb
index ffcd690e1f..d5fffa0e2e 100644
--- a/spec/ruby/library/openstruct/shared/inspect.rb
+++ b/spec/ruby/library/openstruct/shared/inspect.rb
@@ -4,7 +4,7 @@ describe :ostruct_inspect, shared: true do
os.send(@method).should == "#<OpenStruct name=\"John Smith\">"
os = OpenStruct.new(age: 20, name: "John Smith")
- os.send(@method).should be_kind_of(String)
+ os.send(@method).should.is_a?(String)
end
it "correctly handles self-referential OpenStructs" do
diff --git a/spec/ruby/library/openstruct/to_h_spec.rb b/spec/ruby/library/openstruct/to_h_spec.rb
index ebdec16174..7d9c7db5dc 100644
--- a/spec/ruby/library/openstruct/to_h_spec.rb
+++ b/spec/ruby/library/openstruct/to_h_spec.rb
@@ -19,7 +19,7 @@ describe "OpenStruct#to_h" do
end
it "does not return the hash used as initializer" do
- @to_h.should_not equal(@h)
+ @to_h.should_not.equal?(@h)
end
it "returns a Hash that is independent from the struct" do
@@ -27,44 +27,42 @@ describe "OpenStruct#to_h" do
@os.age.should == 70
end
- ruby_version_is "2.6" do
- context "with block" do
- it "converts [key, value] pairs returned by the block to a hash" do
- h = @os.to_h { |k, v| [k.to_s, v*2] }
- h.should == { "name" => "John SmithJohn Smith", "age" => 140, "pension" => 600 }
- end
+ context "with block" do
+ it "converts [key, value] pairs returned by the block to a hash" do
+ h = @os.to_h { |k, v| [k.to_s, v*2] }
+ h.should == { "name" => "John SmithJohn Smith", "age" => 140, "pension" => 600 }
+ end
- it "raises ArgumentError if block returns longer or shorter array" do
- -> do
- @os.to_h { |k, v| [k.to_s, v*2, 1] }
- end.should raise_error(ArgumentError, /element has wrong array length/)
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ @os.to_h { |k, v| [k.to_s, v*2, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
- -> do
- @os.to_h { |k, v| [k] }
- end.should raise_error(ArgumentError, /element has wrong array length/)
- end
+ -> do
+ @os.to_h { |k, v| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
- it "raises TypeError if block returns something other than Array" do
- -> do
- @os.to_h { |k, v| "not-array" }
- end.should raise_error(TypeError, /wrong element type String/)
- end
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ @os.to_h { |k, v| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
- it "coerces returned pair to Array with #to_ary" do
- x = mock('x')
- x.stub!(:to_ary).and_return([:b, 'b'])
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
- @os.to_h { |k| x }.should == { :b => 'b' }
- end
+ @os.to_h { |k| x }.should == { :b => 'b' }
+ end
- it "does not coerce returned pair to Array with #to_a" do
- x = mock('x')
- x.stub!(:to_a).and_return([:b, 'b'])
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
- -> do
- @os.to_h { |k| x }
- end.should raise_error(TypeError, /wrong element type MockObject/)
- end
+ -> do
+ @os.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
end
end
end