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

David Chelimsky dchelimsky at gmail.com
Fri Oct 19 09:48:34 EDT 2007


On 10/19/07, Wincent Colaiuta <win at wincent.com> wrote:
> >> Another alternative combining your suggestion with what Pat
> >> mentioned:
> >>
> >> step_matchers do |match|
> >>    match.given ...
> >>    match.when ...
> >>    match.then ...
> >> end
> >
> > That's nice, except we don't want methods named when and then as they
> > are keywords :(
>
> Even so, it still works. Ruby is smart enough to figure out that when
> "when" and "then" appear after a period, then they're actually
> message sends:
>
>    irb> class Foo
>    irb>   def when
>    irb>     puts "hello world"
>    irb>   end
>    irb> end
>    => nil
>    irb> Foo.new.when
>    hello world
>    => nil
>
> Or is there some other complication that I'm not aware of?

You won't be able to use a case statement in the match object. That
might be OK, but it's a bit weird.


More information about the rspec-users mailing list