[rspec-users] first cut at blockless given/when/then

Wincent Colaiuta win at wincent.com
Thu Oct 18 07:05:11 EDT 2007


El 18/10/2007, a las 10:33, "David Chelimsky" <dchelimsky at gmail.com>  
escribió:

> Take a look at examples/story/calculator.rb to see what's going on.
>
> Needs docs!!!!
>
> Thoughts welcome.

Could this:

   step_matcher(:given, "an addend of $addend") do |addend|
     @adder ||= Adder.new
     @adder << addend.to_i
   end

   step_matcher(:when, "they are added") do
     @sum = @adder.sum
   end

   step_matcher(:then, "the sum should be $sum") do |sum|
     @sum.should == sum.to_i
   end

Be refactored to this?

   given_matcher("an addend of $addend") do |addend|
     @adder ||= Adder.new
     @adder << addend.to_i
   end

   when_matcher("they are added") do
     @sum = @adder.sum
   end

   then_matcher("the sum should be $sum") do |sum|
     @sum.should == sum.to_i
   end

I'd find that a little bit easier to type; what do you think?

Cheers,
Wincent





More information about the rspec-users mailing list