Skip to content
Browse files

add an --init switch to the rspec command

  • Loading branch information...
1 parent 728814b commit 4d2b4ff637384502d5653388f7c04b64cf2fc153 @phoet phoet committed Jul 28, 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
@@ -15,6 +15,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/configuration_options'
require 'rspec/core/command_line'
View
5 lib/rspec/core/option_parser.rb
@@ -63,6 +63,11 @@ def parser(options)
options[:formatters].last << o
end
+ parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
+ ProjectInitializer.new(cmd).run
+ exit
+ end
+
parser.on_tail('-h', '--help', "You're looking at it.") do
puts parser
exit
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 4d2b4ff

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