Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a (very ugly) test for terminating output when input is received

  • Loading branch information...
commit da7370ec298cbc336f27af4747f48a6080cd0a8b 1 parent 0bbd257
@benlangfeld benlangfeld authored
Showing with 44 additions and 10 deletions.
  1. +44 −10 spec/adhearsion-asr/controller_methods_spec.rb
View
54 spec/adhearsion-asr/controller_methods_spec.rb
@@ -67,10 +67,11 @@ def expect_component_execution(component, fail = false)
end
end
- def expect_component_complete_event(reason = nil)
- reason ||= Punchblock::Component::Input::Complete::Match.new :nlsml => nlsml
- complete_event = Punchblock::Event::Complete.new :reason => reason
- Punchblock::Component::Input.any_instance.should_receive(:complete_event).at_least(:once).and_return(complete_event)
+ let(:input_complete_reason) { Punchblock::Component::Input::Complete::Match.new nlsml: nlsml }
+ let(:input_complete_event) { Punchblock::Event::Complete.new reason: input_complete_reason }
+
+ def expect_component_complete_event
+ Punchblock::Component::Input.any_instance.should_receive(:complete_event).at_least(:once).and_return(input_complete_event)
end
it "sends the correct input component" do
@@ -107,11 +108,10 @@ def expect_component_complete_event(reason = nil)
end
context "when a nomatch occurrs" do
- before do
- expect_component_complete_event Punchblock::Component::Input::Complete::NoMatch.new
- end
+ let(:input_complete_reason) { Punchblock::Component::Input::Complete::NoMatch.new }
it "should return a response of nil and a status of nomatch" do
+ expect_component_complete_event
expect_component_execution input_component
result = subject.listen options: %w{yes no}
result.response.should be nil
@@ -132,10 +132,13 @@ def expect_component_complete_event(reason = nil)
Punchblock::Component::Output.new ssml: ssml
end
+ let(:output_complete_event) do
+ reason = Punchblock::Component::Output::Complete::Success.new
+ Punchblock::Event::Complete.new reason: reason
+ end
+
def expect_output_completion
- reason ||= Punchblock::Component::Output::Complete::Success.new
- complete_event = Punchblock::Event::Complete.new :reason => reason
- Punchblock::Component::Output.any_instance.should_receive(:complete_event).at_least(:once).and_return(complete_event)
+ Punchblock::Component::Output.any_instance.should_receive(:complete_event).at_least(:once).and_return(output_complete_event)
end
it "plays the correct output" do
@@ -146,6 +149,37 @@ def expect_output_completion
subject.listen prompt: prompt, options: %w{yes no}
end
+ it "should terminate the output when the input completes" do
+ latch = CountDownLatch.new 1
+
+ expect_message_waiting_for_response input_component
+ input_component.request!
+ input_component.execute!
+ Punchblock::Component::Input.should_receive(:new).and_return(input_component)
+ expect_message_waiting_for_response output_component
+ output_component.request!
+ output_component.execute!
+ Punchblock::Component::Output.should_receive(:new).and_return(output_component)
+
+ thread = Thread.new do
+ result = subject.listen prompt: prompt, options: %w{yes no}
+ latch.countdown!
+ result
+ end
+ latch.wait(1).should be_false
+
+ output_component.should_receive(:stop!).once do
+ output_component.add_event output_complete_event
+ end
+
+ input_component.add_event input_complete_event
+ input_component.trigger_event_handler input_complete_event
+
+ latch.wait(1).should be_true
+
+ thread.join.should_not be_nil
+ end
+
context "with a collection of prompts" do
let(:prompts) { ["/srv/foo.mp3", "Press 3 or 5 to make something happen."] }
Please sign in to comment.
Something went wrong with that request. Please try again.