Scott Taylor
2007-Feb-24 10:21 UTC
[rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?]
I have a spec which is failing, but I just can''t say why. Maybe I''m missing something painfully obvious? Here is the pastie of the results & the spec: http://pastie.caboo.se/42626 The spec to look for is "should have an array of users" I''ve printed out ("puts''ed") to the terminal the fact that the values are *opposite* to what the spec fails on... Thanks, all, for your help, Best Regards, Scott Taylor P.S. In the future shall I just plop in a bunch of code to my message, or is pastie a good means for delivering somewhat large chunks of code?
David Chelimsky
2007-Feb-24 15:07 UTC
[rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?]
On 2/24/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > I have a spec which is failing, but I just can''t say why. Maybe I''m > missing something painfully obvious? > > Here is the pastie of the results & the spec: > > http://pastie.caboo.se/42626 > > The spec to look for is "should have an array of users" I''ve printed > out ("puts''ed") to the terminal the fact that the values are > *opposite* to what the spec fails on...This is a bug related to the underscore sugar and Active Record, and is one of the many reasons we are eliminating the underscore sugar. If you use 0.8.0-RC1 or the current trunk, you can do this: @bdd.users.should be_an_instance_of(Array) and it will pass. Cheers, David> > Thanks, all, for your help, > > Best Regards, > > Scott Taylor > > > P.S. In the future shall I just plop in a bunch of code to my > message, or is pastie a good means for delivering somewhat large > chunks of code? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Jerry West
2007-Feb-24 18:36 UTC
[rspec-users] Spec failing [Possible Bug with kind_of? and instance_of?]
Answer written in haste, so may well be wrong... Rails associations are not Arrays even though they claim to be. I think they are ActiveRecord::Associations::AssociationProxies; why they claim to be Array I have no idea, simply being Enumerable would have sufficed I would have imagined. Why they proxy an array rather han extending it I have no idea. I have very few ideas :-). I personally believe proxies that lie to the developer like this should Be Considered Harmful, but it''s not my opinion that counts in this particular piece of opinionated software :-). I haven''t yet worked out how to tell an AP from an Array. Hope this helps. Hope I''ve remembered correctly too! Rgds, Jerry On Sat, 24 Feb 2007 10:21:25 -0000, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > I have a spec which is failing, but I just can''t say why. Maybe I''m > missing something painfully obvious? > > Here is the pastie of the results & the spec: > > http://pastie.caboo.se/42626 > > The spec to look for is "should have an array of users" I''ve printed > out ("puts''ed") to the terminal the fact that the values are > *opposite* to what the spec fails on... > > Thanks, all, for your help, > > Best Regards, > > Scott Taylor > > > P.S. In the future shall I just plop in a bunch of code to my > message, or is pastie a good means for delivering somewhat large > chunks of code? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-- Using Opera''s revolutionary e-mail client: http://www.opera.com/mail/
Ah. A quick google reveals more of the mystery.. "The target of AssociationProxy is not always an instance of Array. For example, for BelongsToAssociation it''s a ActiveRecord::Base instance." http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/143483 Rgds, Jerry