spec/larynx/prompt_spec.rb in larynx-0.1.2 vs spec/larynx/prompt_spec.rb in larynx-0.1.3
- old
+ new
@@ -83,21 +83,22 @@
end
context "after callback" do
context "input completed" do
it "should not add timers if reached length" do
+ prompt = new_prompt
+ prompt.should_not_receive(:add_digit_timer)
+ prompt.should_not_receive(:add_input_timer)
call.input << '1'
- call.should_not_receive(:timer).with(:digit, anything())
- call.should_not_receive(:timer).with(:input, anything())
- after_callback new_prompt
+ after_callback prompt
end
it "should not add timers if termchar input" do
prompt = new_prompt(:speak => 'hello', :length => 2, :termchar => '#')
+ prompt.should_not_receive(:add_digit_timer)
+ prompt.should_not_receive(:add_input_timer)
call.input << '#'
- call.should_not_receive(:timer).with(:digit, anything())
- call.should_not_receive(:timer).with(:input, anything())
after_callback prompt
end
it "should finalise prompt" do
call.input << '#'
@@ -107,18 +108,19 @@
end
end
context "input not completed" do
it "should add timers" do
- call.should_receive(:timer).with(:digit, anything())
- call.should_receive(:timer).with(:input, anything())
- after_callback new_prompt
+ prompt = new_prompt
+ prompt.should_receive(:add_digit_timer)
+ prompt.should_receive(:add_input_timer)
+ after_callback prompt
end
it "should add itself as call observer" do
prompt = new_prompt
- call.stub!(:timer)
+ call.stub!(:add_timer)
after_callback prompt
call.observers.should include(prompt)
end
it "should finalise prompt" do
@@ -140,17 +142,31 @@
it "should remove prompt as call observer" do
prompt = new_prompt
call.should_receive(:remove_observer).with(prompt)
prompt.finalise
end
+
+ it "should clear input" do
+ prompt = new_prompt
+ call.should_receive(:clear_input)
+ prompt.finalise
+ end
end
context "user callback" do
it "should be passed input argument equal to call input" do
- prompt = new_prompt {|input| @callback = '1'}
+ prompt = new_prompt {|input| @callback = input }
call.input << '1'
after_callback prompt
@callback.should == '1'
+ end
+
+ it "should be passed input and result arguments if block arity is 2" do
+ prompt = new_prompt(:speak => '', :length => 1) {|input, result| @input = input; @result = result }
+ call.input << '1'
+ after_callback prompt
+ @input.should == '1'
+ @result.should be_true
end
end
context "interdigit timeout" do
it "should finalize prompt after specified number of seconds" do