There is an alternate syntax that I'm using nearly exclusively at this
point, which is to pass a block along with the stub() and
should_receive() messages:

   foo.stub(:bar) { "return value" }
   foo.stub(:bar) { raise SomeError }
   foo.stub(:bar) { yield "value" }
   foo.stub(:bar) { throw :value }
   foo.should_receive(:bar) { "return value" }
   foo.should_receive(:bar) { raise SomeError }
   foo.should_receive(:bar) { yield "value" }
   foo.should_receive(:bar) { throw :value }

As you can see, there is much less API to worry about here. You're
just supplying an implementation.

This approach also works with scoped arguments:

   input = Input.new
   calculator = Calculator.new(input)
   calculator.should_receive(:add).with(1,2) { 3 }
   input.type("1", "+", "2", "Enter")

I've been thinking of deprecating the and_xxx methods in rspec-2. Does
anybody think that's an awful idea?

It may be because my RSpec-fu is relatively immature, but I like and_return and friends. It makes sense to my brain. Admittedly, I have not used the other syntax yet, so I really should give it a go and see what I think. At the present moment, I would be very disappointed if the and_ methods went away.

-1

Peace,
Phillip

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to