This is not a big deal, but DelegateClass fails with rspec when methods
are defined in the the delegating class. Here''s code that
demonstrates:
require ''delegate''
gem ''rspec''
# Version 1.0.5
############################################################
# CONTROL EXAMPLE: Works FINE.
############################################################
class InheritedClass < Array
def large?
self.size >= 5
end
end
describe InheritedClass, "normal inheriting class is OK" do
it ''works just fine'' do
myclass = InheritedClass.new([1,2,3,4,5,6])
myclass.should be_large
end
end
############################################################
# rspec should work on DelegateClasses. Not sure how...
############################################################
class DelegateKlass < DelegateClass(Array)
def initialize(array)
@internal_array = array
super(@internal_array)
end
def large?
@internal_array.size >= 5
end
end
=begin
# will work if this code is available.
class Array
def large?
self.size >= 5
end
end
=end
describe DelegateKlass, "delegate class fails" do
it ''does not work on methods defined within the delegating
class'' do
myclass = DelegateKlass.new([1,2,3,4,5,6])
myclass.should be_large
end
end
--JTP
On 6/11/07, John Prince <jtprince at gmail.com> wrote:> This is not a big deal, but DelegateClass fails with rspec when methods > are defined in the the delegating class. Here''s code that demonstrates: > > require ''delegate'' > gem ''rspec'' > # Version 1.0.5 > > ############################################################ > # CONTROL EXAMPLE: Works FINE. > ############################################################ > class InheritedClass < Array > def large? > self.size >= 5 > end > end > > describe InheritedClass, "normal inheriting class is OK" do > it ''works just fine'' do > myclass = InheritedClass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > ############################################################ > # rspec should work on DelegateClasses. Not sure how... > ############################################################ > > class DelegateKlass < DelegateClass(Array) > > def initialize(array) > @internal_array = array > super(@internal_array) > end > > def large? > @internal_array.size >= 5 > end > > end > > =begin > # will work if this code is available. > class Array > def large? > self.size >= 5 > end > end > =end > > > describe DelegateKlass, "delegate class fails" do > it ''does not work on methods defined within the delegating class'' do > myclass = DelegateKlass.new([1,2,3,4,5,6]) > myclass.should be_large > end > endWhat''s the error message?> > > --JTP > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Please submit a failing spec On 6/11/07, John Prince <jtprince at gmail.com> wrote:> This is not a big deal, but DelegateClass fails with rspec when methods > are defined in the the delegating class. Here''s code that demonstrates: > > require ''delegate'' > gem ''rspec'' > # Version 1.0.5 > > ############################################################ > # CONTROL EXAMPLE: Works FINE. > ############################################################ > class InheritedClass < Array > def large? > self.size >= 5 > end > end > > describe InheritedClass, "normal inheriting class is OK" do > it ''works just fine'' do > myclass = InheritedClass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > ############################################################ > # rspec should work on DelegateClasses. Not sure how... > ############################################################ > > class DelegateKlass < DelegateClass(Array) > > def initialize(array) > @internal_array = array > super(@internal_array) > end > > def large? > @internal_array.size >= 5 > end > > end > > =begin > # will work if this code is available. > class Array > def large? > self.size >= 5 > end > end > =end > > > describe DelegateKlass, "delegate class fails" do > it ''does not work on methods defined within the delegating class'' do > myclass = DelegateKlass.new([1,2,3,4,5,6]) > myclass.should be_large > end > end > > > --JTP > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >