こんにちはみんなでテストする場合、アップロードきれいな添付ファイルのためのソリューションを必要としています。 は、私は、データベース・クリーナを設定しますが、私はそれが新しいファイルを作成する毎回のパブリックフォルダのツリーを行うときに、私は、私はRSpecのコマンドを実行し、このたびをきれいにしたいです。私はRSpecの
tree public
public
├── 404.html
├── 422.html
├── 500.html
├── attachment
├── favicon.ico
├── robots.txt
└── uploads
├── attachment
│ └── file
│ ├── 1
│ │ ├── photo.jpg
│ │ ├── photo02.jpg
│ │ └── photo03.jpg
│ ├── 10
│ │ └── photo03.jpg
│ ├── 11
│ │ └── photo.jpg
│ ├── 12
│ │ └── photo02.jpg
│ ├── 13
│ │ └── photo.jpg
│ ├── 14
│ │ └── photo02.jpg
│ ├── 15
│ │ └── photo03.jpg
│ ├── 16
│ │ └── photo.jpg
│ ├── 17
│ │ └── photo02.jpg
│ ├── 18
│ │ └── photo.jpg
│ ├── 19
│ │ └── photo02.jpg
│ ├── 2
│ │ ├── photo.jpg
│ │ └── photo02.jpg
│ ├── 20
│ │ └── photo03.jpg
│ ├── 21
│ │ └── photo.jpg
│ ├── 22
│ │ └── photo02.jpg
│ ├── 23
│ │ └── photo.jpg
│ ├── 24
│ │ └── photo02.jpg
│ ├── 25
│ │ └── photo03.jpg
│ ├── 26
│ │ └── photo.jpg
│ ├── 27
│ │ └── photo02.jpg
│ ├── 28
│ │ └── photo.jpg
│ ├── 29
│ │ └── photo02.jpg
│ ├── 3
│ │ ├── photo.jpg
│ │ └── photo03.jpg
│ ├── 30
│ │ └── photo.jpg
│ ├── 31
│ │ └── photo02.jpg
│ ├── 32
│ │ └── photo.jpg
│ ├── 33
│ │ └── photo02.jpg
│ ├── 34
│ │ └── photo.jpg
│ ├── 35
│ │ └── photo02.jpg
│ ├── 36
│ │ └── photo.jpg
│ ├── 37
│ │ └── photo02.jpg
│ ├── 38
│ │ └── photo.jpg
│ ├── 39
│ │ └── photo02.jpg
│ ├── 4
│ │ └── photo02.jpg
│ ├── 40
│ │ └── photo.jpg
│ ├── 41
│ │ └── photo02.jpg
│ ├── 42
│ │ └── photo.jpg
│ ├── 43
│ │ └── photo02.jpg
│ ├── 44
│ │ └── photo.jpg
│ ├── 45
│ │ └── photo02.jpg
│ ├── 46
│ │ └── photo.jpg
│ ├── 47
│ │ └── photo02.jpg
│ ├── 48
│ │ └── photo.jpg
│ ├── 49
│ │ └── photo02.jpg
│ ├── 5
│ │ └── photo03.jpg
│ ├── 50
│ │ └── photo.jpg
│ ├── 51
│ │ └── photo02.jpg
│ ├── 52
│ │ └── photo.jpg
│ ├── 53
│ │ └── photo02.jpg
│ ├── 54
│ │ └── photo.jpg
│ ├── 55
│ │ └── photo02.jpg
│ ├── 56
│ │ └── photo.jpg
│ ├── 57
│ │ └── photo02.jpg
│ ├── 58
│ │ └── photo.jpg
│ ├── 59
│ │ └── photo02.jpg
│ ├── 6
│ │ └── photo.jpg
│ ├── 60
│ │ └── photo.jpg
│ ├── 61
│ │ └── photo02.jpg
│ ├── 62
│ │ └── photo.jpg
│ ├── 63
│ │ └── photo02.jpg
│ ├── 64
│ │ └── photo.jpg
│ ├── 65
│ │ └── photo02.jpg
│ ├── 66
│ │ └── photo.jpg
│ ├── 67
│ │ └── photo02.jpg
│ ├── 68
│ │ └── photo.jpg
│ ├── 69
│ │ └── photo02.jpg
│ ├── 7
│ │ └── photo02.jpg
│ ├── 70
│ │ └── photo.jpg
│ ├── 71
│ │ └── photo02.jpg
│ ├── 72
│ │ └── photo.jpg
│ ├── 73
│ │ └── photo02.jpg
│ ├── 74
│ │ └── photo.jpg
│ ├── 75
│ │ └── photo02.jpg
│ ├── 8
│ │ └── photo.jpg
│ └── 9
│ └── photo02.jpg
├── post
└── tmp
だから、のconfigureのため、私はスペック/サポート/ database_cleaner.rbに入れたデータベース・クリーナ:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :deletion
DatabaseCleaner.clean_with(:deletion)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
私rails_helper:attachments.rbの
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require "pundit/rspec"
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
# Include Factory Girl syntax to simplify calls to factories
config.include FactoryGirl::Syntax::Methods
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
# Or, choose the following (which implies all of the above):
with.library :rails
end
end
config.include Warden::Test::Helpers, type: :feature
config.after(type: :feature) { Warden.test_reset! }
config.use_transactional_fixtures = false
config.include Devise::Test::ControllerHelpers, type: :controller
end
私の工場:
FactoryGirl.define do
factory :attachment do
transient do
file_to_attach "spec/fixtures/photo.jpg"
end
file { File.open file_to_attach }
end
end
適切にあなたが '"#{} Rails.root /公共/アップロード/設定されているので。あなたの開発環境と同じかもしれない、テスト環境でのアップロードのためのあなたのディレクトリとして ""。代わりに '' {{Rails.root}/spec/support/uploads/...」 'を試してみてください。 –