[rspec-users] Story Runner: Readability of output with multiple params

Zach Dennis zach.dennis at gmail.com
Sun Oct 14 13:58:17 EDT 2007

On 10/14/07, Pat Maddox <pergesu at gmail.com> wrote:
> On 10/14/07, Zach Dennis <zach.dennis at gmail.com> wrote:
> > Does it add any value to even add things like "Joe" and "Acme" into a
> > story part? It seems like that is an implementation detail of your
> > story.
> >
> > Who cares about "Joe" or "Acme", don't you just care that you have a
> > user who works for a company. And if that company has a particular
> > trait wouldn't it be cleaner to identify the company by that trait
> > rather then a name in the description?
> >
> > IE: Given " a user who works for a company that sells cartoons"
> >
> > And then in your helper you can use "Joe" and Acme"
> >
> > def a_user_who_works_for_a_company_that_sells_cartoons
> >   @user = Generate.user( "joe")
> >   @company = Generate.company("Acme")
> >   @company.employees = @user
> > end
> >
> >
> > ?
> >
> > --
> > Zach Dennis
> > http://www.continuousthinking.com
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> How do you create two users?

Given "a user joe who works for a company that sells cartoons"
And "a user jim who works for a company that sells cartoons"

Leave it in the description and have a well named helper method
responsible for making these users.

  def a_user_joe_who_works_for_a_company_that_sells_cartoons

Otherwise you will still most likely end up with a helper method and
you haven't added any value except for making your story more cody by
passing arguments and creating unneeded do/end blocks.

Given "a user who works for a company that sells cartoons", "Joe" do |name|

Another option would be to not use a helper method at all and do the
real work inside of the do/end block, but no you've made your code not
reusable. How likely is it that you have one acceptance test where you
have a user who works for a company?

Given "a user who works for a company that sells cartoons", "Joe" do |name|
  @company = Generate.company("Acme")
  @user = Generate.user("Joe")
  @company.employees << @user

I prefer hiding the implementation in well named helper methods as to
not take away from the a higher level of readability that the
acceptance test can accomplish. Granted, I'm shooting for the ideal,
which is a customer readable/writable acceptance test.

I don't think argument passing in story parts is wrong, I think that
how they are being used in this thread is wrong. For example for a
game you may have an acceptance test that looks like:

Given "a user playing the game"
When "they make a guess of", 200_000
# etc...

This makes more sense to me then passing in something which adds no
value to the test, like the user's name "Joe"

Zach Dennis

More information about the rspec-users mailing list