Skip to content
Browse files

Specs and Docs around Question

  • Loading branch information...
1 parent ad7a7b7 commit 195c0601fe78fe8a322c69e4f4626305ebb16ef4 @burtlo committed
Showing with 109 additions and 9 deletions.
  1. +34 −6 lib/question.rb
  2. +11 −3 lib/quiz.rb
  3. +64 −0 spec/question_spec.rb
View
40 lib/question.rb
@@ -5,30 +5,58 @@ module Robut::Plugin::Quiz::Question
# This regex will find all the questions and parameters specified with the question
GROUP_REGEX = /['"]([^'"]+)['"]/
- def initialize(sender,request)
+ #
+ # Initialize the question with the asker of the question and the details about
+ # question that is being asked.
+ #
+ # @param [String] sender the name of the person asking the question.
+ # @param [String] question_with_parameters this is the remaining question and
+ # parameters left on the question posed to the chat room.
+ #
+ def initialize(sender,question_with_parameters)
@sender = sender
- process_question(request)
+ process_question(question_with_parameters)
end
- def process_question(request)
+ #
+ # This is used internally to process the the question and parameters that sent
+ # to the question.
+ #
+ # @param [String] question_with_parameters this is the remaining question and
+ # parameters left on the question posed to the chat room.
+ #
+ def process_question(question_with_parameters)
- parsed_parameters = request.scan(GROUP_REGEX)
+ parsed_elements = question_with_parameters.scan(GROUP_REGEX)
- @question = parsed_parameters.first
+ @question = parsed_elements.first.first
# After the target, question type, question, and answer length has been determined
# look at all the single quoted items to find the list of parameters if there are any
- @parameters = parsed_parameters[1..-1].flatten
+ @parameters = parsed_elements[1..-1].flatten
end
+ #
+ # @return [String] the question that is being asked.
def to_s
@question
end
+ #
+ # Ask the question that has been proposed.
+ #
+ # @return [String] a string that asks the question in the chat room.
def ask
"@all Question '#{@question}'"
end
+ #
+ # Maintains a list of the results that have been captured for the question.
+ # The hash that is maintained would be used with the user's nickname as the
+ # key and the value as a response to the question.
+ #
+ # @return [Hash] used for storing responses from the various senders.
+ #
def captured_results
@captured_results ||= {}
end
View
14 lib/quiz.rb
@@ -5,8 +5,9 @@ class Robut::Plugin::Quiz
include Robut::Plugin
def usage
- [ "#{at_nick} ask 'Should we break for lunch?'",
- "#{at_nick} ask polar 'Should I continue the presentation?' for 3 minutes",
+ [
+ "#{at_nick} ask 'Should we break for lunch?'",
+ "#{at_nick} ask for 3 minutes 'Should I continue the presentation?'",
]
end
@@ -45,8 +46,15 @@ def enqueue_the_question(sender,question)
(store["quiz::question::queue"] ||= []) << [sender,question]
end
+ #
+ # Return a new thread which will pop questions in the queue of questions
+ #
def quizmaster
- @@quizmaster ||= Thread.new { pop_the_question until there_are_no_more_questions_to_pop }
+ if not defined?(@@quizmaster) or @@quizmaster.nil? or !@@quizmaster.alive?
+ @@quizmaster = Thread.new { pop_the_question until there_are_no_more_questions_to_pop }
+ end
+
+ @@quizmaster
end
def pop_the_question
View
64 spec/question_spec.rb
@@ -0,0 +1,64 @@
+require "spec_helper"
+
+describe Robut::Plugin::Quiz::Question do
+
+ class TestQuestion
+ include Robut::Plugin::Quiz::Question
+
+ attr_accessor :question, :parameters, :captured_results
+
+ end
+
+ let(:question) { "Do you like questions?" }
+ let(:question_with_params) { "'#{question}', 'yes', 'no' 'maybe'" }
+
+ subject { TestQuestion.new "sender", question_with_params }
+
+ describe "#to_s" do
+
+ it "should be the question that was asked" do
+ subject.to_s.should == question
+ end
+
+ end
+
+ describe "#ask" do
+
+ it "should be the default statement to ask question" do
+ subject.ask.should == "@all Question '#{question}'"
+ end
+
+ end
+
+ describe "#process_question" do
+
+ context "when a question with parameters" do
+
+ it "should find the question" do
+ subject.process_question question_with_params
+ subject.question.should == question
+ end
+
+ it "should find the parameters" do
+ subject.process_question question_with_params
+ subject.parameters.should == [ 'yes', 'no', 'maybe' ]
+ end
+
+ end
+
+ context "when only a question has been provided" do
+
+ it "should find the question" do
+ subject.process_question "'Ask more questions?'"
+ subject.question.should == 'Ask more questions?'
+ end
+
+ end
+
+ end
+
+ describe "subject" do
+
+ end
+
+end

0 comments on commit 195c060

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