Ruby on rails 通过工厂女孩创建图像进行RSpec测试
在rails 4.2.0应用程序中,我使用RSpec和Factory Girl进行测试。在应用程序中,我使用回形针上传图像。当我使用空白图像运行测试时,图像将被放置在公用文件夹中 我有没有办法用数据库来解决这个问题 到目前为止,我有: spec\support\factory\u girl.rbRuby on rails 通过工厂女孩创建图像进行RSpec测试,ruby-on-rails,ruby,rspec,factory-bot,database-cleaner,Ruby On Rails,Ruby,Rspec,Factory Bot,Database Cleaner,在rails 4.2.0应用程序中,我使用RSpec和Factory Girl进行测试。在应用程序中,我使用回形针上传图像。当我使用空白图像运行测试时,图像将被放置在公用文件夹中 我有没有办法用数据库来解决这个问题 到目前为止,我有: spec\support\factory\u girl.rb RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.before(:suite) do b
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\u 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(:each) { FileUtils.rm @file_path }
哦,对了,我从阅读一些文档中得到的印象是它会。为小费干杯。尽管如何定义@file_path?@Koxi,但您可以通过各种方式将文件路径传递给after块,例如在before
块中定义它。或者,您可以在创建该文件的同一示例中删除该文件,并对两者使用相同的path变量。