0

In a rails 4.2.0 app I'm using RSpec and Factory Girl for tests. In the app I am using Paperclip for image uploads. When I run the tests with a blank image the image is being placed in the public folder.

Is there any way I can use the database_cleaner gem to fix this?

So far I have this:

spec\support\factory_girl.rb

RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
 config.before(:suite) do
  begin
    DatabaseCleaner.start
    FactoryGirl.lint
  ensure
    DatabaseCleaner.clean
  end
 end
end

spec\support\database_cleaner.rb

RSpec.configure do |config|

 config.before(:suite) 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
end
Koxzi
  • 1,021
  • 1
  • 10
  • 21

1 Answers1

2

DatabaseCleaner is for cleaning the database, not the file system. You can remove the file yourself instead, e.g. in an after block.

after(:each) { FileUtils.rm @file_path }
Mori
  • 27,279
  • 10
  • 68
  • 73
  • Oh right, I was under the impression from reading bits of documentation that it would. Cheers for the tip. Although how would define @file_path ? – Koxzi Feb 15 '15 at 16:13
  • @Koxi, You can pass the file path to the after block in various ways, e.g. define it in a `before` block. Or you can remove the file in the same example that you create it, and use the same path variable for both. – Mori Feb 15 '15 at 16:40