Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored delay logic into RateController

  • Loading branch information...
commit 40eb0c198666875404e863aea8d6766d624ead07 1 parent 32a46b8
Robert Chatley authored
8 lib/extreme_startup/question_factory.rb
View
@@ -47,6 +47,14 @@ def delay_before_next
else 20
end
end
+
+ def was_answered_correctly
+ result == "correct"
+ end
+
+ def was_answered_wrongly
+ result == "wrong"
+ end
def display_result
"\tquestion: #{self.to_s}\n\tanswer: #{answer}\n\tresult: #{result}"
12 lib/extreme_startup/quiz_master.rb
View
@@ -5,7 +5,17 @@ module ExtremeStartup
class RateController
def wait_for_next_request(question)
- sleep question.delay_before_next
+ sleep delay_before_next_request(question)
+ end
+
+ def delay_before_next_request(question)
+ if (question.was_answered_correctly)
+ return 5
+ end
+ if (question.was_answered_wrongly)
+ return 10
+ end
+ return 20
end
end
34 spec/extreme_startup/rate_controller_spec.rb
View
@@ -0,0 +1,34 @@
+require 'spec_helper'
+require 'extreme_startup/quiz_master'
+
+module ExtremeStartup
+ describe RateController do
+ let(:controller) { RateController.new }
+
+ it "delays 5 seconds after correct answers" do
+ controller.delay_before_next_request(FakeAnswer.new(:correct)).should == 5
+ end
+
+ it "delays 10 seconds after wrong answers" do
+ controller.delay_before_next_request(FakeAnswer.new(:wrong)).should == 10
+ end
+
+ it "delays 20 seconds after error responses" do
+ controller.delay_before_next_request(FakeAnswer.new(:error)).should == 20
+ end
+
+ end
+
+ class FakeAnswer
+ def initialize(result)
+ @result = result
+ end
+ def was_answered_correctly
+ @result == :correct
+ end
+ def was_answered_wrongly
+ @result == :wrong
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.