diff --git a/README.markdown b/README.markdown index 264a180..f1210c0 100644 --- a/README.markdown +++ b/README.markdown @@ -1,36 +1,13 @@ -GemTemplate -=========== +Question +======== -A gem template for new projects. +Ask questions from Auto. -Requirements ------------- +Install +------- -
-sudo gem install stencil --source http://gemcutter.org
-
- -Setup the template ------------------- - -You only have to do this once. - -
-git clone git@github.com:winton/gem_template.git
-cd gem_template
-stencil
-
- -Setup a new project -------------------- - -Do this for every new project. +This plugin is automatically installed when you install the auto gem.
-mkdir my_project
-git init
-stencil gem_template
-rake rename
-
- -The last command does a find-replace (gem\_template -> my\_project) on files and filenames. \ No newline at end of file +sudo gem install auto --source http://gemcutter.org + \ No newline at end of file diff --git a/bin/gem_template b/bin/gem_template deleted file mode 100644 index 2ab65da..0000000 --- a/bin/gem_template +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby - -$:.push File.expand_path("#{File.dirname(__FILE__)}/../lib") -require 'gem_template' diff --git a/gemspec.rb b/gemspec.rb index 81dcfe2..ebeb210 100644 --- a/gemspec.rb +++ b/gemspec.rb @@ -1,12 +1,13 @@ -GEM_NAME = 'gem_template' +GEM_NAME = 'auto-question' GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*'] GEM_SPEC = Gem::Specification.new do |s| # == CONFIGURE == s.author = "Winton Welsh" s.email = "mail@wintoni.us" s.homepage = "http://github.com/winton/#{GEM_NAME}" - s.summary = "" + s.summary = "Ask questions from Auto" # == CONFIGURE == + s.add_dependency('auto', '=0.1.2') s.executables << GEM_NAME s.extra_rdoc_files = [ "README.markdown" ] s.files = GEM_FILES.to_a @@ -14,5 +15,5 @@ s.name = GEM_NAME s.platform = Gem::Platform::RUBY s.require_path = "lib" - s.version = "0.1.0" -end \ No newline at end of file + s.version = "0.0.1" +end diff --git a/lib/auto/question.rb b/lib/auto/question.rb new file mode 100644 index 0000000..eb0ac71 --- /dev/null +++ b/lib/auto/question.rb @@ -0,0 +1,70 @@ +module Auto + module Question + + def after_question(key=nil, value=nil, &block) + Questions.after_question(key, value, &block) + end + + def before_question(key=nil, value=nil, &block) + Questions.before_question(key, value, &block) + end + + def questions(hash={}, &block) + q = Questions + hash.each do |key, value| + q[key] = value + if before_question(key, value) + yield if block_given? + after_question(key, value) + end + end + q.questions + end + alias :question :questions + alias :q :questions + + class Questions + + cattr_accessor :questions + @@questions = {} + + class < "q1", :q2 => "q2" + end + end + + before(:each) do + @r = Runner.new + end + + it 'should store questions' do + run + @r.run do + q.should == { + :q1 => "q1" , + :q2 => "q2" + } + end + end + + it 'should trigger a "before question" callback' do + questions = {} + @r.before_question do |key, value| + questions[key] = value + end + run + questions.should == { :q1 => "q1", :q2 => "q2" } + end + + it 'should trigger an "after question" callback' do + questions = {} + @r.after_question do |key, value| + questions[key] = value + end + run + questions.should == { :q1 => "q1", :q2 => "q2" } + end + + it 'should not trigger "after question" if a "before question" callback returns false' do + @r.before_question { |key, value| false } + @r.after_question do |key, value| + true.should == false # fail test + end + run + end + + it 'should yield to a block if specified' do + @r.run do + q :q1 => "q1", :q2 => "q2" do + q[:q1].should == "q1" + q[:q2].should == "q2" + end + end + end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 88df6fd..4865f95 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,11 +2,11 @@ SPEC = File.dirname(__FILE__) $:.unshift File.expand_path("#{SPEC}/../lib") -require 'gem_template' +require 'auto/require' require 'pp' -Spec::Runner.configure do |config| -end +# Manually add this plugin +Auto::Plugins.add File.expand_path("#{SPEC}/../") # For use with rspec textmate bundle def debug(object) @@ -14,3 +14,6 @@ def debug(object) puts object.pretty_inspect.gsub('<', '<').gsub('>', '>') puts "" end + +Spec::Runner.configure do |config| +end \ No newline at end of file