Class: RSpec::Core::ProjectInitializer
- Inherits:
-
Object
- Object
- RSpec::Core::ProjectInitializer
- Defined in:
- lib/rspec/core/project_initializer.rb
Instance Method Summary collapse
- #create_dot_rspec_file ⇒ Object
- #create_spec_helper_file ⇒ Object
- #delete_if_confirmed(path, message) ⇒ Object
-
#initialize(arg = nil) ⇒ ProjectInitializer
constructor
A new instance of ProjectInitializer.
- #report_creating(file) ⇒ Object
- #report_exists(file) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(arg = nil) ⇒ ProjectInitializer
Returns 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
#create_dot_rspec_file ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec/core/project_initializer.rb', line 23 def create_dot_rspec_file if File.exist?('.rspec') report_exists('.rspec') else report_creating('.rspec') File.open('.rspec','w') do |f| f.write "--color\n--format progress\n" end end end |
#create_spec_helper_file ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rspec/core/project_initializer.rb', line 37 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 "# This file was generated by the `rspec --init` command. Conventionally, all\n# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.\n# Require this file using `require \"spec_helper.rb\"` to ensure that it is only\n# loaded once.\n#\n# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration\nRSpec.configure do |config|\n config.treat_symbols_as_metadata_keys_with_true_values = true\n config.run_all_when_everything_filtered = true\n config.filter_run :focus\nend\n" end end end |
#delete_if_confirmed(path, message) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rspec/core/project_initializer.rb', line 61 def delete_if_confirmed(path, ) if File.exist?(path) puts puts puts puts " delete #{path}? [y/n]" FileUtils.rm_rf(path) if gets =~ /y/i end end |
#report_creating(file) ⇒ Object
75 76 77 |
# File 'lib/rspec/core/project_initializer.rb', line 75 def report_creating(file) puts " create #{file}" end |
#report_exists(file) ⇒ Object
71 72 73 |
# File 'lib/rspec/core/project_initializer.rb', line 71 def report_exists(file) puts " exist #{file}" end |
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspec/core/project_initializer.rb', line 8 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", " RSpec registers its own discover.rb with Autotest, so autotest/discover.rb is\n no longer needed.\n MESSAGE\n\n delete_if_confirmed(\"lib/tasks/rspec.rake\", <<-MESSAGE)\n If the file in lib/tasks/rspec.rake is the one generated by rspec-rails-1x,\n you can get rid of it, as it is no longer needed with rspec-2.\n MESSAGE\nend\n") |