1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00

Only add exist paths to reloading target

Currently, `factories`, `test/factories` and `spec/factories` are
specified by default as reload watching paths.
In many applications, there are directories which do not exist (perhaps
do not have` spec` if using minitest and do not have` spec` if using
minitest).

In Rails 5 series, if specify a path that does not exist in
`EventedFileUpdateChecker`, its parent is added to the watching path.
As a result, `node_modules` is also included in the watching path, and
unexpectedly many directories and files are included in listen's watching
targets. Also, if symlink is included in `node_modules`, it also causes
warning of listen.

This issue is solved in Rails 6. However, since many applications use
this gem in Rails 5 and below, it is good not to add directories that
do not exist on the gem side.

Ref: https://github.com/rails/rails/issues/32700
This commit is contained in:
yuuji.yaginuma 2019-02-05 15:45:14 +09:00 committed by Daniel Colson
parent e6509920a6
commit f718048aa8
2 changed files with 16 additions and 11 deletions

View file

@ -2,8 +2,6 @@
module FactoryBotRails
class DefinitionFilePaths
attr_reader :files, :directories
def initialize(definition_file_paths)
@files = []
@directories = {}
@ -13,5 +11,13 @@ module FactoryBotRails
@directories[path.to_s] = [:rb]
end
end
def directories
@directories.select { |path| Dir.exist?(path) }
end
def files
@files.select { |file| File.exist?(file) }
end
end
end

View file

@ -2,33 +2,32 @@
describe FactoryBotRails::DefinitionFilePaths do
describe "#files" do
it "returns a list of definition files" do
definition_file_paths = ["definition_path", "another_definition_path"]
it "returns a list of definition files that only exist" do
definition_file_paths = ["spec/fixtures/factories", "not_exist_directory"]
files = described_class.new(definition_file_paths).files
expect(files).to eq ["definition_path.rb", "another_definition_path.rb"]
expect(files).to eq ["spec/fixtures/factories.rb"]
end
end
describe "#directories" do
it "returns a hash of definition directories" do
definition_file_paths = ["definition_path", "another_definition_path"]
it "returns a hash of definition directories that only exist" do
definition_file_paths = ["spec/fixtures/factories", "not_exist_directory"]
directories = described_class.new(definition_file_paths).directories
expect(directories).to eq(
"definition_path" => [:rb],
"another_definition_path" => [:rb],
"spec/fixtures/factories" => [:rb],
)
end
it "converts Pathname objects to strings" do
definition_file_paths = [Pathname.new("definition_path")]
definition_file_paths = [Pathname.new("spec/fixtures/factories")]
directories = described_class.new(definition_file_paths).directories
expect(directories).to eq("definition_path" => [:rb])
expect(directories).to eq("spec/fixtures/factories" => [:rb])
end
end
end