Skip to content
Browse files

Added tests for options on say and ask

  • Loading branch information...
1 parent 90865bf commit 15d199d3af0b0e66eb0d8bbbe02173195a59434c @plamoni plamoni committed Nov 29, 2011
Showing with 28 additions and 0 deletions.
  1. +18 −0 spec/cora_spec.rb
  2. +10 −0 spec/support/test_plugin.rb
View
18 spec/cora_spec.rb
@@ -20,6 +20,13 @@
end
end
+ context "say" do
+ it "responds to a say with options" do
+ subject.should_receive(:respond).with("test options", {option: "option"})
+ subject.process("options")
+ end
+ end
+
context "multiple state" do
it "doesn't respond to listeners that don't have the required state" do
subject.should_receive(:no_matches)
@@ -97,6 +104,17 @@ class TestPlugin2 < Cora::Plugin
subject.should_receive(:respond).with("You said: Answer 3", {})
subject.process("Answer 3")
end
+
+ it "can ask questions with options" do
+ subject.should_receive(:respond).with("Question with option", {prompt_for_response: true, option: "option"})
+ subject.process("ask option")
+ subject.process("plamoni")
+
+ random_num = rand(1000000)
+ subject.should_receive(:respond).with("Question with option", {prompt_for_response: true, option: random_num})
+ subject.process("ask option #{random_num}")
+ subject.process("plamoni")
+ end
end
context "confirming" do
View
10 spec/support/test_plugin.rb
@@ -4,6 +4,10 @@ class TestPlugin < Cora::Plugin
listen_for /test/ do
say "test!"
end
+
+ listen_for /^options$/ do
+ say "test options", {option: "option"}
+ end
listen_for /^foo$/ do
say "foo"
@@ -23,6 +27,12 @@ class TestPlugin < Cora::Plugin
answer = ask "Question 3"
say "You said: #{answer}"
end
+
+ listen_for /ask option[ ]?([0-9]*)/ do |numeric_option|
+ opt = "option"
+ opt = numeric_option.to_i if not numeric_option.empty?
+ answer = ask "Question with option", {option: opt}
+ end
listen_for /confirm something/ do
if confirm "Does confirm work?"

0 comments on commit 15d199d

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