[rspec-users] Common setup code and naming specifications

David Chelimsky dchelimsky at gmail.com
Thu Jan 4 22:50:01 EST 2007


On 1/4/07, Bob Cotton <bob.cotton at rallydev.com> wrote:
> Bryan Liles <bryan at osesm.com> writes:
>
> > On Jan 4, 2007, at 6:34 PM, Bob Cotton wrote:
> >
> >>
> >> What about:
> >>
> >> module LoggedIn
> >>   def setup
> >>     session[:logged_in] = true
> >>   end
> >> end
> >>
> >> context "..." do
> >>   include LoggedIn
> >> end
> >>
> >
> > With this method, don't you lose access to setup?  Seems like a lot
> > to lose just to gain a a login mixin.
>
> Sorry, LoggedIn should have been a class:
>
> class One
>   def setup
>     puts "in setup one"
>   end
> end
>
> context "context with inherit" do
>   inherit One
>
>   setup do
>     puts "in context setup"
>   end
>
>   specify "some specify" do
>     puts "in specify"
>   end
> end
>
> $ spec foo_spec..rb
>
> in setup one
> in context setup
> in specify
> .
>
>
> I do agree with David, that some duplication in test code is ok. It
> would be easy to get the LoggedIn class buried up the inheritance
> hierarchy where it can't be seen.
>
> But if it's the only superclass of the context, and it's visible, and
> it named correctly, this will save you some typing.

Great idea - but unfortunately we already use "inherit" in all of the
rails contexts. That's ultimately how we're able to tap into
Test::Unit::TestCase to take advantage of fixture loading, etc.

>
>  -Bob
>
> --
> Bob Cotton
> Test Architect -- Rally Software -- rallydev.com
> http://www.testarchitecture.com/blog
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list