繁体   English   中英

RSpec使用Factory Girl创建映像进行测试

[英]RSpec tests with Factory Girl creating image

在Rails 4.2.0应用程序中,我使用RSpec和Factory Girl进行测试。 在应用程序中,我使用回形针进行图像上传。 当我使用空白图像运行测试时,该图像将放置在公用文件夹中。

有什么办法可以使用database_cleaner gem修复此问题?

到目前为止,我有这个:

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

DatabaseCleaner用于清除数据库,而不是文件系统。 您可以自己删除文件,例如在after块中。

after(:each) { FileUtils.rm @file_path }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM