Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add an --init switch to the rspec command #430

Closed
wants to merge 1 commit into from

4 participants

@phoet

i always need to search the rspec documentation (one of the several repos until i find the real wiki) for how to set up my rspec stuff. so i thought it might be a good idea to add an --init switch which does some minor scaffolding for the project.

the fork is just a simple implementation, so that you get the idea.

@dchelimsky
Owner

There was a request for this a while back, but it never got prioritized. I think it's a good idea, but there are a few things we need to consider. This needs to integrate seamlessly with rails generate rspec:install so rspec does the right thing in non-rails and rails projects. Also, this should generate a .rspec file (empty), which is how rspec tells autotest that this is an rspec project.

@phoet

i will have a look into the rails generate stuff and see if i find a generic approach

@conradwt

Has there been any movement with adding an --init option to the rspec command in such a way that it can be reused by the rails generate rspec:install?

@phoet

no. i stopped looking for the integration. so i will close this request.

@phoet phoet closed this
@dchelimsky dchelimsky reopened this
@dchelimsky
Owner

I still think this is a good idea, so I've reopened it. Not sure when it'll happen but I'd like to keep it on the radar.

@dchelimsky
Owner

A while back we added a --configure option which generates a .rspec file if there isn't one, and also deletes (on confirmation) autotest/discover.rb, which is not longer used. It was designed in a very autotest-centric way, with the notion that we'd add other options later. My thinking is we can repurpose --configure to be more generic by default: don't require any argument; don't make it about autotest; generate .rspec if not present; generate spec directory if not present; generate spec/spec_helper.rb if not present. Still offer to delete autotest/discover.rb and perhaps lib/tasks/rspec.rake (which would help people upgrading from rails-2 to rails-3. We could also change the name to --init, though I'm not sure if that's necessary or not.

Thoughts?

@dchelimsky
Owner

@phoet - looks like you deleted your fork so I can't merge this. If you restore it I'll merge it. I have some changes I want to make, but this way we'd have your contribution attributed correctly.

@phoet

i will see if i can find it somewhere...

@dchelimsky
Owner

what's odd is that github still shows the diff. Would be nice if I could download it via the github UI :)

@phoet

i guess that they store it internally as a git patch

@benedikt

I guess you're looking for this: https://github.com/rspec/rspec-core/pull/430.patch :)

@dchelimsky
Owner

@benedikt - yes, thanks!

@dchelimsky
Owner

@benedikt - do you know how github stores that? i.e. if they do a git gc would this patch go away? Or is it actually stored with this repo (vs @phoet's)?

@benedikt

As far as I know they store it separately so you always have the history. I think they mentioned it in one of their talks on how they use pull requests themselves.

@dchelimsky
Owner

Thanks for the info (can't get to this until tonight, so hoping it will still be there :) )

@conradwt

@dchelimsky You can save the patch locally so that it's available when you need it. I have saved it locally just in the event it's not there tonight and I can mail it to you.

@dchelimsky
Owner

@conradwt - very kind of you - I have done the same, so you need not hold on to your copy :)

Cheers,
David

@dchelimsky
Owner
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky merge --configure and --init into a single command
- #430

- generates .rspec if not present
- generates spec/spec_helper if not present
- offers to delete obsolete autotest/discover.rb if present
- offers to delete obsolete lib/tasks/rspec.rake if present
3eff799
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky changelog for #430 8a613b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 28, 2011
  1. @phoet
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.