forked from thoughtbot/factory_bot_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not register a reloader when file paths not exist
If all the paths specified in `FactoryBot.definition_file_paths` do not exist, an empty array is passed to the reloader. If an empty array is specified, reloader passes it to `Listen.to` as it is. This causes the application root to be watched and `node_modules` to become a target of listening. The behavior when an empty array is passed to reloader depends on the Rails side. Fixes to not register a reloader when file paths do not exist consistent behavior regardless of Rails side. Fixes thoughtbot#328.
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
describe FactoryBotRails::Reloader do | ||
describe "#run" do | ||
before do | ||
@original_definition_file_paths = FactoryBot.definition_file_paths | ||
end | ||
|
||
after do | ||
FactoryBot.definition_file_paths = @original_definition_file_paths | ||
end | ||
|
||
context "when a definition file paths exist" do | ||
it "registers a reloader" do | ||
allow(reloader_class).to receive(:new) | ||
|
||
run_reloader(["spec/fixtures/factories", "not_exist_directory"]) | ||
|
||
expect(reloader_class).to have_received(:new) | ||
end | ||
end | ||
|
||
context "when a file exists but not a directory" do | ||
it "registers a reloader" do | ||
allow(reloader_class).to receive(:new) | ||
|
||
run_reloader(["spec/fake_app", "not_exist_directory"]) | ||
|
||
expect(reloader_class).to have_received(:new) | ||
end | ||
end | ||
|
||
context "when a definition file paths NOT exist" do | ||
it "does NOT register a reloader" do | ||
allow(reloader_class).to receive(:new) | ||
|
||
run_reloader(["not_exist_directory"]) | ||
|
||
expect(reloader_class).not_to have_received(:new) | ||
end | ||
end | ||
|
||
def run_reloader(definition_file_paths) | ||
FactoryBot.definition_file_paths = definition_file_paths | ||
FactoryBotRails::Reloader. | ||
new(Rails.application, Rails.application.config).run | ||
end | ||
|
||
def reloader_class | ||
Rails.application.config.file_watcher | ||
end | ||
end | ||
end |