Re: [rspec-users] before(:all) leaves records in database

2012-04-07 Thread nathanvda
When using before(:all) to create records in the database, you should use after(:all) to clean that up. Sometimes when you need to setup a lot of data, this can speed your tests a lot. Otherwise avoid it. On Friday, November 25, 2011 3:04:08 PM UTC+1, Zhi-Qiang Lei wrote: > > Hi, > > When I te

Re: [rspec-users] before(:all) leaves records in database

2011-11-25 Thread David Chelimsky
On Nov 25, 2011, at 8:04 AM, Zhi-Qiang Lei wrote: > Hi, > > When I test my Rails controller, I find that records created in before(:all) > remain in database while records created in before(:each) and let are wiped > out after testing. This made me run "rake test:prepare" for every new test. >

Re: [rspec-users] before(:all) leaves records in database

2011-11-25 Thread Evgeni Dzhelyov
Yes, Only before :each is run in transaction. You should avoid creating records in the before :all hook ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] before(:all) leaves records in database

2011-11-25 Thread Zhi-Qiang Lei
Hi, When I test my Rails controller, I find that records created in before(:all) remain in database while records created in before(:each) and let are wiped out after testing. This made me run "rake test:prepare" for every new test. Is that normal? Best regards, Zhi-Qiang Lei zhiqiang@gmai

Re: [rspec-users] before(:all) to set up mocks and stubs

2010-07-15 Thread Ivo Dancet
Thanks for your answers. I'll use a fixture replacement to set up the environment. I know that this (using before(:all) to setup a state) is not a best practice. In this case however, I would consider my approach to be acceptable as the pdf takes a long time to generate. All tests run on the sa

Re: [rspec-users] before(:all) to set up mocks and stubs

2010-07-13 Thread David Chelimsky
On Jul 13, 2010, at 7:25 AM, Ivo Dancet wrote: > Hi > > I'm upgrading an application to rspec2/rails3. A certain suite of tests, that > generates a pdf document, uses a before(:all) filter to set the environment > using mocks and stubs. Then the pdf gets generated and after that all the > test

Re: [rspec-users] before(:all) to set up mocks and stubs

2010-07-13 Thread Bayard Randel
I know that generally it is not considered best practice to user before(:all) and after(:all) as state is shared between all examples, which is a unit-testing anti-pattern. The rspec book recommends setting up fixtures and environment for each example. Perhaps to drive this point home, support for

[rspec-users] before(:all) to set up mocks and stubs

2010-07-13 Thread Ivo Dancet
Hi I'm upgrading an application to rspec2/rails3. A certain suite of tests, that generates a pdf document, uses a before(:all) filter to set the environment using mocks and stubs. Then the pdf gets generated and after that all the tests run on that same pdf document. In rspec2 it seems like I c

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread David Chelimsky
On Thu, Jul 9, 2009 at 9:37 AM, Daniel Tenner wrote: >> 2) Is it your goal to call "some_expensive_operation" once and only once? > > Yes, exactly. In the case of the project archival spec, creating a project, > archiving it, and then unzipping it to a temporary location to look at what > was archi

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread Daniel Tenner
> > 2) Is it your goal to call "some_expensive_operation" once and only once? Yes, exactly. In the case of the project archival spec, creating a project, archiving it, and then unzipping it to a temporary location to look at what was archived is a process that takes about 3 seconds on my machine.

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread Zach Moazeni
Rereading your original email, I'm thinking I may not have entirely understood your situation. 1) Looks like you've already defined the "some_expensive_operation" (but that's minor) 2) Is it your goal to call "some_expensive_operation" once and only once? On Jul 9, 2009, at 10:18 AM,

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread Zach Moazeni
Hey Dan, 1 approach you could do is define a method within the outer describe that is called within the inner describe and within each test not contained by an inner describe. describe "Some functionality" do it "should do something" do @variable = some_expensive_operation @variab

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread David Chelimsky
On Thu, Jul 9, 2009 at 5:40 AM, Daniel Tenner wrote: > Hi all, > Like everyone (?), I use nested contexts to keep my specs well organised and > tidy. > However, I have a problem. I have various sets of specs that needs to > perform very time-expensive operations to set up the fixtures that will be

Re: [rspec-users] before(:all) and nested contexts

2009-07-09 Thread Daniel Tenner
To answer myself, I've put together the following work-around: http://www.swombat.com/getting-rspec-beforeall-and-nested-contexts-w Still, would love to know if there was a better, less hackish way to do it. Daniel On Thu, Jul 9, 2009 at 11:40 AM, Daniel Tenner wrote: > Hi all, > Like everyone

[rspec-users] before(:all) and nested contexts

2009-07-09 Thread Daniel Tenner
Hi all, Like everyone (?), I use nested contexts to keep my specs well organised and tidy. However, I have a problem. I have various sets of specs that needs to perform very time-expensive operations to set up the fixtures that will be examined in the tests. Two specific examples: testing access c

Re: [rspec-users] before(:all)

2009-06-09 Thread Kyle Hargraves
On Sun, Jun 7, 2009 at 9:40 PM, lawrence.pit wrote: > Hi, > > I took a stab at this and created what I call Machinery. So far it > works great for me. > > For those that are looking for a way to create objects in the database > in a before(:all) instead of a before(:each) to speed up tests, have a

Re: [rspec-users] before(:all)

2009-06-07 Thread lawrence.pit
Hi, I took a stab at this and created what I call Machinery. So far it works great for me. For those that are looking for a way to create objects in the database in a before(:all) instead of a before(:each) to speed up tests, have a look at: http://github.com/lawrencepit/machinery Cheers, Lawr

Re: [rspec-users] before(:all)

2009-05-21 Thread David Chelimsky
On Wed, May 20, 2009 at 10:27 PM, lawrence.pit wrote: > Hi All, > > When I execute database actions within a before(:each) they are rolled > back after each example test has run. I expected that if I execute db > actions within a before(:all) they would all be rolled back after all > examples fini

[rspec-users] before(:all)

2009-05-21 Thread lawrence.pit
Hi All, When I execute database actions within a before(:each) they are rolled back after each example test has run. I expected that if I execute db actions within a before(:all) they would all be rolled back after all examples finished running. This appears not to be the case, in my case. Is ther