123456789_123456789_123456789_123456789_123456789_

Class: Rspec::Generators::InstallGenerator Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rails::Generators::Base
Instance Chain:
self, Rails::Generators::Base
Inherits: Rails::Generators::Base
  • Object
Defined in: rspec-rails/lib/generators/rspec/install/install_generator.rb

Class Method Summary

Instance Method Summary

Class Method Details

.source_root

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 17

def self.source_root
  @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Method Details

#append_default_path(dot_rspec_path) (private)

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 70

def append_default_path(dot_rspec_path)
  append_to_file dot_rspec_path,
                 "--default-path #{default_path}"
end

#copy_rails_files

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 29

def copy_rails_files
  template 'spec/rails_helper.rb', "#{default_path}/rails_helper.rb"
end

#copy_spec_files

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 21

def copy_spec_files
  Dir.mktmpdir do |dir|
    generate_rspec_init dir
    template File.join(dir, '.rspec'), '.rspec'
    directory File.join(dir, 'spec'), default_path
  end
end

#default_path (private)

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 75

def default_path
  options[:default_path]
end

#generate_rspec_init(tmpdir) (private)

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 35

def generate_rspec_init(tmpdir)
  initializer = ::RSpec::Core::ProjectInitializer.new(
    destination: tmpdir,
    report_stream: StringIO.new
  )
  initializer.run

  spec_helper_path = File.join(tmpdir, 'spec', 'spec_helper.rb')

  replace_generator_command(spec_helper_path)
  remove_warnings_configuration(spec_helper_path)

  unless default_path == "spec"
    dot_rspec_path = File.join(tmpdir, '.rspec')

    append_default_path(dot_rspec_path)
  end
end

#remove_warnings_configuration(spec_helper_path) (private)

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 61

def remove_warnings_configuration(spec_helper_path)
  empty_line = '^\n'
  comment_line = '^\s*#.+\n'
  gsub_file spec_helper_path,
            /#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
            '',
            verbose: false
end

#replace_generator_command(spec_helper_path) (private)

[ GitHub ]

  
# File 'rspec-rails/lib/generators/rspec/install/install_generator.rb', line 54

def replace_generator_command(spec_helper_path)
  gsub_file spec_helper_path,
            'rspec --init',
            'rails generate rspec:install',
            verbose: false
end