1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,11 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#===" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:===).with(42).and_return(:foo)
(delegator === 42).should == :foo
end
end

View file

@ -0,0 +1,11 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#<=>" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:<=>).with(42).and_return(1)
(delegator <=> 42).should == 1
end
end

View file

@ -0,0 +1,11 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#~" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:~).and_return(:foo)
(~delegator).should == :foo
end
end

View file

@ -0,0 +1,46 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#eql?" do
ruby_version_is ""..."2.5" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:eql?).with(42).and_return(:foo)
delegator.eql?(42).should == :foo
end
end
ruby_version_is "2.5" do
it "returns true when compared with same delegator" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
delegator.eql?(delegator).should be_true
end
it "returns true when compared with the inner object" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
delegator.eql?(base).should be_true
end
it "returns false when compared with the delegator with other object" do
base = mock('base')
other = mock('other')
delegator0 = DelegateSpecs::Delegator.new(base)
delegator1 = DelegateSpecs::Delegator.new(other)
delegator0.eql?(delegator1).should be_false
end
it "returns false when compared with the other object" do
base = mock('base')
other = mock('other')
delegator = DelegateSpecs::Delegator.new(base)
delegator.eql?(other).should be_false
end
end
end

View file

@ -0,0 +1,13 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#equal?" do
it "returns true only when compared with the delegator" do
obj = mock('base')
delegator = DelegateSpecs::Delegator.new(obj)
obj.should_not_receive(:equal?)
delegator.equal?(obj).should be_false
delegator.equal?(nil).should be_false
delegator.equal?(delegator).should be_true
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#==" do
before :all do
@base = mock('base')
@delegator = DelegateSpecs::Delegator.new(@base)
end
it "is not delegated when passed self" do
@base.should_not_receive(:==)
(@delegator == @delegator).should be_true
end
it "is delegated when passed the delegated object" do
@base.should_receive(:==).and_return(false)
(@delegator == @base).should be_false
end
it "is delegated in general" do
@base.should_receive(:==).and_return(true)
(@delegator == 42).should be_true
end
end

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator when frozen" do
before :all do
@array = [42, :hello]
@delegate = DelegateSpecs::Delegator.new(@array)
@delegate.freeze
end
it "is still readable" do
@delegate.should == [42, :hello]
@delegate.include?("bar").should be_false
end
it "is frozen" do
@delegate.frozen?.should be_true
end
it "is not writeable" do
lambda{ @delegate[0] += 2 }.should raise_error( RuntimeError )
end
it "creates a frozen clone" do
@delegate.clone.frozen?.should be_true
end
it "creates an unfrozen dup" do
@delegate.dup.frozen?.should be_false
end
it "causes mutative calls to raise RuntimeError" do
lambda{ @delegate.__setobj__("hola!") }.should raise_error( RuntimeError )
end
it "returns false if only the delegated object is frozen" do
DelegateSpecs::Delegator.new([1,2,3].freeze).frozen?.should be_false
end
end

View file

@ -0,0 +1,11 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#hash" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:hash).and_return(42)
delegator.hash.should == 42
end
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'delegate'
describe "SimpleDelegator" do
before :all do
@obj = "hello"
@delegate = SimpleDelegator.new(@obj)
end
it "can be marshalled" do
m = Marshal.load(Marshal.dump(@delegate))
m.class.should == SimpleDelegator
(m == @obj).should be_true
end
it "can be marshalled with its instance variables intact" do
@delegate.instance_variable_set(:@foo, "bar")
m = Marshal.load(Marshal.dump(@delegate))
m.instance_variable_get(:@foo).should == "bar"
end
end

View file

