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

Pat Maddox pergesu at gmail.com
Thu Oct 18 12:54:05 EDT 2007


On 10/18/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 10/18/07, Pat Maddox <pergesu at gmail.com> wrote:
> > step_matchers("arithmetic") do
> >  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
> > end
> >
> > That allows you to do something like
> >
> > Story: Adding numbers
> >   uses arithmetic vocabulary
> >   ...
> >
> >
> > or something along those lines.
>
> I like the idea of mapping a story to a vocabulary. I just don't like
> doing it in the story text itself - seems more dev-facing than
> customer-facing. But perhaps the notion of vocabulary is a good thing
> to have front and center to help the customer understand the
> constraints of what can be written. Need to think about that some
> more.

I know what you mean.  It comes across too much as "import some_lib"
to me.  Not quite sure what to do about that.

One other idea I had was sticking similar stories in subdirs, each of
which has a helper.rb file.  That helper file would load up whatever
step libraries you would want to apply to each story in that dir.

Pat


More information about the rspec-users mailing list