diff --git a/lib/alchemy/test_support.rb b/lib/alchemy/test_support.rb new file mode 100644 index 0000000000..54cc8e99ed --- /dev/null +++ b/lib/alchemy/test_support.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +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/, "") } + end + end +end diff --git a/lib/alchemy/test_support/essence_shared_examples.rb b/lib/alchemy/test_support/essence_shared_examples.rb index 1d5ea09418..0609a55209 100644 --- a/lib/alchemy/test_support/essence_shared_examples.rb +++ b/lib/alchemy/test_support/essence_shared_examples.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true require "shoulda-matchers" -require "alchemy/test_support/factories/page_factory" -require "alchemy/test_support/factories/element_factory" -require "alchemy/test_support/factories/content_factory" RSpec.shared_examples_for "an essence" do let(:element) { Alchemy::Element.new } diff --git a/lib/alchemy/test_support/factories.rb b/lib/alchemy/test_support/factories.rb index 73c3392771..d0f16a58b0 100644 --- a/lib/alchemy/test_support/factories.rb +++ b/lib/alchemy/test_support/factories.rb @@ -1,5 +1,16 @@ # frozen_string_literal: true +Alchemy::Deprecation.warn <<~MSG + Please require factories using FactoryBots preferred approach: + + # spec/rails_helper.rb + + require 'alchemy/test_support' + + FactoryBot.definition_file_paths.concat(Alchemy::TestSupport.factory_paths) + FactoryBot.reload +MSG + Dir["#{File.dirname(__FILE__)}/factories/*.rb"].sort.each do |file| require file end diff --git a/lib/alchemy/test_support/factories/attachment_factory.rb b/lib/alchemy/test_support/factories/attachment_factory.rb index 085cf90938..98fdfc5f0c 100644 --- a/lib/alchemy/test_support/factories/attachment_factory.rb +++ b/lib/alchemy/test_support/factories/attachment_factory.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "factory_bot" - FactoryBot.define do factory :alchemy_attachment, class: "Alchemy::Attachment" do file do diff --git a/lib/alchemy/test_support/factories/content_factory.rb b/lib/alchemy/test_support/factories/content_factory.rb index 44ab890c67..514aad0db9 100644 --- a/lib/alchemy/test_support/factories/content_factory.rb +++ b/lib/alchemy/test_support/factories/content_factory.rb @@ -1,11 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/element_factory" -require "alchemy/test_support/factories/essence_file_factory" -require "alchemy/test_support/factories/essence_picture_factory" -require "alchemy/test_support/factories/essence_text_factory" - FactoryBot.define do factory :alchemy_content, class: "Alchemy::Content" do name { "text" } diff --git a/lib/alchemy/test_support/factories/dummy_user_factory.rb b/lib/alchemy/test_support/factories/dummy_user_factory.rb index 0b40c47df4..9990bad6d4 100644 --- a/lib/alchemy/test_support/factories/dummy_user_factory.rb +++ b/lib/alchemy/test_support/factories/dummy_user_factory.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "factory_bot" - FactoryBot.define do factory :alchemy_dummy_user, class: "DummyUser" do sequence(:email) { |n| "john.#{n}@doe.com" } diff --git a/lib/alchemy/test_support/factories/element_factory.rb b/lib/alchemy/test_support/factories/element_factory.rb index 8140b6d3e8..9f417909e1 100644 --- a/lib/alchemy/test_support/factories/element_factory.rb +++ b/lib/alchemy/test_support/factories/element_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/page_factory" - FactoryBot.define do factory :alchemy_element, class: "Alchemy::Element" do name { "article" } diff --git a/lib/alchemy/test_support/factories/essence_file_factory.rb b/lib/alchemy/test_support/factories/essence_file_factory.rb index aaf1b425f5..82f11e0f7c 100644 --- a/lib/alchemy/test_support/factories/essence_file_factory.rb +++ b/lib/alchemy/test_support/factories/essence_file_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/attachment_factory" - FactoryBot.define do factory :alchemy_essence_file, class: "Alchemy::EssenceFile" do attachment factory: :alchemy_attachment diff --git a/lib/alchemy/test_support/factories/essence_page_factory.rb b/lib/alchemy/test_support/factories/essence_page_factory.rb index ad4b7a2494..b44fc67602 100644 --- a/lib/alchemy/test_support/factories/essence_page_factory.rb +++ b/lib/alchemy/test_support/factories/essence_page_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/page_factory" - FactoryBot.define do factory :alchemy_essence_page, class: "Alchemy::EssencePage" do page factory: :alchemy_page diff --git a/lib/alchemy/test_support/factories/essence_picture_factory.rb b/lib/alchemy/test_support/factories/essence_picture_factory.rb index 267f2bac45..f7d56bd71f 100644 --- a/lib/alchemy/test_support/factories/essence_picture_factory.rb +++ b/lib/alchemy/test_support/factories/essence_picture_factory.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/content_factory" -require "alchemy/test_support/factories/picture_factory" - FactoryBot.define do factory :alchemy_essence_picture, class: "Alchemy::EssencePicture" do picture factory: :alchemy_picture diff --git a/lib/alchemy/test_support/factories/essence_text_factory.rb b/lib/alchemy/test_support/factories/essence_text_factory.rb index 4982cccebb..a093182962 100644 --- a/lib/alchemy/test_support/factories/essence_text_factory.rb +++ b/lib/alchemy/test_support/factories/essence_text_factory.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "factory_bot" - FactoryBot.define do factory :alchemy_essence_text, class: "Alchemy::EssenceText" do body { "This is a headline" } diff --git a/lib/alchemy/test_support/factories/language_factory.rb b/lib/alchemy/test_support/factories/language_factory.rb index 3bbc4d47e5..bb976016f9 100644 --- a/lib/alchemy/test_support/factories/language_factory.rb +++ b/lib/alchemy/test_support/factories/language_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/site_factory" - FactoryBot.define do factory :alchemy_language, class: "Alchemy::Language" do name { "Your Language" } diff --git a/lib/alchemy/test_support/factories/node_factory.rb b/lib/alchemy/test_support/factories/node_factory.rb index 05aea03ad3..5dc1ba6f15 100644 --- a/lib/alchemy/test_support/factories/node_factory.rb +++ b/lib/alchemy/test_support/factories/node_factory.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/language_factory" -require "alchemy/test_support/factories/page_factory" - FactoryBot.define do factory :alchemy_node, class: "Alchemy::Node" do language { Alchemy::Language.default || create(:alchemy_language) } diff --git a/lib/alchemy/test_support/factories/page_factory.rb b/lib/alchemy/test_support/factories/page_factory.rb index 25136903e6..34e1fc9fdc 100644 --- a/lib/alchemy/test_support/factories/page_factory.rb +++ b/lib/alchemy/test_support/factories/page_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "alchemy/test_support/factories/language_factory" - FactoryBot.define do factory :alchemy_page, class: "Alchemy::Page" do language do diff --git a/lib/alchemy/test_support/factories/picture_factory.rb b/lib/alchemy/test_support/factories/picture_factory.rb index 31362d117d..08aeffdee7 100644 --- a/lib/alchemy/test_support/factories/picture_factory.rb +++ b/lib/alchemy/test_support/factories/picture_factory.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "factory_bot" - FactoryBot.define do factory :alchemy_picture, class: "Alchemy::Picture" do image_file do diff --git a/lib/alchemy/test_support/factories/picture_thumb_factory.rb b/lib/alchemy/test_support/factories/picture_thumb_factory.rb index be8f847f18..ca6fc779ad 100644 --- a/lib/alchemy/test_support/factories/picture_thumb_factory.rb +++ b/lib/alchemy/test_support/factories/picture_thumb_factory.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "factory_bot" -require "securerandom" - FactoryBot.define do factory :alchemy_picture_thumb, class: "Alchemy::PictureThumb" do picture { create(:alchemy_picture) } diff --git a/lib/alchemy/test_support/factories/site_factory.rb b/lib/alchemy/test_support/factories/site_factory.rb index 5d848fd010..de5cb539fe 100644 --- a/lib/alchemy/test_support/factories/site_factory.rb +++ b/lib/alchemy/test_support/factories/site_factory.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "factory_bot" - FactoryBot.define do factory :alchemy_site, class: "Alchemy::Site" do name { "A Site" } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 85af067a94..098bb211aa 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -14,16 +14,16 @@ require "rspec/rails" require "webdrivers/chromedriver" require "shoulda-matchers" +require "factory_bot" require "alchemy/seeder" +require "alchemy/test_support" require "alchemy/test_support/config_stubbing" require "alchemy/test_support/essence_shared_examples" require "alchemy/test_support/integration_helpers" -require "alchemy/test_support/factories" require "alchemy/test_support/shared_contexts" require "alchemy/test_support/shared_uploader_examples" -require_relative "factories" require_relative "support/calculation_examples.rb" require_relative "support/hint_examples.rb" require_relative "support/transformation_examples.rb" @@ -44,6 +44,9 @@ Capybara.default_selector = :css Capybara.ignore_hidden_elements = false +FactoryBot.definition_file_paths.concat(Alchemy::TestSupport.factory_paths) +FactoryBot.reload + Capybara.register_driver :selenium_chrome_headless do |app| Capybara::Selenium::Driver.load_selenium browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|