diff options
Diffstat (limited to 'spec/ruby/library/delegate')
29 files changed, 686 insertions, 0 deletions
diff --git a/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb new file mode 100644 index 0000000000..16bf8d734c --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb @@ -0,0 +1,52 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "DelegateClass.instance_method" do + before :all do + @klass = DelegateSpecs::DelegateClass + @obj = @klass.new(DelegateSpecs::Simple.new) + end + + it "returns a method object for public instance methods of the delegated class" do + m = @klass.instance_method(:pub) + m.should be_an_instance_of(UnboundMethod) + m.bind(@obj).call.should == :foo + end + + it "returns a method object for protected instance methods of the delegated class" do + m = @klass.instance_method(:prot) + m.should be_an_instance_of(UnboundMethod) + m.bind(@obj).call.should == :protected + end + + it "raises a NameError for a private instance methods of the delegated class" do + -> { + @klass.instance_method(:priv) + }.should raise_error(NameError) + end + + it "returns a method object for public instance methods of the DelegateClass class" do + m = @klass.instance_method(:extra) + m.should be_an_instance_of(UnboundMethod) + m.bind(@obj).call.should == :cheese + end + + it "returns a method object for protected instance methods of the DelegateClass class" do + m = @klass.instance_method(:extra_protected) + m.should be_an_instance_of(UnboundMethod) + m.bind(@obj).call.should == :baz + end + + it "returns a method object for private instance methods of the DelegateClass class" do + m = @klass.instance_method(:extra_private) + m.should be_an_instance_of(UnboundMethod) + m.bind(@obj).call.should == :bar + end + + it "raises a NameError for an invalid method name" do + -> { + @klass.instance_method(:invalid_and_silly_method_name) + }.should raise_error(NameError) + end + +end diff --git a/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb new file mode 100644 index 0000000000..6012ff72de --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb @@ -0,0 +1,26 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "DelegateClass.instance_methods" do + before :all do + @methods = DelegateSpecs::DelegateClass.instance_methods + end + + it "includes all public methods of the delegated class" do + @methods.should include :pub + end + + it "includes all protected methods of the delegated class" do + @methods.should include :prot + end + + it "includes instance methods of the DelegateClass 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 diff --git a/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb new file mode 100644 index 0000000000..06b2115cc5 --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb @@ -0,0 +1,23 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "DelegateClass.private_instance_methods" do + before :all do + @methods = DelegateSpecs::DelegateClass.private_instance_methods + end + + it "does not include any instance methods of the delegated class" do + @methods.should_not include :pub + @methods.should_not include :prot + @methods.should_not include :priv # since these are not forwarded... + end + + it "includes private instance methods of the DelegateClass class" do + @methods.should include :extra_private + end + + it "does not include public or protected instance methods of the DelegateClass class" do + @methods.should_not include :extra + @methods.should_not include :extra_protected + end +end diff --git a/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb new file mode 100644 index 0000000000..ac6659ec1e --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb @@ -0,0 +1,29 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "DelegateClass.protected_instance_methods" do + before :all do + @methods = DelegateSpecs::DelegateClass.protected_instance_methods + end + + it "does not include public methods of the delegated class" do + @methods.should_not include :pub + end + + it "includes the protected methods of the delegated class" do + @methods.should include :prot + end + + it "includes protected instance methods of the DelegateClass class" do + @methods.should include :extra_protected + end + + it "does not include public instance methods of the DelegateClass class" do + @methods.should_not include :extra + end + + it "does not include private methods" do + @methods.should_not include :priv + @methods.should_not include :extra_private + end +end diff --git a/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb new file mode 100644 index 0000000000..6c0d9bcab1 --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "DelegateClass.public_instance_methods" do + before :all do + @methods = DelegateSpecs::DelegateClass.public_instance_methods + end + + it "includes all public methods of the delegated class" do + @methods.should include :pub + end + + it "does not include the protected methods of the delegated class" do + @methods.should_not include :prot + end + + it "includes public instance methods of the DelegateClass class" do + @methods.should include :extra + end + + it "does not include private methods" do + @methods.should_not include :priv + @methods.should_not include :extra_private + end +end diff --git a/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb b/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb new file mode 100644 index 0000000000..3975e5208b --- /dev/null +++ b/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb @@ -0,0 +1,24 @@ +require_relative "../../../spec_helper" +require 'delegate' + +describe "DelegateClass#respond_to_missing?" do + it "is used for respond_to? behavior of late-bound delegated methods" do + # From jruby/jruby#3151: + # DelegateClass subtracts Delegate's public API from the target class's instance_methods + # to determine which methods to eagerly delegate. If respond_to_missing? shows up in + # instance_methods, it will get delegated and skip the delegate-aware implementation + # in Delegate. Any methods that must be delegated through method_missing, like methods + # defined after the DelegateClass is created, will fail to dispatch properly. + + cls = Class.new + dcls = DelegateClass(cls) + cdcls = Class.new(dcls) + cdcls_obj = cdcls.new(cls.new) + + cdcls_obj.respond_to?(:foo).should == false + + cls.class_eval { def foo; end } + + cdcls_obj.respond_to?(:foo).should == true + end +end diff --git a/spec/ruby/library/delegate/delegator/case_compare_spec.rb b/spec/ruby/library/delegate/delegator/case_compare_spec.rb new file mode 100644 index 0000000000..b62397cecf --- /dev/null +++ b/spec/ruby/library/delegate/delegator/case_compare_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/compare_spec.rb b/spec/ruby/library/delegate/delegator/compare_spec.rb new file mode 100644 index 0000000000..7dee5c2fb5 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/compare_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/complement_spec.rb b/spec/ruby/library/delegate/delegator/complement_spec.rb new file mode 100644 index 0000000000..10cb37c7ea --- /dev/null +++ b/spec/ruby/library/delegate/delegator/complement_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/eql_spec.rb b/spec/ruby/library/delegate/delegator/eql_spec.rb new file mode 100644 index 0000000000..34f56f44c9 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/eql_spec.rb @@ -0,0 +1,35 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "Delegator#eql?" 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 diff --git a/spec/ruby/library/delegate/delegator/equal_spec.rb b/spec/ruby/library/delegate/delegator/equal_spec.rb new file mode 100644 index 0000000000..c8711c74b5 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/equal_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/equal_value_spec.rb b/spec/ruby/library/delegate/delegator/equal_value_spec.rb new file mode 100644 index 0000000000..0c967d5f94 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/equal_value_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/frozen_spec.rb b/spec/ruby/library/delegate/delegator/frozen_spec.rb new file mode 100644 index 0000000000..b3145c54b1 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/frozen_spec.rb @@ -0,0 +1,39 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 writable" do + ->{ @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 + ->{ @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 diff --git a/spec/ruby/library/delegate/delegator/hash_spec.rb b/spec/ruby/library/delegate/delegator/hash_spec.rb new file mode 100644 index 0000000000..132cb91ccc --- /dev/null +++ b/spec/ruby/library/delegate/delegator/hash_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/marshal_spec.rb b/spec/ruby/library/delegate/delegator/marshal_spec.rb new file mode 100644 index 0000000000..6c75c8f573 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/marshal_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../../spec_helper' +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 diff --git a/spec/ruby/library/delegate/delegator/method_spec.rb b/spec/ruby/library/delegate/delegator/method_spec.rb new file mode 100644 index 0000000000..81c8eea710 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/method_spec.rb @@ -0,0 +1,69 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 + -> { + -> { + @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 + -> { + -> { + @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 + -> { + @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]) + -> { + m.call + }.should raise_error(NameError) + end +end diff --git a/spec/ruby/library/delegate/delegator/methods_spec.rb b/spec/ruby/library/delegate/delegator/methods_spec.rb new file mode 100644 index 0000000000..b9942bd230 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/methods_spec.rb @@ -0,0 +1,37 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/not_equal_spec.rb b/spec/ruby/library/delegate/delegator/not_equal_spec.rb new file mode 100644 index 0000000000..6f2df21715 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/not_equal_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/not_spec.rb b/spec/ruby/library/delegate/delegator/not_spec.rb new file mode 100644 index 0000000000..50105181c3 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/not_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/private_methods_spec.rb b/spec/ruby/library/delegate/delegator/private_methods_spec.rb new file mode 100644 index 0000000000..7724b8d413 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/private_methods_spec.rb @@ -0,0 +1,20 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/protected_methods_spec.rb b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb new file mode 100644 index 0000000000..fd7874fb21 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb @@ -0,0 +1,18 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/public_methods_spec.rb b/spec/ruby/library/delegate/delegator/public_methods_spec.rb new file mode 100644 index 0000000000..18da16a613 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/public_methods_spec.rb @@ -0,0 +1,18 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/send_spec.rb b/spec/ruby/library/delegate/delegator/send_spec.rb new file mode 100644 index 0000000000..3022c2ce91 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/send_spec.rb @@ -0,0 +1,26 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 + ->{ @delegate.prot }.should raise_error( NoMethodError ) + end + + it "doesn't forward private method calls" do + ->{ @delegate.priv }.should raise_error( NoMethodError ) + end + + it "doesn't forward private method calls even via send or __send__" do + ->{ @delegate.send(:priv, 42) }.should raise_error( NoMethodError ) + ->{ @delegate.__send__(:priv, 42) }.should raise_error( NoMethodError ) + end +end diff --git a/spec/ruby/library/delegate/delegator/taint_spec.rb b/spec/ruby/library/delegate/delegator/taint_spec.rb new file mode 100644 index 0000000000..6bf13bb73d --- /dev/null +++ b/spec/ruby/library/delegate/delegator/taint_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "Delegator#taint" do + before :each do + @delegate = DelegateSpecs::Delegator.new("") + end +end diff --git a/spec/ruby/library/delegate/delegator/tap_spec.rb b/spec/ruby/library/delegate/delegator/tap_spec.rb new file mode 100644 index 0000000000..34a88fa1d5 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/tap_spec.rb @@ -0,0 +1,16 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +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 diff --git a/spec/ruby/library/delegate/delegator/trust_spec.rb b/spec/ruby/library/delegate/delegator/trust_spec.rb new file mode 100644 index 0000000000..f1b81814c5 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/trust_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "Delegator#trust" do + before :each do + @delegate = DelegateSpecs::Delegator.new([]) + end +end diff --git a/spec/ruby/library/delegate/delegator/untaint_spec.rb b/spec/ruby/library/delegate/delegator/untaint_spec.rb new file mode 100644 index 0000000000..4051fd2629 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/untaint_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "Delegator#untaint" do + before :each do + @delegate = -> { DelegateSpecs::Delegator.new("") }.call + end +end diff --git a/spec/ruby/library/delegate/delegator/untrust_spec.rb b/spec/ruby/library/delegate/delegator/untrust_spec.rb new file mode 100644 index 0000000000..4f7fa1e582 --- /dev/null +++ b/spec/ruby/library/delegate/delegator/untrust_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../../spec_helper' +require_relative '../fixtures/classes' + +describe "Delegator#untrust" do + before :each do + @delegate = DelegateSpecs::Delegator.new("") + end +end diff --git a/spec/ruby/library/delegate/fixtures/classes.rb b/spec/ruby/library/delegate/fixtures/classes.rb new file mode 100644 index 0000000000..3cb43eb8b1 --- /dev/null +++ b/spec/ruby/library/delegate/fixtures/classes.rb @@ -0,0 +1,60 @@ +require 'delegate' +module DelegateSpecs + class Simple + def pub + :foo + end + + def respond_to_missing?(method, priv=false) + method == :pub_too || + (priv && method == :priv_too) + end + + def method_missing(method, *args) + super unless respond_to_missing?(method, true) + method + end + + def priv(arg=nil) + yield arg if block_given? + [:priv, arg] + end + private :priv + + def prot + :protected + end + protected :prot + end + + module Extra + def extra + :cheese + end + + def extra_private + :bar + end + private :extra_private + + def extra_protected + :baz + end + protected :extra_protected + end + + class Delegator < ::Delegator + attr_accessor :data + + attr_reader :__getobj__ + def __setobj__(o) + @__getobj__ = o + end + + include Extra + end + + class DelegateClass < DelegateClass(Simple) + include Extra + end +end |
