On Thu, Jun 18, 2009 at 1:36 AM, Stephen Eley<sfe...@gmail.com> wrote:
> On Thu, Jun 18, 2009 at 12:17 AM, Ben Mabey<b...@benmabey.com> wrote:
>>
>> If you do go down that route, I recommend method calls instead of instance
>> variables.  That way it will yell out you when you forget to define one. :)
>
> Hey, instance variables do that too.  Yelling == "my tests fail."  >8->
>
> (And if they don't, I'm *really* doing something wrong...)

But methods are more explicit. Suppose you want to parametrize on the
value of a certain property named "bar". Not defining  @bar will raise
an NoMethodError because you called something on nil. Not defining the
method will raise a NoMethodError because bar isn't defined, which
tells you immediately what you need to solve.

You could also do something like

def bar
  raise NotImplementedError, "please define this method in each of
your example groups that use this shared behavior"
end

and it will be even more explicit. *But* this means you have to define
the method *after* you include the shared examples, or it will fail
(which is a code smell, IMO).

-foca

>
>
> --
> Have Fun,
>   Steve Eley (sfe...@gmail.com)
>   ESCAPE POD - The Science Fiction Podcast Magazine
>   http://www.escapepod.org
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to