Skip to content

Commit e4d2344

Browse files
committed
Reuse existing definition_file_paths from factory_bot_helper
Note: By default, Factory bot sets definition_file_paths to directories to search for factories: https://github.com/thoughtbot/factory_bot/blob/8446cb6c5b39ea046d8ba180197aabc66adf62ed/lib/factory_bot/find_definitions.rb#L10 Cypress on rails SmartFactoryWrapper is expecting files to be a pattern or a file that when evaluated with Dir[xxx], will return files, not a directory: https://github.com/shakacode/cypress-playwright-on-rails/blob/abb505c0691c29d5f2a57c2ba28aedbfd43d079e/lib/cypress_on_rails/smart_factory_wrapper.rb#L88 Therefore, to reuse the existing definition_file_paths, we must convert the directories to glob pattern matches.
1 parent 3311ca0 commit e4d2344

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cypress/e2e/e2e_helper.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
factory = FactoryBot if defined?(FactoryBot)
2929
factory = FactoryGirl if defined?(FactoryGirl)
3030

31+
# TODO: By default, Factory bot sets definition_file_paths to directories to search for factories:
32+
# https://github.com/thoughtbot/factory_bot/blob/8446cb6c5b39ea046d8ba180197aabc66adf62ed/lib/factory_bot/find_definitions.rb#L10
33+
# Cypress on rails SmartFactoryWrapper is expecting files to be a pattern or a file that when evaluated with Dir[xxx],
34+
# will return files, not a directory:
35+
# https://github.com/shakacode/cypress-playwright-on-rails/blob/abb505c0691c29d5f2a57c2ba28aedbfd43d079e/lib/cypress_on_rails/smart_factory_wrapper.rb#L88
36+
# Therefore, to reuse the existing definition_file_paths, we must convert the directories to glob pattern matches.
37+
require Rails.root.join('spec/support/factory_bot_helper')
3138
CypressOnRails::SmartFactoryWrapper.configure(
3239
always_reload: false,
3340
factory: factory,
34-
files: [
35-
Rails.root.join('spec', 'factories.rb'),
36-
Rails.root.join('spec', 'factories', '**', '*.rb'),
37-
*Vmdb::Plugins.collect {|p| p.root.join("spec/factories", "**", "*.rb")}
38-
]
41+
files: FactoryBot.definition_file_paths.flat_map { |p| p.directory? ? p.join("**/*.rb") : p }
3942
)

0 commit comments

Comments
 (0)