[Rspec-devel] possible addition to expectations...

Richard Kilmer rich at infoether.com
Mon Apr 24 16:09:37 EDT 2006

On Apr 24, 2006, at 9:08 AM, aslak hellesoy wrote:

> hi rich,
> that's funny. it's back to the way it used to be!
> the reason we.switched.to.a.dotted.syntax was primarily  
> implementation reasons.
> however, i can't help but think it sounds a bit staccato when i read
> it. my ruby head is more_used_to_digesting_underscores.
> i like it a lot. let's see what the others think.
> oh - i think you forgot to attach the tests ;-) we're trying to keep
> our coverage where it is (98.9%)
> aslak

Yep, sorry about that, I was operating on the gem code on the plane,  
it was all I had.  I will roll tests in.  I just wanted feedback, as  
my initial impression of the readability of rspec (as a long time  
ruby person) was "why all the ugly dots".  I like the implementation  
and encapsulation (chaining of calls).  That's why I just split and  
dispatch.  The dots remove all ambiguity as to what is happening, the  
other syntax is more "readable ruby".  You will likely mix them for  


You need the dot to separate the passed variables, but its still  
better to me than:


Although the same is happening.


> On 4/24/06, Richard Kilmer <rich at infoether.com> wrote:
>> Hello all.
>> Very great framework!
>> I was talking with Steven Baker at the Ruby in the Valley thing and I
>> came up with a simple addition that allows underscore notation in
>> addition to dot notation...so you can do this:
>> target.should.equal <value>
>> target.should.not.equal <value>
>> target.should.be.close <value>, <tolerance>
>> target.should.not.be.close <value>, <tolerance>
>> can also be expressed as:
>> target.should_equal <value>
>> target.should_not_equal <value>
>> target.should_be_close <value>, <tolerance>
>> target.should_not_be_close <value>, <tolerance>
>> What I did was override method_missing on Object and if the call
>> begins with should_ it splits on _ and then chain invokes those
>> methods.  There may be cleaner code than this...I did it on a red- 
>> eye.
>> Best,
>> Rich Kilmer
>> class Object
>>    include Spec::ObjectExpectations
>>    alias_method :__orig_method_missing, :method_missing
>>    def method_missing(method, *args, &block)
>>      if method.to_s[0,7] == "should_"
>>        object = self
>>        calls = method.to_s.split("_")
>>        while calls.length > 1
>>          object = object.send(calls.shift)
>>        end
>>        return object.send(calls.shift, *args, &block)
>>      end
>>      __orig_method_missing(method, *args, &block)
>>    end
>> end
>> _______________________________________________
>> Rspec-devel mailing list
>> Rspec-devel at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the Rspec-devel mailing list