Hi Jon, thanks for the info.

Problem is that functions that we are trying to write tests for have a lot 
of database calls for the records i mentioned above so just hardcoding them 
or mocking them is not gonna work. Now i know that this is not the best 
practise but code is old and refactoring it is currently not possible...so 
i'm trying to work on speeding up tests. Also i tried with excluding tables 
but it created some other issues in some tests.

My current spec config looks something like this...

 config.use_transactional_fixtures = true


 config.before(:all) do
 DatabaseCleaner.clean_with(:truncation)
 end


 config.before(:each) do
 DatabaseCleaner.strategy = :transaction
 end


 config.before(:each) do
 DatabaseCleaner.start
 end


 config.after(:each) do
 DatabaseCleaner.clean
 end

Not sure on logic behind this since it was not my setup but do you think 
this can be improved and for the problem above do you maybe have some other 
solution?

Cheers,
Uros

On Tuesday, August 21, 2018 at 11:50:40 AM UTC+2, Jon Rowe wrote:
>
> Hi Uros
>
> This is generally considered “less than ideal” as it encourages shared 
> state making your tests dependant on each other (e.g. if one of your tests 
> deletes this seed data your other specs will fail regardless) if your data 
> is “static” consider making it hard coded instead, or refactor your tests 
> to not “always” need this data.
>
> However if really want to do this consider switching to transactional 
> tests (or cleaning), unfortunately this is not possible in integration 
> testing environments with a real server ala puma or webrick due to thread / 
> process separation. Transactional setup here will rollback any changes made 
> by your individual tests allowing you to do setup in a `before(:suite)`. 
> You can also exclude certain tables from database cleaners truncation if 
> that helps?
>
> Cheers
> Jon Rowe
> ---------------------------
> [email protected] <javascript:>
> jonrowe.co.uk
>
> On 20 August 2018 at 15:22, Uros Certic wrote:
>
> Anyone knows if there is a way to use database_cleaner and clean test 
> database after each test but keep only certain records?
> I have some records that are reused in almost all tests and they need to 
> be persisted.
> Currently i'm setting them with factorybot in before(:all) block but it 
> takes a lot of time and it would be good if they can be persisted and not 
> removed with database cleaner
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/f4f67110-9bb9-4dd4-b205-07b0951ca610%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to