[rspec-devel] names for setup and teardown methods

aslak hellesoy aslak.hellesoy at gmail.com
Tue May 1 14:15:46 EDT 2007


On 5/1/07, Matt Aimonetti <mattaimonetti at gmail.com> wrote:
> after(:each) doesn't work either.
>

Really? A sample spec showing how after(:each) doesn't work would be helpful.

Aslak

> -Matt
>
>
> On 5/1/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> >
> > It's after(:each) and not teardown(:each)
> >
> > On 5/1/07, Matt Aimonetti < mattaimonetti at gmail.com> wrote:
> > > describe "a legacy user" do
> > >   include LegacyUserHelper
> > >
> > >   before :all do
> > >     LEGACY.connect
> > >     migration_for_legacy_users
> > >   end
> > >
> > >   before do
> > >     @l_user = LegacyUser.new
> > >   end
> > >
> > >  teardown :each do
> > >
> delete_user_with_email(valid_legacy_user_attributes[:email])
> > >  end
> > >
> > > Here is a snippet of my code.
> > >
> > > Before running my examples, I need to connect to my legacy database and
> > > migrating the schema. After each example I need to delete the legacy
> user
> > > just created. To get the above code to work, I had to move my
> > >
> delete_user_with_email(valid_legacy_user_attributes[:email])
> function to be
> > > run before each example instead of after.
> > >
> > > -Matt
> > >
> > > On 4/30/07, David Chelimsky < dchelimsky at gmail.com> wrote:
> > > >
> > > > On 4/30/07, Matt Aimonetti <mattaimonetti at gmail.com> wrote:
> > > > > teardown :each and after :each don't seem to work for me.
> > > > >
> > > > > I had to move my function from "teardown :each" to "before" since
> the
> > > > > function was deleting the object created by the previous spec and
> the
> > > > > function didn't seem to be called. Maybe I didn't understand
> properly
> > > > how
> > > > > teardown and after work.
> > > >
> > > > Each example (i.e. #it or #specify) gets run in its own object. It has
> > > > no access to any state in the other examples. before(:each) is run
> > > > before each example, in the same object as the example. after(:each)
> > > > is run after each example, in the same object as the example.
> > > >
> > > > I'm a bit confused by your description of the problem. Can you post
> > > > some code so we can talk about a specific example?
> > > >
> > > >
> > > > >
> > > > > -Matt
> > > > >
> > > > >
> > > > > On 4/18/07, Matthew Heidemann < matthew.heidemann at gmail.com> wrote:
> > > > > > I personally like before :each_example. The first time I read it I
> > > > said,
> > > > > "before :each what?".
> > > > > >
> > > > > > I think once people run the spec and see 1 example 0 failures,
> they
> > > > know
> > > > > that the 'it do' is an example
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 4/11/07, Matt Aimonetti < matt at aimonetti.net> wrote:
> > > > > > > I fully agree with Dean and prefer the "before :each", "after
> :all"
> > > > > option, it reads better and is easier to understand for newbies.
> > > > > > >
> > > > > > > -Matt
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On 4/11/07, Dean Wampler <deanwampler at gmail.com> wrote:
> > > > > > > > Setup and teardown are more approachable to converts from
> > > > Test::Unit,
> > > > > > > > but "before :all" and "after :each" read better, IMHO.
> > > > > > > >
> > > > > > > > "all_examples" might cause people to ask "what examples?" I'm
> not
> > > > sure
> > > > > > > > most people will think of the "it blocks" as examples. Still,
> you
> > > > > > > > could just accept any symbol that begins with "each" and
> "all", so
> > > > > > > > people can invent their own name ;)
> > > > > > > >
> > > > > > > > dean
> > > > > > > >
> > > > > > > >
> > > > > > > > On 4/11/07, David Chelimsky < dchelimsky at gmail.com> wrote:
> > > > > > > > > We're going to rename context_setup and context_teardown
> because
> > > > > they
> > > > > > > > > no longer read well when using "describe/id". There are two
> > > > ideas
> > > > > > > > > floating around about this. The first:
> > > > > > > > >
> > > > > > > > > setup :each        #default - works like setup does now
> > > > > > > > > setup :all             #replaces context_setup
> > > > > > > > > teardown :each #default - works like teardown does now
> > > > > > > > > teardown :all      #replaces context teardown
> > > > > > > > >
> > > > > > > > > The second uses "before" and "after" in the same way:
> > > > > > > > >
> > > > > > > > > before :each   #default - works like setup does now
> > > > > > > > > before :all        #replaces context_setup
> > > > > > > > > after :each       #default - works like teardown does now
> > > > > > > > > after :all            #replaces context teardown
> > > > > > > > >
> > > > > > > > > In both cases, the default is :each, so you can just say
> "setup
> > > > do"
> > > > > or
> > > > > > > > > "before do" instead of "setup :each do" or "before :each
> do".
> > > > > > > > >
> > > > > > > > > == Examples
> > > > > > > > >
> > > > > > > > > describe Thing do
> > > > > > > > >   setup :all { ... }
> > > > > > > > >   setup :each { ... }
> > > > > > > > >   it "should do something" { ... }
> > > > > > > > >   it "should do something else" { ... }
> > > > > > > > >   teardown :each { ... }
> > > > > > > > >   teardown :all { ... }
> > > > > > > > > end
> > > > > > > > >
> > > > > > > > > describe Thing do
> > > > > > > > >   before :all { ... }
> > > > > > > > >   before :each { ... }
> > > > > > > > >   it "should do something" { ... }
> > > > > > > > >   it "should do something else" { ... }
> > > > > > > > >   after :each { ... }
> > > > > > > > >   after :all { ... }
> > > > > > > > > end
> > > > > > > > >
> > > > > > > > > describe Thing do
> > > > > > > > >   before { ... } # works like before :each
> > > > > > > > >   it "should do something" { ... }
> > > > > > > > >   it "should do something else" { ... }
> > > > > > > > >   after { ... } # works like after :each
> > > > > > > > > end
> > > > > > > > >
> > > > > > > > > One other thing that occurs to me is that "before :each"
> really
> > > > > means
> > > > > > > > > "before each example" - so perhaps it should be "before
> > > > > :each_example"
> > > > > > > > > and "before :all_examples" (or :each and :each_example could
> > > > both be
> > > > > > > > > supported, etc).
> > > > > > > > >
> > > > > > > > > WDYT?
> > > > > > > > >
> _______________________________________________
> > > > > > > > > rspec-devel mailing list
> > > > > > > > > rspec-devel at rubyforge.org
> > > > > > > > >
> http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > > Dean Wampler
> > > > > > > > http://www.objectmentor.com
> > > > > > > > http://www.aspectprogramming.com
> > > > > > > > http://www.contract4j.org
> > > > > > > >
> _______________________________________________
> > > > > > > > rspec-devel mailing list
> > > > > > > > rspec-devel at rubyforge.org
> > > > > > > >
> http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > _______________________________________________
> > > > > > > rspec-devel mailing list
> > > > > > > rspec-devel at rubyforge.org
> > > > > > >
> http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > > > >
> > > > > >
> > > > > >
> > > > > > _______________________________________________
> > > > > > rspec-devel mailing list
> > > > > > rspec-devel at rubyforge.org
> > > > > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > > >
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > rspec-devel mailing list
> > > > > rspec-devel at rubyforge.org
> > > > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > >
> > > > _______________________________________________
> > > > rspec-devel mailing list
> > > > rspec-devel at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > > >
> > >
> > _______________________________________________
> > rspec-devel mailing list
> > rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
> >
>
>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list