Skip to content
This repository
Browse code

add an --init switch to the rspec command

  • Loading branch information...
commit 4d2b4ff637384502d5653388f7c04b64cf2fc153 1 parent 728814b
Peter Schröder phoet authored
1  lib/rspec/core.rb
@@ -15,6 +15,7 @@
15 15 require 'rspec/core/world'
16 16 require 'rspec/core/configuration'
17 17 require 'rspec/core/command_line_configuration'
  18 +require 'rspec/core/project_initializer'
18 19 require 'rspec/core/option_parser'
19 20 require 'rspec/core/configuration_options'
20 21 require 'rspec/core/command_line'
5 lib/rspec/core/option_parser.rb
@@ -63,6 +63,11 @@ def parser(options)
63 63 options[:formatters].last << o
64 64 end
65 65
  66 + parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
  67 + ProjectInitializer.new(cmd).run
  68 + exit
  69 + end
  70 +
66 71 parser.on_tail('-h', '--help', "You're looking at it.") do
67 72 puts parser
68 73 exit
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 4d2b4ff

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