# frozen_string_literal: true require 'pp' ################################################################################ # Test Gem Requires # # These are gems which, if they exist, we generally want to load. Ideally we'd # be able to do this only if there were tests with the proper metadata # specifying that we want to use these gems, however due to load order, they # must be required here. # # Below, we throw exceptions for each gem if the user requests that a test use # these gems, but the load failed (due to it not being in the gemspec/Gemfile). # # rubocop:disable Layout/EmptyLinesAroundExceptionHandlingKeywords begin; require 'email_spec'; rescue LoadError; end begin; require 'timecop'; rescue LoadError; end begin; require 'webmock'; rescue LoadError; end begin; require 'vcr'; rescue LoadError; end # rubocop:enable Layout/EmptyLinesAroundExceptionHandlingKeywords ################################################################################ # Configuration # # These are the standard requires and configuration generally listed in the # gem's README. # # These files do *not* load the ACTUAL gem, but WILL load any RSpec files that # the README says need to be required (but only if necessary). # require 'rspeckled/plugins/configuration/bullet' if defined?(::Bullet) require 'rspeckled/plugins/configuration/capybara' if defined?(::Capybara) require 'rspeckled/plugins/configuration/capybara_screenshot' if defined?(::Capybara::Screenshot) require 'rspeckled/plugins/configuration/carrier_wave' if defined?(::CarrierWave) require 'rspeckled/plugins/configuration/database_cleaner' if defined?(::DatabaseCleaner) require 'rspeckled/plugins/configuration/devise' if defined?(::Devise) require 'rspeckled/plugins/configuration/elasticsearch' if defined?(::Elasticsearch) require 'rspeckled/plugins/configuration/email_spec' if defined?(::EmailSpec) require 'rspeckled/plugins/configuration/factory_bot' if defined?(::FactoryBot) require 'rspeckled/plugins/configuration/fakeredis' if defined?(::FakeRedis) require 'rspeckled/plugins/configuration/mongoid' if defined?(::Mongoid) require 'rspeckled/plugins/configuration/omniauth' if defined?(::OmniAuth) require 'rspeckled/plugins/configuration/recaptcha' if defined?(::Recaptcha) require 'rspeckled/plugins/configuration/selenium_webdriver' if defined?(::Selenium::WebDriver) require 'rspeckled/plugins/configuration/shoulda' if defined?(::Shoulda::Matchers) require 'rspeckled/plugins/configuration/sidekiq' if defined?(::Sidekiq) require 'rspeckled/plugins/configuration/test_after_commit' if defined?(::TestAfterCommit) require 'rspeckled/plugins/configuration/vcr' if defined?(::VCR) require 'rspeckled/plugins/configuration/warden' if defined?(::Warden) require 'rspeckled/plugins/configuration/webmock' if defined?(::WebMock) require 'rspeckled/plugins/configuration/wisper' if defined?(::Wisper) ################################################################################ # Hooks # # These are the hooks around specs that are either required or are best # practices for a given gem based on the gem's README. # # Some of these would happen on every spec. In those cases we just check to see # if the constant exists. In other cases we only want it to happen if the test # has specific metadata. In those cases we load it regardless because we want # the user to get an error if the required libraries are not loaded. # # THE ORDER OF SOME OF THESE HOOKS MATTERS! # require 'rspeckled/plugins/hooks/garbage_collection' require 'rspeckled/plugins/hooks/request' require 'rspeckled/plugins/hooks/timecop' require 'rspeckled/plugins/hooks/action_mailer' if defined?(::ActionMailer) require 'rspeckled/plugins/hooks/authentication' require 'rspeckled/plugins/hooks/bullet' if defined?(::Bullet) require 'rspeckled/plugins/hooks/capybara' require 'rspeckled/plugins/hooks/carrier_wave' require 'rspeckled/plugins/hooks/database_cleaner' if defined?(::DatabaseCleaner) require 'rspeckled/plugins/hooks/devise' if defined?(::Devise) require 'rspeckled/plugins/hooks/dox' require 'rspeckled/plugins/hooks/elasticsearch' require 'rspeckled/plugins/hooks/factory_bot' if defined?(::FactoryBot) require 'rspeckled/plugins/hooks/foreign_keys' require 'rspeckled/plugins/hooks/redis' if defined?(::Redis) require 'rspeckled/plugins/hooks/referehencible' require 'rspeckled/plugins/hooks/rspec_mocks' require 'rspeckled/plugins/hooks/selenium_webdriver' require 'rspeckled/plugins/hooks/sidekiq' require 'rspeckled/plugins/hooks/singletons' require 'rspeckled/plugins/hooks/stripe' require 'rspeckled/plugins/hooks/vcr' require 'rspeckled/plugins/hooks/warden' if defined?(::Warden) require 'rspeckled/plugins/hooks/webmock' ################################################################################ # Extensions # # These are the more opinionated bits that involve gems. # # Add 'sap' Kernel Method for Amazing puts Debugging require 'rspeckled/plugins/extensions/awesome_print' # Properly Configure Puma and Setup Headed/Headless Chrome/Firefix Adapters require 'rspeckled/plugins/extensions/capybara' if defined?(::Capybara) # Register a Faraday Middleware for Amazing Request/Response Logging require 'rspeckled/plugins/extensions/faraday' if defined?(::Faraday::Response::Middleware) && defined?(::Faraday::Response) # Registers Fixtures for Mocking OAuth Responses from Common Services (Facebook, Twitter, etc) require 'rspeckled/plugins/extensions/omniauth' if defined?(::OmniAuth) # Setup for APIs by Always Allowing 'id' and Fail Fast By Raising on Unpermitted Parameters require 'rspeckled/plugins/extensions/strong_parameters' if defined?(::ActionController::Parameters) # Register Matchers Which Ignore Trailing UUID/GUIDs in URLs require 'rspeckled/plugins/extensions/vcr' if defined?(::VCR) ################################################################################ # Automatic Gem Requirements # RSpec.configure do |config| config.when_first_matching_example_defined(:email) do unless defined?(::EmailSpec) fail LoadError, "Add 'email_spec' to your gemspec for Gemfile to use the :email metadata" end end config.when_first_matching_example_defined(:time_mock) do unless defined?(::Timecop) fail LoadError, "Add 'timecop' to your gemspec for Gemfile to use the :time_mock metadata" end end config.when_first_matching_example_defined(:vcr) do unless defined?(::VCR) fail LoadError, "Add 'vcr' to your gemspec for Gemfile to use the :vcr metadata" end end config.when_first_matching_example_defined(:webmock) do unless defined?(::WebMock) fail LoadError, "Add 'webmock' to your gemspec for Gemfile to use the :webmock metadata" end end end