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

Josh Chisholm joshuachisholm at gmail.com
Mon Oct 22 05:34:55 EDT 2007

I don't know if this is still open for discussion, but I had a thought
relating back to one of Pat's suggestions:

> I had thought about putting the match method on string, so it becomes
> "an addend of $addend".matcher(:given) do {blah blah}
> or something similar.  But I don't really like that because I want
> "given" to be the first thing on the line.

...so we ended up with:

step_matchers do | add |
    add.given("my savings account balance is $balance") do |balance|
      @savings_account = Account.new(balance.to_f)

my thought is... would it be wrong to take the first word of the
matcher itself to determine its type? e.g:

step_matchers do
    "given my savings account balance is $balance".means do |balance|
      @savings_account = Account.new(balance.to_f)


On 10/20/07, Ian Dees <undees at gmail.com> wrote:
> Hi, Pat.
> > > Thinking out loud for larger projects here....  What's the scope (or
> > > lifetime -- I'm not sure what to call it) of a step created by
> > > step_matcher?  How does it know which Story to attach to?
> >
> > I don't think that's been figured out yet.  I chatted with David a bit
> > earlier this evening and we were brainstorming a little, but the convo
> > got cut short.  If you've got ideas I'd love to hear them.
> I'm not sure I have a solution, but I have some puzzles.
> Some steps might need to work for multiple stories.  A story about
> managing users (with several scenarios) and another story about
> managing blog posts (also with several scenarios) might both benefit
> from a "when I log in as an administrator" step.  So something like a
> story_helper.rb file could get included into multiple stories.
> On the other hand...
> Some steps are definitely story-specific.  A bowling game and a
> football game (take your pick which kind of football) might each have
> a "Given a new game" step.  We'd want to avoid collision somehow,
> either by non-RSpec methods (file/directory/require organization) or
> by some kind of optional namespacing:
> step_helper(:given, 'A new game', :story => 'bowling') do
>   @game = BowlingGame.new
> end
> > step_matcher(:given, "an addend of $addend")
> >
> > stands on its own.  At a glance you can tell that it's used as a
> > given.  Contrast that with scouring hundreds of lines of
> >
> > step_matcher("an addend of $addend")
> > step_matcher("an augend of $augend")
> > step_matcher("a tightend of $tightend")
> I dunno, it looks to me like those are all Given steps.  I certainly
> can't imagine "when an addend of $addend" or "then an addend of
> $addend."
> The Given/:given capitalization and colon mismatch is actually more
> distracting to me than a lack of a prefix; I'd constantly be typing
> the wrong one.  But maybe I'm just clumsy....
> --Ian
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the rspec-devel mailing list