Skip to content
Browse files

It should be possible to override default input parameters

  • Loading branch information...
1 parent 42f68b1 commit 1a722c37d40c5301f4e91ff449e4a945f5917f1f @benlangfeld benlangfeld committed
Showing with 10 additions and 3 deletions.
  1. +2 −2 lib/adhearsion-asr/controller_methods.rb
  2. +8 −1 spec/adhearsion-asr/controller_methods_spec.rb
View
4 lib/adhearsion-asr/controller_methods.rb
@@ -35,7 +35,7 @@ def listen(opts = {})
{ url: opts[:grammar_url] }
else
language = opts.delete(:language) || AdhearsionASR::Plugin.config[:language]
- grammar = opts[:grammar]
+ grammar = opts.delete(:grammar)
grammar ||= RubySpeech::GRXML.draw root: 'main', language: language do
rule id: 'main', scope: 'public' do
one_of do
@@ -47,7 +47,7 @@ def listen(opts = {})
end
{ value: grammar }
end
- input_options = opts.merge(grammar: grammar_opts, min_confidence: AdhearsionASR::Plugin.config[:min_confidence])
+ input_options = {grammar: grammar_opts, min_confidence: AdhearsionASR::Plugin.config[:min_confidence]}.merge(opts)
prompts = Array(opts.delete :prompt)
timeout = opts.has_key?(:timeout) ? opts.delete(:timeout) : AdhearsionASR::Plugin.config[:timeout]
[:prompt, :options, :grammar_url, :timeout].each { |o| input_options.delete o }
View
9 spec/adhearsion-asr/controller_methods_spec.rb
@@ -89,7 +89,7 @@ def expect_component_complete_event
it "can execute a grammar by url" do
expect_component_complete_event
url = "http://foo.com/bar.grxml"
- input_component = Punchblock::Component::Input.new grammar: { url: url }, min_confidence: 0.5
+ input_component.grammar = {url: url}
expect_component_execution input_component
subject.listen grammar_url: url
end
@@ -112,6 +112,13 @@ def expect_component_complete_event
subject.listen options: %w{yes no}, language: 'en-gb'
end
+ it "allows specifying a min confidence" do
+ expect_component_complete_event
+ input_component.min_confidence = 0.1
+ expect_component_execution input_component
+ subject.listen options: %w{yes no}, min_confidence: 0.1
+ end
+
it "raises ArgumentError when not provided options, a grammar or a grammar URL" do
expect { subject.listen }.to raise_error(ArgumentError, "You must provide a grammar, a grammar URL or a set of options")
end

0 comments on commit 1a722c3

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