Sha256: 53c1447183b54715f8c559f0d083ac83b81442481f8ec14a75ac3976eb22c671

Contents?: true

Size: 881 Bytes

Versions: 17

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

module Gemsmith
  module Generators
    # Generates RSpec support.
    class Rspec < Base
      def run
        if configuration.dig :generate, :rspec
          install_templates
        else
          remove_rake_lines
        end
      end

      private

      def remove_rake_lines
        cli.gsub_file "#{gem_name}/Rakefile", /require.+rspec.+\n/, ""
        cli.gsub_file "#{gem_name}/Rakefile", /RSpec.+\n/, ""
      end

      def install_templates
        template "#{rspec_root}/spec_helper.rb.tt"
        install_rails_helper
        template "#{rspec_root}/support/shared_contexts/temp_dir.rb.tt"
      end

      def rspec_root
        "%gem_name%/spec"
      end

      def install_rails_helper
        return unless configuration.dig :generate, :engine

        template "#{rspec_root}/rails_helper.rb.tt"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gemsmith-15.5.0 lib/gemsmith/generators/rspec.rb
gemsmith-15.4.0 lib/gemsmith/generators/rspec.rb
gemsmith-15.3.0 lib/gemsmith/generators/rspec.rb
gemsmith-15.2.0 lib/gemsmith/generators/rspec.rb
gemsmith-15.1.1 lib/gemsmith/generators/rspec.rb
gemsmith-15.1.0 lib/gemsmith/generators/rspec.rb
gemsmith-15.0.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.11.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.10.1 lib/gemsmith/generators/rspec.rb
gemsmith-14.10.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.9.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.8.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.7.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.6.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.5.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.4.0 lib/gemsmith/generators/rspec.rb
gemsmith-14.3.0 lib/gemsmith/generators/rspec.rb