Sha256: b730f6b54acfb78a489722a3755f56afdb62855b6480d6a7cc468cda3f508d92

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 KB

Contents

require 'generators/rspec'

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

      class_option :template_engine,  desc: "Template engine to generate view files"
      class_option :request_specs,    type: :boolean, default: true, desc: "Generate request specs"
      class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
      class_option :view_specs,       type: :boolean, default: true, desc: "Generate view specs"
      class_option :routing_specs,    type: :boolean, default: false, desc: "Generate routing specs"

      def generate_request_spec
        return unless options[:request_specs]

        template 'request_spec.rb',
                 target_path('requests', class_path, "#{file_name}_spec.rb")
      end

      def generate_controller_spec
        return unless options[:controller_specs]

        template 'controller_spec.rb',
                 target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
      end

      def generate_view_specs
        return if actions.empty? && behavior == :invoke
        return unless options[:view_specs] && options[:template_engine]

        empty_directory File.join("spec", "views", file_path)

        actions.each do |action|
          @action = action
          template 'view_spec.rb',
                   target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
        end
      end

      def generate_routing_spec
        return if actions.empty?
        return unless options[:routing_specs]

        template 'routing_spec.rb',
                 target_path('routing', class_path, "#{file_name}_routing_spec.rb")
      end
    end
  end
end

Version data entries

19 entries across 18 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/rspec-rails-7.1.0/lib/generators/rspec/controller/controller_generator.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rspec-rails-7.1.0/lib/generators/rspec/controller/controller_generator.rb
rspec-rails-7.1.0 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-7.0.2 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-7.0.1 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-7.0.0 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.5 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.4 lib/generators/rspec/controller/controller_generator.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rspec-rails-6.1.3/lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.3 lib/generators/rspec/controller/controller_generator.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rspec-rails-6.0.4/lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.2 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.1 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.1.0 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.0.4 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.0.3 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.0.2 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.0.1 lib/generators/rspec/controller/controller_generator.rb
rspec-rails-6.0.0 lib/generators/rspec/controller/controller_generator.rb