Sha256: bc65d753e844091b590f99ed9411ff6b478394bcd552eda54b75a819a0d2b36b

Contents?: true

Size: 1006 Bytes

Versions: 9

Compression:

Stored size: 1006 Bytes

Contents

require 'generators/rspec'
require "rspec/rails/feature_check"

module Rspec
  module Generators
    # @private
    class MailerGenerator < Base
      argument :actions, type: :array, default: [], banner: "method method"

      def generate_mailer_spec
        file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
        template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
      end

      def generate_fixtures_files
        actions.each do |action|
          @action, @path = action, File.join(file_path, action)
          template "fixture", target_path("fixtures", @path)
        end
      end

      def generate_preview_files
        return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?

        file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
        template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rspec-rails-7.1.0 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-7.0.2 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-7.0.1 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-7.0.0 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-6.1.5 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-6.1.4 lib/generators/rspec/mailer/mailer_generator.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rspec-rails-6.1.3/lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-6.1.3 lib/generators/rspec/mailer/mailer_generator.rb
rspec-rails-6.1.2 lib/generators/rspec/mailer/mailer_generator.rb