summaryrefslogtreecommitdiff
path: root/spec/ruby/library/objectspace
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/objectspace')
-rw-r--r--spec/ruby/library/objectspace/dump_all_spec.rb4
-rw-r--r--spec/ruby/library/objectspace/dump_spec.rb22
-rw-r--r--spec/ruby/library/objectspace/fixtures/trace.rb1
-rw-r--r--spec/ruby/library/objectspace/memsize_of_all_spec.rb4
-rw-r--r--spec/ruby/library/objectspace/memsize_of_spec.rb4
-rw-r--r--spec/ruby/library/objectspace/reachable_objects_from_spec.rb14
-rw-r--r--spec/ruby/library/objectspace/trace_object_allocations_spec.rb34
-rw-r--r--spec/ruby/library/objectspace/trace_spec.rb20
8 files changed, 57 insertions, 46 deletions
diff --git a/spec/ruby/library/objectspace/dump_all_spec.rb b/spec/ruby/library/objectspace/dump_all_spec.rb
index e9b449a905..c92812ebd5 100644
--- a/spec/ruby/library/objectspace/dump_all_spec.rb
+++ b/spec/ruby/library/objectspace/dump_all_spec.rb
@@ -82,7 +82,7 @@ describe "ObjectSpace.dump_all" do
ObjectSpace.dump_all(output: :stdout)
RUBY
- stdout.should include('"value":"abc"')
+ stdout.should.include?('"value":"abc"')
end
it "dumps Ruby heap to provided IO when passed output: IO" do
@@ -107,6 +107,6 @@ describe "ObjectSpace.dump_all" do
end
it "raises ArgumentError when passed not supported :output value" do
- -> { ObjectSpace.dump_all(output: Object.new) }.should raise_error(ArgumentError, /wrong output option/)
+ -> { ObjectSpace.dump_all(output: Object.new) }.should.raise(ArgumentError, /wrong output option/)
end
end
diff --git a/spec/ruby/library/objectspace/dump_spec.rb b/spec/ruby/library/objectspace/dump_spec.rb
index e22ee3df1e..4b5e0da198 100644
--- a/spec/ruby/library/objectspace/dump_spec.rb
+++ b/spec/ruby/library/objectspace/dump_spec.rb
@@ -13,23 +13,23 @@ describe "ObjectSpace.dump" do
it "dumps to string when passed output: :string" do
string = ObjectSpace.dump("abc", output: :string)
- string.should be_kind_of(String)
- string.should include('"value":"abc"')
+ string.should.is_a?(String)
+ string.should.include?('"value":"abc"')
end
it "dumps to string when :output not specified" do
string = ObjectSpace.dump("abc")
- string.should be_kind_of(String)
- string.should include('"value":"abc"')
+ string.should.is_a?(String)
+ string.should.include?('"value":"abc"')
end
it "dumps to a temporary file when passed output: :file" do
file = ObjectSpace.dump("abc", output: :file)
- file.should be_kind_of(File)
+ file.should.is_a?(File)
file.rewind
content = file.read
- content.should include('"value":"abc"')
+ content.should.include?('"value":"abc"')
ensure
file.close
File.unlink file.path
@@ -37,10 +37,10 @@ describe "ObjectSpace.dump" do
it "dumps to a temporary file when passed output: :nil" do
file = ObjectSpace.dump("abc", output: nil)
- file.should be_kind_of(File)
+ file.should.is_a?(File)
file.rewind
- file.read.should include('"value":"abc"')
+ file.read.should.include?('"value":"abc"')
ensure
file.close
File.unlink file.path
@@ -48,7 +48,7 @@ describe "ObjectSpace.dump" do
it "dumps to stdout when passed output: :stdout" do
stdout = ruby_exe('ObjectSpace.dump("abc", output: :stdout)', options: "-robjspace").chomp
- stdout.should include('"value":"abc"')
+ stdout.should.include?('"value":"abc"')
end
it "dumps to provided IO when passed output: IO" do
@@ -58,13 +58,13 @@ describe "ObjectSpace.dump" do
result.should.equal? io
io.rewind
- io.read.should include('"value":"abc"')
+ io.read.should.include?('"value":"abc"')
ensure
io.close
rm_r filename
end
it "raises ArgumentError when passed not supported :output value" do
- -> { ObjectSpace.dump("abc", output: Object.new) }.should raise_error(ArgumentError, /wrong output option/)
+ -> { ObjectSpace.dump("abc", output: Object.new) }.should.raise(ArgumentError, /wrong output option/)
end
end
diff --git a/spec/ruby/library/objectspace/fixtures/trace.rb b/spec/ruby/library/objectspace/fixtures/trace.rb
index fd4524b0ba..e53a7a0cac 100644
--- a/spec/ruby/library/objectspace/fixtures/trace.rb
+++ b/spec/ruby/library/objectspace/fixtures/trace.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: false
require "objspace/trace"
a = "foo"
b = "b" + "a" + "r"
diff --git a/spec/ruby/library/objectspace/memsize_of_all_spec.rb b/spec/ruby/library/objectspace/memsize_of_all_spec.rb
index c5a48165ce..9fc6e8be9d 100644
--- a/spec/ruby/library/objectspace/memsize_of_all_spec.rb
+++ b/spec/ruby/library/objectspace/memsize_of_all_spec.rb
@@ -3,12 +3,12 @@ require 'objspace'
describe "ObjectSpace.memsize_of_all" do
it "returns a non-zero Integer for all objects" do
- ObjectSpace.memsize_of_all.should be_kind_of(Integer)
+ ObjectSpace.memsize_of_all.should.is_a?(Integer)
ObjectSpace.memsize_of_all.should > 0
end
it "returns a non-zero Integer for Class" do
- ObjectSpace.memsize_of_all(Class).should be_kind_of(Integer)
+ ObjectSpace.memsize_of_all(Class).should.is_a?(Integer)
ObjectSpace.memsize_of_all(Class).should > 0
end
diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb
index eefafbb334..9c8aea4e84 100644
--- a/spec/ruby/library/objectspace/memsize_of_spec.rb
+++ b/spec/ruby/library/objectspace/memsize_of_spec.rb
@@ -13,12 +13,12 @@ describe "ObjectSpace.memsize_of" do
end
it "returns 0 for literal Symbols" do
- ObjectSpace.memsize_of(:abc).should == 0
+ ObjectSpace.memsize_of(:object_space_memsize_spec_static_sym).should == 0
end
it "returns a positive Integer for an Object" do
obj = Object.new
- ObjectSpace.memsize_of(obj).should be_kind_of(Integer)
+ ObjectSpace.memsize_of(obj).should.is_a?(Integer)
ObjectSpace.memsize_of(obj).should > 0
end
diff --git a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb
index 7e70bc8569..4620bdec31 100644
--- a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb
+++ b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb
@@ -16,7 +16,7 @@ describe "ObjectSpace.reachable_objects_from" do
end
it "enumerates objects directly reachable from a given object" do
- ObjectSpace.reachable_objects_from(['a', 'b', 'c']).should include(Array, 'a', 'b', 'c')
+ ObjectSpace.reachable_objects_from(['a', 'b', 'c']).to_set.should >= Set[Array, 'a', 'b', 'c']
ObjectSpace.reachable_objects_from(Object.new).should == [Object]
end
@@ -24,7 +24,7 @@ describe "ObjectSpace.reachable_objects_from" do
obj = Object.new
ary = [obj]
reachable = ObjectSpace.reachable_objects_from(ary)
- reachable.should include(obj)
+ reachable.should.include?(obj)
end
it "finds an object stored in a copy-on-write Array" do
@@ -33,29 +33,27 @@ describe "ObjectSpace.reachable_objects_from" do
ary = [removed, obj]
ary.shift
reachable = ObjectSpace.reachable_objects_from(ary)
- reachable.should include(obj)
- reachable.should_not include(removed)
+ reachable.should.include?(obj)
+ reachable.should_not.include?(removed)
end
it "finds an object stored in a Queue" do
- require 'thread'
o = Object.new
q = Queue.new
q << o
reachable = ObjectSpace.reachable_objects_from(q)
reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) }
- reachable.should include(o)
+ reachable.should.include?(o)
end
it "finds an object stored in a SizedQueue" do
- require 'thread'
o = Object.new
q = SizedQueue.new(3)
q << o
reachable = ObjectSpace.reachable_objects_from(q)
reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) }
- reachable.should include(o)
+ reachable.should.include?(o)
end
end
diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
index 612430e067..0bb6efbfa5 100644
--- a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
+++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
@@ -2,6 +2,20 @@ require_relative '../../spec_helper'
require 'objspace'
describe "ObjectSpace.trace_object_allocations" do
+ def has_class_frame?
+ Class.new {
+ attr_reader :c
+
+ def initialize
+ @c = caller_locations.first.label =~ /new/
+ end
+ }.new.c
+ end
+
+ def obj_class_path
+ has_class_frame? ? "Class" : nil
+ end
+
it "runs a block" do
ScratchPad.clear
ObjectSpace.trace_object_allocations do
@@ -13,7 +27,7 @@ describe "ObjectSpace.trace_object_allocations" do
it "records info for allocation_class_path" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
a = [1, 2, 3]
ObjectSpace.allocation_class_path(a).should == nil
end
@@ -31,7 +45,7 @@ describe "ObjectSpace.trace_object_allocations" do
it "records info for allocation_method_id" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_method_id(o).should == :new
+ ObjectSpace.allocation_method_id(o).should == (has_class_frame? ? :new : nil)
a = [1, 2, 3]
ObjectSpace.allocation_method_id(a).should == nil
end
@@ -58,9 +72,9 @@ describe "ObjectSpace.trace_object_allocations" do
it "can be cleared using trace_object_allocations_clear" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ObjectSpace.trace_object_allocations_clear
- ObjectSpace.allocation_class_path(o).should be_nil
+ ObjectSpace.allocation_class_path(o).should == nil
end
end
@@ -69,14 +83,14 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations do
o = Object.new
end
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
it "can be used without a block using trace_object_allocations_start and _stop" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
a = [1, 2, 3]
ObjectSpace.allocation_class_path(a).should == nil
ensure
@@ -91,14 +105,14 @@ describe "ObjectSpace.trace_object_allocations" do
ensure
ObjectSpace.trace_object_allocations_stop
end
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
it "can be nested" do
ObjectSpace.trace_object_allocations do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
end
end
@@ -109,7 +123,7 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ensure
ObjectSpace.trace_object_allocations_stop
end
@@ -122,7 +136,7 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ObjectSpace.trace_object_allocations_stop
ensure
ObjectSpace.trace_object_allocations_stop
diff --git a/spec/ruby/library/objectspace/trace_spec.rb b/spec/ruby/library/objectspace/trace_spec.rb
index 59952a006c..3957dc930d 100644
--- a/spec/ruby/library/objectspace/trace_spec.rb
+++ b/spec/ruby/library/objectspace/trace_spec.rb
@@ -1,15 +1,13 @@
require_relative '../../spec_helper'
-ruby_version_is "3.1" do
- describe 'require "objspace/trace"' do
- it "shows object allocation sites" do
- file = fixture(__FILE__ , "trace.rb")
- ruby_exe(file, args: "2>&1").lines(chomp: true).should == [
- "objspace/trace is enabled",
- "\"foo\" @ #{file}:2",
- "\"bar\" @ #{file}:3",
- "42"
- ]
- end
+describe 'require "objspace/trace"' do
+ it "shows object allocation sites" do
+ file = fixture(__FILE__ , "trace.rb")
+ ruby_exe(file, args: "2>&1").lines(chomp: true).should == [
+ "objspace/trace is enabled",
+ "\"foo\" @ #{file}:3",
+ "\"bar\" @ #{file}:4",
+ "42"
+ ]
end
end