On Jul 25, 6:40 pm, 7stud -- <[email protected]> wrote: > John Feminella wrote in post #1012869: > > > In other words, it > > needs a "before" to start with and an "after" to compare to. With a > > lambda, this is accomplished by measuring the thing you want to check > > before the lambda is run, and then again after it's run. > > Okay, I sort of sussed that out myself. But the question remains, how > can should_not() expect a lambda in one case, and then successfully > operate on a String in another case, like here: > > @user.encrypted_password.should_not be_blank > > Does the definition of should_not check the type of the receiver before > executing? I can't find any docs for the definition of should_not().
should and should_not are both added to every object, and pass self (the receiver) to the matches?() method on the matcher passed to should[_not]. e.g. obj.should matcher # => matcher.matches?(obj) It is the matcher that cares what the object is, not the should[_not] method. And the matchers do not, generally, do type checking on the object - they just assume that you're doing the right thing, and let Ruby handle errors if you do the wrong thing (e.g. undefined method 'call'). HTH, David -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

