<commit_before>require 'spec_helper'

module Adhearsion
  module Punchblock
    module Commands
      describe Record do
        include PunchblockCommandTestHelpers

        describe "#record" do
          let(:options) do
            {
              :start_beep => true,
              :max_duration => 5000
            }
          end
          let(:component) { Punchblock::Component::Record.new options }
          let(:response)  { Punchblock::Event::Complete.new }

          describe "with :async => true and an :on_complete callback" do
            let(:callback) { lambda { |rec| @rec.push rec } }

            before do
              expect_component_execution_asynchronously component
              @rec = Queue.new
              options.merge! :async => true, :on_complete => callback
              mock_execution_environment.record options
              component.request!
              component.execute!
            end

            it "should execute the callback" do
              component.add_event response
              Timeout::timeout 5 do
                @rec.pop.should == response
              end
            end

            describe "when the callback raises an exception" do
              before { TestException = Class.new StandardError }
              let(:callback) { lambda { |rec| raise TestException } }

              it "should pass the exception to the events system" do
                flexmock(Events).should_receive(:trigger).once.with(['exception'], TestException)
                component.add_event response
              end
            end
          end

          describe "with :async => false" do
            before do
              expect_component_execution component
              component.request!
              component.execute!
              component.add_event response
              @rec = Queue.new
              mock_execution_environment.record(options.merge(:async => false)) { |rec| @rec.push rec }
            end

            it 'should execute a passed block' do
              Timeout::timeout 5 do
                @rec.pop.should == response
              end
            end
          end<commit_msg>Fix a trivial test failure<commit_after>require 'spec_helper'

module Adhearsion
  module Punchblock
    module Commands
      describe Record do
        include PunchblockCommandTestHelpers

        describe "#record" do
          let(:options) do
            {
              :start_beep => true,
              :max_duration => 5000
            }
          end
          let(:component) { Punchblock::Component::Record.new options }
          let(:response)  { Punchblock::Event::Complete.new }

          describe "with :async => true and an :on_complete callback" do
            let(:callback) { lambda { |rec| @rec.push rec } }

            before do
              expect_component_execution_asynchronously component
              @rec = Queue.new
              options.merge! :async => true, :on_complete => callback
              mock_execution_environment.record options
              component.request!
              component.execute!
            end

            it "should execute the callback" do
              component.add_event response
              Timeout::timeout 5 do
                @rec.pop.should == response
              end
            end

            describe "when the callback raises an exception" do
              before { TestException = Class.new StandardError }
              let(:callback) { lambda { |rec| raise TestException } }

              it "should pass the exception to the events system" do
                flexmock(Events).should_receive(:trigger).once.with(:exception, TestException)
                component.add_event response
              end
            end
          end

          describe "with :async => false" do
            before do
              expect_component_execution component
              component.request!
              component.execute!
              component.add_event response
              @rec = Queue.new
              mock_execution_environment.record(options.merge(:async => false)) { |rec| @rec.push rec }
            end

            it 'should execute a passed block' do
              Timeout::timeout 5 do
                @rec.pop.should == response
              end
            end
          end
{'fraction_non_alphanumeric': 0.0700827205882353, 'fraction_numerical': 0.0027573529411764708, 'mean_word_length': 1.5322862129144852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3743269', 'n_tokens_mistral': 1021, 'n_tokens_neox': 972, 'n_words': 289}