diff options
Diffstat (limited to 'spec/ruby/library/weakref')
| -rw-r--r-- | spec/ruby/library/weakref/__getobj___spec.rb | 10 | ||||
| -rw-r--r-- | spec/ruby/library/weakref/allocate_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/weakref/fixtures/classes.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/weakref/new_spec.rb | 13 | ||||
| -rw-r--r-- | spec/ruby/library/weakref/send_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/weakref/weakref_alive_spec.rb | 8 |
6 files changed, 37 insertions, 14 deletions
diff --git a/spec/ruby/library/weakref/__getobj___spec.rb b/spec/ruby/library/weakref/__getobj___spec.rb index e75b8f4704..fa507384c2 100644 --- a/spec/ruby/library/weakref/__getobj___spec.rb +++ b/spec/ruby/library/weakref/__getobj___spec.rb @@ -1,17 +1,17 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "WeakRef#__getobj__" do it "returns the object if it is reachable" do obj = Object.new ref = WeakRef.new(obj) - ref.__getobj__.should equal(obj) + ref.__getobj__.should.equal?(obj) end it "raises WeakRef::RefError if the object is no longer reachable" do ref = WeakRefSpec.make_dead_weakref - lambda { + -> { ref.__getobj__ - }.should raise_error(WeakRef::RefError) + }.should.raise(WeakRef::RefError) end end diff --git a/spec/ruby/library/weakref/allocate_spec.rb b/spec/ruby/library/weakref/allocate_spec.rb new file mode 100644 index 0000000000..0438d093c4 --- /dev/null +++ b/spec/ruby/library/weakref/allocate_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require 'weakref' + +describe "WeakRef#allocate" do + it "assigns nil as the reference" do + -> { WeakRef.allocate.__getobj__ }.should.raise(WeakRef::RefError) + end +end diff --git a/spec/ruby/library/weakref/fixtures/classes.rb b/spec/ruby/library/weakref/fixtures/classes.rb index 560c58b041..041afab14d 100644 --- a/spec/ruby/library/weakref/fixtures/classes.rb +++ b/spec/ruby/library/weakref/fixtures/classes.rb @@ -13,9 +13,11 @@ class WeakRefSpec def self.make_dead_weakref weaks = [] weak = nil - 10_000.times do + 1000.times do weaks << make_weakref - GC.start + end + + 1000.times do GC.start break if weak = weaks.find { |w| !w.weakref_alive? } end diff --git a/spec/ruby/library/weakref/new_spec.rb b/spec/ruby/library/weakref/new_spec.rb new file mode 100644 index 0000000000..6290e61fe3 --- /dev/null +++ b/spec/ruby/library/weakref/new_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../spec_helper' +require 'weakref' + +describe "WeakRef#new" do + it "creates a subclass correctly" do + wr2 = Class.new(WeakRef) { + def __getobj__ + :dummy + end + } + wr2.new(Object.new).__getobj__.should == :dummy + end +end diff --git a/spec/ruby/library/weakref/send_spec.rb b/spec/ruby/library/weakref/send_spec.rb index 173e1055dd..da8660066f 100644 --- a/spec/ruby/library/weakref/send_spec.rb +++ b/spec/ruby/library/weakref/send_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'weakref' describe "WeakRef#__send__" do @@ -27,11 +27,11 @@ describe "WeakRef#__send__" do it "delegates to protected methods of the weakly-referenced object" do wr = WeakRef.new(WeakRefSpecs) - lambda { wr.protected_method }.should raise_error(NameError) + -> { wr.protected_method }.should.raise(NameError) end it "does not delegate to private methods of the weakly-referenced object" do wr = WeakRef.new(WeakRefSpecs) - lambda { wr.private_method }.should raise_error(NameError) + -> { wr.private_method }.should.raise(NameError) end end diff --git a/spec/ruby/library/weakref/weakref_alive_spec.rb b/spec/ruby/library/weakref/weakref_alive_spec.rb index b3c2eab620..1b12ffbbec 100644 --- a/spec/ruby/library/weakref/weakref_alive_spec.rb +++ b/spec/ruby/library/weakref/weakref_alive_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "WeakRef#weakref_alive?" do it "returns true if the object is reachable" do @@ -8,8 +8,8 @@ describe "WeakRef#weakref_alive?" do ref.weakref_alive?.should == true end - it "returns a falsey value if the object is no longer reachable" do + it "returns a falsy value if the object is no longer reachable" do ref = WeakRefSpec.make_dead_weakref - [false, nil].should include(ref.weakref_alive?) + [false, nil].should.include?(ref.weakref_alive?) end end |
