Sha256: 11c22529717bacc74cf2ebe8590843c8eedb2ca16bde01ea11ccf2cbfb8f932c

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module RSpec
  module Core
    class ProjectInitializer
      def initialize(arg=nil)
        @arg = arg
      end

      def run
        warn "The --configure option no longer needs any arguments, so #{@arg} was ignored." if @arg
        create_spec_helper_file
        create_dot_rspec_file
        delete_if_confirmed("autotest/discover.rb", <<-MESSAGE)
  RSpec registers its own discover.rb with Autotest, so autotest/discover.rb is
  no longer needed.
        MESSAGE

        delete_if_confirmed("lib/tasks/rspec.rake", <<-MESSAGE)
  If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,
  you can get rid of it, as it is no longer needed with rspec-2.
        MESSAGE
      end

      def create_dot_rspec_file
        if File.exist?('.rspec')
          report_exists('.rspec')
        else
          report_creating('.rspec')
          FileUtils.touch('.rspec')
        end
      end

      def create_spec_helper_file
        if File.exist?('spec/spec_helper.rb')
          report_exists("spec/spec_helper.rb")
        else
          report_creating("spec/spec_helper.rb")
          FileUtils.mkdir('spec') unless File.exist?('spec') && File.directory?('spec')
          FileUtils.touch('spec/spec_helper.rb')
        end
      end

      def delete_if_confirmed(path, message)
        if File.exist?(path)
          puts
          puts message
          puts
          puts "  delete   #{path}? [y/n]"
          FileUtils.rm_rf(path) if gets =~ /y/i
        end
      end

      def report_exists(file)
        puts "   exist   #{file}"
      end

      def report_creating(file)
        puts "  create   #{file}"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-core-2.8.0.rc2 lib/rspec/core/project_initializer.rb