Sha256: dbf674a68d6c19c1a8d923ec6e4a3719451b2e6bc977317dfa56dd2c1779edc2

Contents?: true

Size: 1.27 KB

Versions: 34

Compression:

Stored size: 1.27 KB

Contents

RSpec::Support.require_rspec_support "directory_maker"

module RSpec
  module Core
    # @private
    # Generates conventional files for an rspec project
    class ProjectInitializer
      attr_reader :destination, :stream, :template_path

      DOT_RSPEC_FILE = '.rspec'
      SPEC_HELPER_FILE =  'spec/spec_helper.rb'

      def initialize(opts={})
        @destination = opts.fetch(:destination, Dir.getwd)
        @stream = opts.fetch(:report_stream, $stdout)
        @template_path = opts.fetch(:template_path) do
          File.expand_path("../project_initializer", __FILE__)
        end
      end

      def run
        copy_template DOT_RSPEC_FILE
        copy_template SPEC_HELPER_FILE
      end

    private

      def copy_template(file)
        destination_file = File.join(destination, file)
        return report_exists(file) if File.exist?(destination_file)

        report_creating(file)
        RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(destination_file))
        File.open(destination_file, 'w') do |f|
          f.write File.read(File.join(template_path, file))
        end
      end

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

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

Version data entries

34 entries across 31 versions & 8 rubygems

Version Path
opal-rspec-0.8.0 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.7.1 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.7.0 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.6.2 rspec-core/lib/rspec/core/project_initializer.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/lib/rspec/core/project_initializer.rb
opal-rspec-0.6.1 rspec-core/lib/rspec/core/project_initializer.rb
opal-rspec-0.6.0 rspec-core/lib/rspec/core/project_initializer.rb
opal-rspec-0.6.0.beta1 rspec-core/lib/rspec/core/project_initializer.rb
opal-connect-rspec-0.5.0 rspec-core/lib/rspec/core/project_initializer.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/project_initializer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-core-3.1.1/lib/rspec/core/project_initializer.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-core-3.1.1/lib/rspec/core/project_initializer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-core-3.1.1/lib/rspec/core/project_initializer.rb
opal-rspec-0.5.0 rspec-core/lib/rspec/core/project_initializer.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/project_initializer.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-core-3.1.7/lib/rspec/core/project_initializer.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-core-3.1.7/lib/rspec/core/project_initializer.rb