123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Rails::Railtie

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rails::Railtie
Instance Chain:
self, Rails::Railtie
Inherits: Rails::Railtie
  • Object
Defined in: rspec-rails/lib/rspec-rails.rb

Overview

Railtie to hook into ::RSpec::Rails.

Instance Method Summary

Instance Method Details

#config_default_preview_path(options) (private)

See additional method definition at line 51.

[ GitHub ]

  
# File 'rspec-rails/lib/rspec-rails.rb', line 57

def config_default_preview_path(options)
  return unless options.preview_paths.empty?

  options.preview_paths << "#{::Rails.root}/spec/mailers/previews"
end

#config_preview_path?(options) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-rails/lib/rspec-rails.rb', line 40

def config_preview_path?(options)
  # We cannot use `respond_to?(:show_previews)` here as it will always
  # return `true`.
  if options.show_previews.nil?
    options.show_previews = ::Rails.env.development?
  else
    options.show_previews
  end
end

#setup_preview_path(app) (private)

[ GitHub ]

  
# File 'rspec-rails/lib/rspec-rails.rb', line 33

def setup_preview_path(app)
  return unless supports_action_mailer_previews?(app.config)

  options = app.config.action_mailer
  config_default_preview_path(options) if config_preview_path?(options)
end

#supports_action_mailer_previews?(config) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-rails/lib/rspec-rails.rb', line 64

def supports_action_mailer_previews?(config)
  # These checks avoid loading `ActionMailer`. Using `defined?` has the
  # side-effect of the class getting loaded if it is available. This is
  # problematic because loading `ActionMailer::Base` will cause it to
  # read the config settings; this is the only time the config is read.
  # If the config is loaded now, any settings declared in a config block
  # in an initializer will be ignored.
  #
  # If the action mailer railtie has not been loaded then `config` will
  # not respond to the method. However, we cannot use
  # `config.action_mailer.respond_to?(:preview_path)` here as it will
  # always return `true`.
  config.respond_to?(:action_mailer)
end