File: feature_generator.rb

package info (click to toggle)
ruby-rspec-rails 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: ruby: 10,881; sh: 198; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'generators/rspec'

module Rspec
  module Generators
    # @private
    class FeatureGenerator < Base
      class_option :feature_specs, type: :boolean, default: true,  desc: "Generate feature specs"
      class_option :singularize,   type: :boolean, default: false, desc: "Singularize the generated feature"

      def generate_feature_spec
        return unless options[:feature_specs]

        template template_name, target_path('features', class_path, filename)
      end

      def template_name
        options[:singularize] ? 'feature_singular_spec.rb' : 'feature_spec.rb'
      end

      def filename
        if options[:singularize]
          "#{file_name.singularize}_spec.rb"
        else
          "#{file_name}_spec.rb"
        end
      end
    end
  end
end