spec/larynx/prompt_spec.rb in larynx-0.1.4 vs spec/larynx/prompt_spec.rb in larynx-0.1.5

- old
+ new

@@ -37,11 +37,32 @@ it "should return call input without termchar" do call.input += ['1', '#'] @prompt.input.should == '1' end end + context "command" do + it "should return command object for command name" do + cmd = new_prompt.command + cmd.should be_kind_of(Larynx::AppCommand) + cmd.command.should == 'speak' + end + end + context "before callback" do + it "should clear input on execution if no bargein allowed" do + call.input << '1' + before_callback new_prompt(:speak => 'hello', :bargein => false) + call.input.should be_empty + end + + it "should clear input on execution if bargein allowed" do + call.input << '1' + before_callback new_prompt(:speak => 'hello', :bargein => true) + call.input.should_not be_empty + end + end + context "prompt_finished?" do it "should return true if input length reached" do prompt = new_prompt(:speak => 'hello', :length => 1) call.input << '1' prompt.prompt_finished?.should be_true @@ -64,27 +85,32 @@ call.input += ['1', '2'] prompt.prompt_finished?.should be_true end end - context "command" do - it "should return command object for command name" do - cmd = new_prompt.command - cmd.should be_kind_of(Larynx::AppCommand) - cmd.command.should == 'speak' - end - end - context "before callback" do - it "should clear input on execution" do - call.input << '1' - before_callback new_prompt - call.input.should be_empty + context "after callback" do + context "bargein" do + it 'should clear input before prompt status evaluated if false' do + prompt = new_prompt(:speak => 'hello', :length => 1, :bargein => false) + call.input << '1' + em do + after_callback prompt + prompt.prompt_finished?.should be_false + done + end + end + + it 'should not clear input before prompt status evaluated if true' do + prompt = new_prompt(:speak => 'hello', :length => 1, :bargein => true) { done } + call.input << '1' + em do + after_callback prompt + end + end end - 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) @@ -144,12 +170,13 @@ call.should_receive(:remove_observer).with(prompt) prompt.finalise end it "should clear input" do + call.input << '1' prompt = new_prompt - call.should_receive(:clear_input) prompt.finalise + call.input.should be_empty end end context "user callback" do it "should be passed input argument equal to call input" do