[Rspec-devel] possible addition to expectations...
aslak.hellesoy at gmail.com
Mon Apr 24 09:25:58 EDT 2006
On 4/24/06, David Astels <dastels at daveastels.com> wrote:
> Nice. But... it doesn't support the have... expectations.
I got the impression Rich wanted feedback on the general idea. Support
for have.. can be easily added.
So what do you think about the idea? Something we want to add before
1.0? In my opinion it makes RSpec follow general Ruby naming
conventions more closely. So I'm +1
> 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%)
> > aslak
> > 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
> > _______________________________________________
> > Rspec-devel mailing list
> > Rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
More information about the Rspec-devel