[Rspec-devel] possible addition to expectations...
dastels at daveastels.com
Mon Apr 24 09:20:18 EDT 2006
Nice. But... it doesn't support the have... expectations.
On 24-Apr-06, at 8: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%)
> 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-
>> 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)
>> return object.send(calls.shift, *args, &block)
>> __orig_method_missing(method, *args, &block)
>> Rspec-devel mailing list
>> Rspec-devel at rubyforge.org
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
More information about the Rspec-devel