Class: RSpec::Core::ProjectInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/project_initializer.rb

Instance Method Summary (collapse)

Constructor Details

- (ProjectInitializer) initialize(arg = nil)

A new instance of ProjectInitializer



4
5
6
# File 'lib/rspec/core/project_initializer.rb', line 4

def initialize(arg=nil)
  @arg = arg
end

Instance Method Details

- (Object) create_dot_rspec_file



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rspec/core/project_initializer.rb', line 22

def create_dot_rspec_file
  if File.exist?('.rspec')
    report_exists('.rspec')
  else
    report_creating('.rspec')
    File.open('.rspec','w') do |f|
      f.write <<-CONTENT
--color
--format progress
CONTENT
    end
  end
end

- (Object) create_spec_helper_file



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rspec/core/project_initializer.rb', line 36

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_p('spec')
    File.open('spec/spec_helper.rb','w') do |f|
      f.write <<-CONTENT
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = 'random'
end
CONTENT
    end
  end
end

- (Object) delete_if_confirmed(path, message)



66
67
68
69
70
71
72
73
74
# File 'lib/rspec/core/project_initializer.rb', line 66

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

- (Object) report_creating(file)



80
81
82
# File 'lib/rspec/core/project_initializer.rb', line 80

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

- (Object) report_exists(file)



76
77
78
# File 'lib/rspec/core/project_initializer.rb', line 76

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

- (Object) run



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec/core/project_initializer.rb', line 8

def run
  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