Skip to content

Commit

Permalink
Change TestSupport.factory_paths
Browse files Browse the repository at this point in the history
Before the method returned a list of individual file paths.
FactoryBot is able to load files from a directory. By changing
this to factories_path and return a single directory path it
is easier to prepend and append the path to the list of factory
bots factory definitions.
  • Loading branch information
tvdeyen committed Mar 2, 2021
1 parent 7abf391 commit c37d64f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions lib/alchemy/test_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

module Alchemy
module TestSupport
def self.factory_paths
Dir[
::Alchemy::Engine.root.join("lib", "alchemy", "test_support", "factories", "*_factory.rb")
].map { |path| path.sub(/.rb\z/, "") }
class << self
def factory_paths
Dir[
::Alchemy::Engine.root.join("lib", "alchemy", "test_support", "factories", "*_factory.rb")
].map { |path| path.sub(/.rb\z/, "") }
end
deprecate factory_paths: :factories_path, deprecator: Alchemy::Deprecation

def factories_path
::Alchemy::Engine.root.join("lib", "alchemy", "test_support", "factories")
end
end
end
end
4 changes: 2 additions & 2 deletions lib/alchemy/test_support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require 'alchemy/test_support'
FactoryBot.definition_file_paths.concat(Alchemy::TestSupport.factory_paths)
FactoryBot.reload
FactoryBot.definition_file_paths.append(Alchemy::TestSupport.factories_path)
FactoryBot.find_definitions
MSG

Dir["#{File.dirname(__FILE__)}/factories/*.rb"].sort.each do |file|
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
Capybara.ignore_hidden_elements = false

FactoryBot.definition_file_paths.concat(Alchemy::TestSupport.factory_paths)
FactoryBot.reload
FactoryBot.find_definitions

Capybara.register_driver :selenium_chrome_headless do |app|
Capybara::Selenium::Driver.load_selenium
Expand Down

0 comments on commit c37d64f

Please sign in to comment.