Skip to content

Commit

Permalink
Added tests for options on say and ask
Browse files Browse the repository at this point in the history
  • Loading branch information
plamoni committed Nov 30, 2011
1 parent 90865bf commit 15d199d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/cora_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/support/test_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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?"
Expand Down

0 comments on commit 15d199d

Please sign in to comment.