@ -0,0 +1,69 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#method" do
before :each do
@simple = DelegateSpecs::Simple.new
@delegate = DelegateSpecs::Delegator.new(@simple)
end
it "returns a method object for public methods of the delegate object" do
m = @delegate.method(:pub)
m.should be_an_instance_of(Method)
m.call.should == :foo
end
it "raises a NameError for protected methods of the delegate object" do
lambda {
-> {
@delegate.method(:prot)
}.should complain(/delegator does not forward private method #prot/)
}.should raise_error(NameError)
end
it "raises a NameError for a private methods of the delegate object" do
lambda {
-> {
@delegate.method(:priv)
}.should complain(/delegator does not forward private method #priv/)
}.should raise_error(NameError)
end
it "returns a method object for public methods of the Delegator class" do
m = @delegate.method(:extra)
m.should be_an_instance_of(Method)
m.call.should == :cheese
end
it "returns a method object for protected methods of the Delegator class" do
m = @delegate.method(:extra_protected)
m.should be_an_instance_of(Method)
m.call.should == :baz
end
it "returns a method object for private methods of the Delegator class" do
m = @delegate.method(:extra_private)
m.should be_an_instance_of(Method)
m.call.should == :bar
end
it "raises a NameError for an invalid method name" do
lambda {
@delegate.method(:invalid_and_silly_method_name)
}.should raise_error(NameError)
end
it "returns a method that respond_to_missing?" do
m = @delegate.method(:pub_too)
m.should be_an_instance_of(Method)
m.call.should == :pub_too
end
it "raises a NameError if method is no longer valid because object has changed" do
m = @delegate.method(:pub)
@delegate.__setobj__([1,2,3])
lambda {
m.call
}.should raise_error(NameError)
end
end

View file

@ -0,0 +1,37 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#methods" do
before :all do
@simple = DelegateSpecs::Simple.new
class << @simple
def singleton_method
end
end
@delegate = DelegateSpecs::Delegator.new(@simple)
@methods = @delegate.methods
end
it "returns singleton methods when passed false" do
@delegate.methods(false).should include(:singleton_method)
end
it "includes all public methods of the delegate object" do
@methods.should include :pub
end
it "includes all protected methods of the delegate object" do
@methods.should include :prot
end
it "includes instance methods of the Delegator class" do
@methods.should include :extra
@methods.should include :extra_protected
end
it "does not include private methods" do
@methods.should_not include :priv
@methods.should_not include :extra_private
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#!=" do
before :all do
@base = mock('base')
@delegator = DelegateSpecs::Delegator.new(@base)
end
it "is not delegated when passed self" do
@base.should_not_receive(:"!=")
(@delegator != @delegator).should be_false
end
it "is delegated when passed the delegated object" do
@base.should_receive(:"!=").and_return(true)
(@delegator != @base).should be_true
end
it "is delegated in general" do
@base.should_receive(:"!=").and_return(false)
(@delegator != 42).should be_false
end
end

View file

@ -0,0 +1,11 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#!" do
it "is delegated" do
base = mock('base')
delegator = DelegateSpecs::Delegator.new(base)
base.should_receive(:"!").and_return(:foo)
(!delegator).should == :foo
end
end

View file

@ -0,0 +1,20 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#private_methods" do
before :all do
@simple = DelegateSpecs::Simple.new
@delegate = DelegateSpecs::Delegator.new(@simple)
@methods = @delegate.private_methods
end
it "does not include any method of the delegate object" do # since delegates does not forward private calls
@methods.should_not include :priv
@methods.should_not include :prot
@methods.should_not include :pub
end
it "includes all private instance methods of the Delegate class" do
@methods.should include :extra_private
end
end

View file

@ -0,0 +1,18 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#protected_methods" do
before :all do
@simple = DelegateSpecs::Simple.new
@delegate = DelegateSpecs::Delegator.new(@simple)
@methods = @delegate.protected_methods
end
it "includes protected methods of the delegate object" do
@methods.should include :prot
end
it "includes protected instance methods of the Delegator class" do
@methods.should include :extra_protected
end
end

View file

@ -0,0 +1,18 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#public_methods" do
before :all do
@simple = DelegateSpecs::Simple.new
@delegate = DelegateSpecs::Delegator.new(@simple)
@methods = @delegate.public_methods
end
it "includes public methods of the delegate object" do
@methods.should include :pub
end
it "includes public instance methods of the Delegator class" do
@methods.should include :extra
end
end

View file

@ -0,0 +1,26 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "SimpleDelegator.new" do
before :all do
@simple = DelegateSpecs::Simple.new
@delegate = SimpleDelegator.new(@simple)
end
it "forwards public method calls" do
@delegate.pub.should == :foo
end
it "forwards protected method calls" do
lambda{ @delegate.prot }.should raise_error( NoMethodError )
end
it "doesn't forward private method calls" do
lambda{ @delegate.priv }.should raise_error( NoMethodError )
end
it "doesn't forward private method calls even via send or __send__" do
lambda{ @delegate.send(:priv, 42) }.should raise_error( NoMethodError )
lambda{ @delegate.__send__(:priv, 42) }.should raise_error( NoMethodError )
end
end

View file

@ -0,0 +1,23 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#taint" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
it "returns self" do
@delegate.taint.equal?(@delegate).should be_true
end
it "taints the delegator" do
@delegate.__setobj__(nil)
@delegate.taint
@delegate.tainted?.should be_true
end
it "taints the delegated object" do
@delegate.taint
@delegate.__getobj__.tainted?.should be_true
end
end

View file

@ -0,0 +1,16 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#tap" do
it "yield the delegator object" do
obj = mock('base')
delegator = DelegateSpecs::Delegator.new(obj)
obj.should_not_receive(:tap)
yielded = []
delegator.tap do |x|
yielded << x
end
yielded.size.should == 1
yielded[0].equal?(delegator).should be_true
end
end

View file

@ -0,0 +1,22 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#trust" do
before :each do
@delegate = DelegateSpecs::Delegator.new([])
end
it "returns self" do
@delegate.trust.equal?(@delegate).should be_true
end
it "trusts the delegator" do
@delegate.trust
@delegate.untrusted?.should be_false
end
it "trusts the delegated object" do
@delegate.trust
@delegate.__getobj__.untrusted?.should be_false
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#untaint" do
before :each do
@delegate = lambda { DelegateSpecs::Delegator.new("") }.call
end
it "returns self" do
@delegate.untaint.equal?(@delegate).should be_true
end
it "untaints the delegator" do
@delegate.untaint
@delegate.tainted?.should be_false
# No additional meaningful test; that it does or not taint
# "for real" the delegator has no consequence
end
it "untaints the delegated object" do
@delegate.untaint
@delegate.__getobj__.tainted?.should be_false
end
end

View file

@ -0,0 +1,23 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Delegator#untrust" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
it "returns self" do
@delegate.untrust.equal?(@delegate).should be_true
end
it "untrusts the delegator" do
@delegate.__setobj__(nil)
@delegate.untrust
@delegate.untrusted?.should be_true
end
it "untrusts the delegated object" do
@delegate.untrust
@delegate.__getobj__.untrusted?.should be_true
end
end