Skip to content
Browse files

add an --init switch to the rspec command

- Closes #430.
  • Loading branch information...
1 parent 9e9f8a4 commit 3f482b7707863b17cbc71786de0c5b0507260989 @phoet phoet committed with dchelimsky Nov 10, 2011
Showing with 55 additions and 0 deletions.
  1. +1 −0 lib/rspec/core.rb
  2. +5 −0 lib/rspec/core/option_parser.rb
  3. +49 −0 lib/rspec/core/project_initializer.rb
View
1 lib/rspec/core.rb
@@ -16,6 +16,7 @@
require 'rspec/core/world'
require 'rspec/core/configuration'
require 'rspec/core/command_line_configuration'
+require 'rspec/core/project_initializer'
require 'rspec/core/option_parser'
require 'rspec/core/drb_options'
require 'rspec/core/configuration_options'
View
5 lib/rspec/core/option_parser.rb
@@ -78,6 +78,11 @@ def parser(options)
exit
end
+ parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
+ ProjectInitializer.new(cmd).run
+ exit
+ end
+
parser.on("--tty", "Used internally by rspec when sending commands to other processes") do |o|
options[:tty] = true
end
View
49 lib/rspec/core/project_initializer.rb
@@ -0,0 +1,49 @@
+module RSpec
+ module Core
+ class ProjectInitializer
+ attr_reader :command
+
+ def initialize(cmd)
+ @command = cmd
+ end
+
+ def run
+ FileUtils.mkdir_p 'spec'
+ File.open 'spec/spec_helper.rb', 'w+' do |file|
+ file.write <<-FILE
+require 'rspec'
+
+RSpec.configure do |c|
+ c.mock_with :rspec
+end
+ FILE
+ end
+ File.open 'spec/example_spec.rb', 'w+' do |file|
+ file.write <<-FILE
+require 'spec_helper'
+
+describe 'example' do
+
+ # let(:test_data) { 'testo' }
+
+ # before do
+ # some_setup_stuff
+ # end
+
+ # context 'doing something' do
+ # it 'should behave like i want to' do
+ # it.should be_true
+ # end
+ # end
+
+ pending 'please remove this example and add your own spec!'
+
+end
+ FILE
+ end
+
+ puts 'now run: rspec spec'
+ end
+ end
+ end
+end

0 comments on commit 3f482b7

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