diff --git a/Gemfile b/Gemfile index 0c911b9..1e78761 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,5 @@ group :test do gem 'rspec' gem 'guard' gem 'guard-rspec' + gem 'growl_notify' end \ No newline at end of file diff --git a/Guardfile b/Guardfile index f14df08..23347b4 100644 --- a/Guardfile +++ b/Guardfile @@ -2,7 +2,7 @@ guard 'rspec', :version => 2, :cli => '--color --format d' do watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } end diff --git a/lib/quiz.rb b/lib/quiz.rb index 5ed3fd3..eb71ab1 100644 --- a/lib/quiz.rb +++ b/lib/quiz.rb @@ -24,10 +24,28 @@ def usage def handle(time, sender_nick, message) # check to see if the user is asking the bot a question + request = words(message).join(" ") - if sent_to_me? message and is_a_question? message + if sent_to_me? message and is_a_valid_question? request + request =~ QUESTION_REGEX + question_type = Regexp.last_match(1) || 'choice' + question = Regexp.last_match(2) + parameters = Regexp.last_match(3) + answer_length = Regexp.last_match(4) || '2' + puts %{ #{question_type} } + + case question_type + when 'polar' + handle_polar(question,parameters,answer_length) + when 'choice' + handle_choice(question,parameters,answer_length) + when 'scale' + handle_scale(question,parameters,answer_length) + else + puts "failed to find a question type" + end end @@ -38,8 +56,20 @@ def handle(time, sender_nick, message) end + def handle_polar(question,parameters,length) + puts "#{question} #{parameters} #{length}" + end + + def handle_choice(question,parameters,length) + puts "#{question} #{parameters} #{length}" + end + + def handle_scale(question,parameters,length) + puts "#{question} #{parameters} #{length}" + end + def is_a_valid_question? message - message =~ QUESTION_REGEX + QUESTION_REGEX =~ message end end diff --git a/spec/quiz_spec.rb b/spec/quiz_spec.rb index 8401dee..8adb201 100644 --- a/spec/quiz_spec.rb +++ b/spec/quiz_spec.rb @@ -24,5 +24,31 @@ end end + + describe "#handle" do + + context "when a polar question is asked" do + + it "should find all the components of the question" do + + subject.should_receive(:handle_polar).with('Should I continue the presentation?',nil,'3') + subject.handle Time.now,'person',"@quizmaster ask polar 'Should I continue the presentation?' for 3 minutes" + + end + + end + + context "when a choice question is asked" do + + it "should find all the components of the question" do + + subject.should_receive(:handle_choice).with('What should I talk about next?',"'x', 'y', 'z'",'2') + subject.handle Time.now,'person',"@quizmaster ask choice 'What should I talk about next?', 'x', 'y', 'z'" + + end + + end + + end end \ No newline at end of file