Skip to content

Commit

Permalink
add an --init switch to the rspec command
Browse files Browse the repository at this point in the history
- Closes #430.
  • Loading branch information
phoet authored and dchelimsky committed Nov 11, 2011
1 parent 9e9f8a4 commit 3f482b7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions lib/rspec/core/project_initializer.rb
Original file line number Diff line number Diff line change
@@ -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.