Skip to content
This repository
Browse code

add an --init switch to the rspec command

- Closes #430.
  • Loading branch information...
commit 3f482b7707863b17cbc71786de0c5b0507260989 1 parent 9e9f8a4
Peter Schröder phoet authored dchelimsky committed
1  lib/rspec/core.rb
@@ -16,6 +16,7 @@
16 16 require 'rspec/core/world'
17 17 require 'rspec/core/configuration'
18 18 require 'rspec/core/command_line_configuration'
  19 +require 'rspec/core/project_initializer'
19 20 require 'rspec/core/option_parser'
20 21 require 'rspec/core/drb_options'
21 22 require 'rspec/core/configuration_options'
5 lib/rspec/core/option_parser.rb
@@ -78,6 +78,11 @@ def parser(options)
78 78 exit
79 79 end
80 80
  81 + parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
  82 + ProjectInitializer.new(cmd).run
  83 + exit
  84 + end
  85 +
81 86 parser.on("--tty", "Used internally by rspec when sending commands to other processes") do |o|
82 87 options[:tty] = true
83 88 end
49 lib/rspec/core/project_initializer.rb
... ... @@ -0,0 +1,49 @@
  1 +module RSpec
  2 + module Core
  3 + class ProjectInitializer
  4 + attr_reader :command
  5 +
  6 + def initialize(cmd)
  7 + @command = cmd
  8 + end
  9 +
  10 + def run
  11 + FileUtils.mkdir_p 'spec'
  12 + File.open 'spec/spec_helper.rb', 'w+' do |file|
  13 + file.write <<-FILE
  14 +require 'rspec'
  15 +
  16 +RSpec.configure do |c|
  17 + c.mock_with :rspec
  18 +end
  19 + FILE
  20 + end
  21 + File.open 'spec/example_spec.rb', 'w+' do |file|
  22 + file.write <<-FILE
  23 +require 'spec_helper'
  24 +
  25 +describe 'example' do
  26 +
  27 + # let(:test_data) { 'testo' }
  28 +
  29 + # before do
  30 + # some_setup_stuff
  31 + # end
  32 +
  33 + # context 'doing something' do
  34 + # it 'should behave like i want to' do
  35 + # it.should be_true
  36 + # end
  37 + # end
  38 +
  39 + pending 'please remove this example and add your own spec!'
  40 +
  41 +end
  42 + FILE
  43 + end
  44 +
  45 + puts 'now run: rspec spec'
  46 + end
  47 + end
  48 + end
  49 +end

0 comments on commit 3f482b7

Please sign in to comment.
Something went wrong with that request. Please try again.