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

David Chelimsky dchelimsky at gmail.com
Thu Oct 18 10:05:54 EDT 2007


On 10/18/07, Wincent Colaiuta <win at wincent.com> wrote:
> 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?

Easier to type, sure. I'm not in love w/ the names yet though because
they sound like verb phrases - "given matcher", "when matcher", "then
matcher".

How about something like match_given, match_when, match_then?


More information about the rspec-users mailing list