<commit_before>require 'spec_helper'

module Punchblock
  module Translator
    class Asterisk
      module Component
        module Asterisk
          describe Input do
            let(:media_engine)    { nil }
            let(:translator)      { Punchblock::Translator::Asterisk.new mock('AMI'), mock('Client'), media_engine }
            let(:call)            { Punchblock::Translator::Asterisk::Call.new 'foo', translator }
            let(:command_options) { nil }

            let :command do
              Punchblock::Component::Input.new command_options
            end

            let :grammar do
              RubySpeech::GRXML.draw :mode => 'dtmf', :root => 'pin' do
                rule id: 'digit' do
                  one_of do
                    0.upto(9) { |d| item { d.to_s } }
                  end
                end

                rule id: 'pin', scope: 'public' do
                  item repeat: '2' do
                    ruleref uri: '#digit'
                  end
                end
              end
            end

            let :command_options do
              {

              }
            end

            subject { Input.new command, call }

            describe '#execute' do
              before { command.request! }

              context 'with a media engine of :unimrcp' do
                pending
                let(:media_engine) { :unimrcp }
              end

              context 'with a media engine of :asterisk' do
                let(:media_engine) { :asterisk }

                let(:command_opts) { {} }

                let :command_options do
                  { :mode => :dtmf, :grammar => { :value => grammar } }.merge(command_opts)
                end

                def ami_event_for_dtmf(digit, position)
                  RubyAMI::Event.new('DTMF').tap do |e|
                    e['Digit']  = digit.to_s
                    e['Start']  = position == :start ? 'Yes' : 'No'
                    e['End']    = position == :end ? 'Yes' : 'No'
                  end
                end

                def send_ami_events_for_dtmf(digit)
                  call.process_ami_event ami_event_for_dtmf(digit, :start)
                  call.process_ami_event ami_event_for_dtmf(digit, :end)
                end

                let(:reason) { command.complete_event(5).reason }

                describe "receiving DTMF events" do
                  before { subject.execute! }

                  context "when a match is found" do
                    before do
                      send_ami_events_for_dtmf 1
                      send_ami_events_for_dtmf 2
                    end<commit_msg>[BUGFIX] Fix a race condition in tests producing failures on JRuby<commit_after>require 'spec_helper'

module Punchblock
  module Translator
    class Asterisk
      module Component
        module Asterisk
          describe Input do
            let(:media_engine)    { nil }
            let(:translator)      { Punchblock::Translator::Asterisk.new mock('AMI'), mock('Client'), media_engine }
            let(:call)            { Punchblock::Translator::Asterisk::Call.new 'foo', translator }
            let(:command_options) { nil }

            let :command do
              Punchblock::Component::Input.new command_options
            end

            let :grammar do
              RubySpeech::GRXML.draw :mode => 'dtmf', :root => 'pin' do
                rule id: 'digit' do
                  one_of do
                    0.upto(9) { |d| item { d.to_s } }
                  end
                end

                rule id: 'pin', scope: 'public' do
                  item repeat: '2' do
                    ruleref uri: '#digit'
                  end
                end
              end
            end

            let :command_options do
              {

              }
            end

            subject { Input.new command, call }

            describe '#execute' do
              before { command.request! }

              context 'with a media engine of :unimrcp' do
                pending
                let(:media_engine) { :unimrcp }
              end

              context 'with a media engine of :asterisk' do
                let(:media_engine) { :asterisk }

                let(:command_opts) { {} }

                let :command_options do
                  { :mode => :dtmf, :grammar => { :value => grammar } }.merge(command_opts)
                end

                def ami_event_for_dtmf(digit, position)
                  RubyAMI::Event.new('DTMF').tap do |e|
                    e['Digit']  = digit.to_s
                    e['Start']  = position == :start ? 'Yes' : 'No'
                    e['End']    = position == :end ? 'Yes' : 'No'
                  end
                end

                def send_ami_events_for_dtmf(digit)
                  call.process_ami_event ami_event_for_dtmf(digit, :start)
                  call.process_ami_event ami_event_for_dtmf(digit, :end)
                end

                let(:reason) { command.complete_event(5).reason }

                describe "receiving DTMF events" do
                  before { subject.execute }

                  context "when a match is found" do
                    before do
                      send_ami_events_for_dtmf 1
                      send_ami_events_for_dtmf 2
                    end
{'fraction_non_alphanumeric': 0.08675373134328358, 'fraction_numerical': 0.002238805970149254, 'mean_word_length': 1.2034525277435264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3110163', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1361, 'n_words': 349}