diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2f8597f..fb8e56d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,12 +25,12 @@ jobs: - 3.2 - 3.1 rails: - - 6.1 # TODO: move to 7.2 + - 7.2 include: # Edge - { ruby: 'head', rails: 'edge', allow-fail: true } # Outdated - - { ruby: '3.0', rails: '6.1' } # TODO: move to 7.1 + - { ruby: '3.0', rails: '7.1' } - { ruby: '2.7', rails: '6' } # RSpec AR Expectations support Rails 7.1 since Ruby 3.0 - { ruby: '2.6', rails: '6' } - { ruby: '2.5', rails: '6' } diff --git a/.rspec b/.rspec index fdd4d9d8..e4d136b7 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1 @@ ---color ---order rand +--format progress diff --git a/Gemfile b/Gemfile index c6842495..5db18794 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'puma' platforms :ruby do if RUBY_VERSION >= "2.5.0" - gem 'sqlite3', '~> 1.4' + gem 'sqlite3' else gem 'sqlite3', '~> 1.3.6' end @@ -17,8 +17,6 @@ platforms :jruby do gem "activerecord-jdbcsqlite3-adapter" end -gem 'mongoid' - case rails_version = ENV['RAILS_VERSION'] when nil gem 'rails' @@ -28,6 +26,10 @@ else gem 'rails', "~> #{rails_version}.0" end +gem 'mongoid' unless + rails_version == 'edge' +gem 'active_model_serializers' + case RUBY_VERSION when '2.6'...'3.0' gem "turbo-rails", "<= 2.0.7" diff --git a/draper.gemspec b/draper.gemspec index b159217f..3ec083f5 100644 --- a/draper.gemspec +++ b/draper.gemspec @@ -29,7 +29,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec-activerecord-expectations' s.add_development_dependency 'minitest-rails' s.add_development_dependency 'capybara' - s.add_development_dependency 'active_model_serializers', '>= 0.10' s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' end diff --git a/spec/dummy/.rspec b/spec/dummy/.rspec index 5f164763..e4d136b7 100644 --- a/spec/dummy/.rspec +++ b/spec/dummy/.rspec @@ -1,2 +1 @@ ---color --format progress diff --git a/spec/dummy/app/decorators/mongoid_post_decorator.rb b/spec/dummy/app/decorators/mongoid_post_decorator.rb index 42d87e06..61596e42 100644 --- a/spec/dummy/app/decorators/mongoid_post_decorator.rb +++ b/spec/dummy/app/decorators/mongoid_post_decorator.rb @@ -1,4 +1,2 @@ -if defined?(Mongoid) - class MongoidPostDecorator < Draper::Decorator - end +class MongoidPostDecorator < Draper::Decorator end diff --git a/spec/dummy/app/models/admin.rb b/spec/dummy/app/models/admin.rb index 3bf08dd2..f1d81e6c 100644 --- a/spec/dummy/app/models/admin.rb +++ b/spec/dummy/app/models/admin.rb @@ -1,5 +1,3 @@ -if defined?(Devise) - class Admin - extend Devise::Models - end +class Admin + extend Devise::Models if defined? Devise end diff --git a/spec/dummy/app/models/mongoid_post.rb b/spec/dummy/app/models/mongoid_post.rb index aba35210..7ec46175 100644 --- a/spec/dummy/app/models/mongoid_post.rb +++ b/spec/dummy/app/models/mongoid_post.rb @@ -1,5 +1,3 @@ -if defined?(Mongoid) - class MongoidPost - include Mongoid::Document - end +class MongoidPost + include Mongoid::Document if defined? Mongoid end diff --git a/spec/dummy/app/models/post.rb b/spec/dummy/app/models/post.rb index 7bf61aa0..0cbe9171 100644 --- a/spec/dummy/app/models/post.rb +++ b/spec/dummy/app/models/post.rb @@ -1,5 +1,3 @@ -require 'turbo/broadcastable' if defined? Turbo::Broadcastable # HACK: looks weird, but works - class Post < ApplicationRecord # attr_accessible :title, :body diff --git a/spec/dummy/app/models/user.rb b/spec/dummy/app/models/user.rb index 04101867..8aba8c0f 100644 --- a/spec/dummy/app/models/user.rb +++ b/spec/dummy/app/models/user.rb @@ -1,5 +1,3 @@ -if defined?(Devise) - class User - extend Devise::Models - end +class User + extend Devise::Models if defined? Devise end diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 159f806c..e27e52b6 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,64 +1,34 @@ -require File.expand_path('../boot', __FILE__) - -def attempt_require(file) - require file -rescue LoadError -end +require_relative 'boot' require 'rails/all' -require 'draper' -attempt_require 'mongoid' -attempt_require 'devise' -attempt_require 'turbo-rails' -require 'active_model_serializers' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Kernel.silence_warnings do + Bundler.require(*Rails.groups) +end module Dummy class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Custom directories with classes and modules you want to be autoloadable. - # config.autoload_paths += %W(#{config.root}/extras) - - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named. - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" - - # Enable escaping HTML in JSON. - config.active_support.escape_html_entities_in_json = true - - # Use SQL instead of Active Record's schema dumper when creating the database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql + config.load_defaults Rails::VERSION::STRING.to_f - # Enforce whitelist mode for mass assignment. - # This will create an empty whitelist of attributes available for mass-assignment for all models - # in your app. As such, your models will need to explicitly whitelist or blacklist accessible - # parameters by using an attr_accessible or attr_protected declaration. - # config.active_record.whitelist_attributes = true + # For compatibility with applications that use this config + # config.action_controller.include_all_helpers = false # FIXME - # Enable the asset pipeline - # config.assets.enabled = true + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.try :autoload_lib, ignore: %w[assets tasks] # HACK for Rails below 7 - # Version of your assets, change this if you want to expire all your assets - # config.assets.version = '1.0' + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + # HACK: allows testing in production & development environments # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 80d91ee2..c2dd02e5 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,35 +1,78 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +require "active_support/core_ext/integer/time" - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local - # Print deprecation notices to the Rails logger + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false + + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise - config.eager_load = false + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] - # Raise exception on mass assignment protection for Active Record models - # config.active_record.mass_assignment_sanitizer = :strict + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true - # Do not compress assets - # config.assets.compress = false + # Highlight code that enqueued background job in logs. + # config.active_job.verbose_enqueue_logs = true - # Expands the lines which load the assets - # config.assets.debug = true + # Suppress logger output for asset requests. + # config.assets.quiet = true - config.active_storage.service = :local + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + # config.action_controller.raise_on_missing_callback_actions = true end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index fb828684..aaebc3ae 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -1,59 +1,102 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +require "active_support/core_ext/integer/time" - # Code is not reloaded between requests - config.cache_classes = true +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. - # Full error reports are disabled and caching is turned on + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true - config.eager_load = true + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + # config.public_file_server.enabled = false + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fall back to assets pipeline if a precompiled asset is missed. + # config.assets.compile = false - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" - # Specifies the header that your server uses for sending files - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # See everything in the log (default is :info) - # config.log_level = :debug + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new(STDOUT) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .tap { |logger| break ActiveSupport::TaggedLogging.new logger } - # Prepend all log lines with the following tags - # config.log_tags = [ :subdomain, :uuid ] + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] - # Use a different logger for distributed setups - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + # "info" includes generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") - # Use a different cache store in production + # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server - # config.action_controller.asset_host = "http://assets.example.com" + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "dummy_production" - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - # config.assets.precompile += %w( search.js ) + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false - # Enable threaded mode - # config.threadsafe! + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) + # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners - config.active_support.deprecation = :notify + # Don't log any deprecations. + config.active_support.report_deprecations = false - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false - config.active_storage.service = :local + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index de472e37..53df8948 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,35 +1,69 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +require "active_support/core_ext/integer/time" - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! - # Configure static asset server for tests with Cache-Control for performance - # config.serve_static_assets = true - # config.static_cache_control = "public, max-age=3600" +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. - # Show full error reports and disable caching + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } + + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates - config.action_dispatch.show_exceptions = false + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.active_job.queue_adapter = :test # TODO: remove alongside support for Rails below 7.2 - # Raise exception on mass assignment protection for Active Record models - # config.active_record.mass_assignment_sanitizer = :strict + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. + config.action_mailer.perform_caching = false - # Print deprecation notices to the stderr + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: "www.example.com" } + + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - config.eager_load = false + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise - config.active_job.queue_adapter = :test + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] - config.active_storage.service = :test + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + # config.action_controller.raise_on_missing_callback_actions = true end diff --git a/spec/dummy/config/initializers/draper.rb b/spec/dummy/config/initializers/draper.rb index 414d9d69..a33c1f8c 100644 --- a/spec/dummy/config/initializers/draper.rb +++ b/spec/dummy/config/initializers/draper.rb @@ -1,3 +1,5 @@ -Draper.configure do |config| - config.default_controller = BaseController +Rails.application.config.to_prepare do + Draper.configure do |config| + config.default_controller = BaseController + end end diff --git a/spec/dummy/spec/decorators/active_model_serializers_spec.rb b/spec/dummy/spec/decorators/active_model_serializers_spec.rb index ee83e24d..fc43dc8d 100644 --- a/spec/dummy/spec/decorators/active_model_serializers_spec.rb +++ b/spec/dummy/spec/decorators/active_model_serializers_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe Draper::CollectionDecorator do describe "#active_model_serializer" do diff --git a/spec/dummy/spec/decorators/post_decorator_spec.rb b/spec/dummy/spec/decorators/post_decorator_spec.rb index 7260e68b..37663aa6 100644 --- a/spec/dummy/spec/decorators/post_decorator_spec.rb +++ b/spec/dummy/spec/decorators/post_decorator_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe PostDecorator do let(:decorator) { PostDecorator.new(object) } diff --git a/spec/dummy/spec/jobs/publish_post_job_spec.rb b/spec/dummy/spec/jobs/publish_post_job_spec.rb index c809f42a..d3d14913 100644 --- a/spec/dummy/spec/jobs/publish_post_job_spec.rb +++ b/spec/dummy/spec/jobs/publish_post_job_spec.rb @@ -1,3 +1,5 @@ +require 'rails_helper' + RSpec.describe PublishPostJob, type: :job do let(:post) { Post.create.decorate } diff --git a/spec/dummy/spec/mailers/post_mailer_spec.rb b/spec/dummy/spec/mailers/post_mailer_spec.rb index 4ab0135d..17ae588e 100644 --- a/spec/dummy/spec/mailers/post_mailer_spec.rb +++ b/spec/dummy/spec/mailers/post_mailer_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe PostMailer do describe "#decorated_email" do diff --git a/spec/dummy/spec/models/application_spec.rb b/spec/dummy/spec/models/application_spec.rb index 5fed74b0..85ed4a45 100644 --- a/spec/dummy/spec/models/application_spec.rb +++ b/spec/dummy/spec/models/application_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe ApplicationRecord do it { expect(described_class.superclass).to eq ActiveRecord::Base } diff --git a/spec/dummy/spec/models/post_spec.rb b/spec/dummy/spec/models/post_spec.rb index 808000ac..51ce22a0 100644 --- a/spec/dummy/spec/models/post_spec.rb +++ b/spec/dummy/spec/models/post_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' require 'shared_examples/decoratable' RSpec.describe Post do diff --git a/spec/dummy/spec/rails_helper.rb b/spec/dummy/spec/rails_helper.rb new file mode 100644 index 00000000..f40ffd01 --- /dev/null +++ b/spec/dummy/spec/rails_helper.rb @@ -0,0 +1,69 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +require 'rspec/activerecord/expectations' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + abort e.to_s.strip +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + # config.fixture_paths = [ + # Rails.root.join('spec/fixtures') + # ] + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + # config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://rspec.info/features/6-0/rspec-rails + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") + + # Extra matchers + config.include RSpec::ActiveRecord::Expectations +end diff --git a/spec/dummy/spec/spec_helper.rb b/spec/dummy/spec/spec_helper.rb index 367bac66..36280f2d 100644 --- a/spec/dummy/spec/spec_helper.rb +++ b/spec/dummy/spec/spec_helper.rb @@ -1,11 +1,93 @@ -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rspec/rails' -require 'rspec/activerecord/expectations' - +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - config.expect_with(:rspec) {|c| c.syntax = :expect} + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 config.order = :random - include RSpec::ActiveRecord::Expectations + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed end diff --git a/spec/support/dummy_app.rb b/spec/support/dummy_app.rb index c205f86f..e2e1554c 100644 --- a/spec/support/dummy_app.rb +++ b/spec/support/dummy_app.rb @@ -50,7 +50,7 @@ def start_server yield Process.kill("KILL", out.pid) - File.delete("tmp/pids/server.pid") + File.delete("tmp/pids/server.pid") if File.exist?("tmp/pids/server.pid") end end end