Sha256: 76b0bfcd3a3f7f42806eca9ab7aae264d7b6bd5e147b15c2dbc086eaccf99702

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

# encoding: utf-8
require 'spec_helper'

module RubyAMI
  describe AGIResultParser do
    subject { described_class.new result_string }

    context 'with something that does not match the valid format' do
      let(:result_string) { 'foobar' }

      it 'should raise ArgumentError on creation' do
        expect { subject }.to raise_error(ArgumentError, /format/)
      end
    end

    context 'with a simple result with no data' do
      let(:result_string) { "200%20result=123%0A" }

      its(:code)      { should == 200 }
      its(:result)    { should == 123 }
      its(:data)      { should == '' }
      its(:data_hash) { should == nil }
    end

    context 'with a simple unescaped result with no data' do
      let(:result_string) { "200 result=123" }

      its(:code)      { should == 200 }
      its(:result)    { should == 123 }
      its(:data)      { should == '' }
      its(:data_hash) { should == nil }
    end

    context 'with a result and data in parens' do
      let(:result_string) { "200%20result=-123%20(timeout)%0A" }

      its(:code)      { should == 200 }
      its(:result)    { should == -123 }
      its(:data)      { should == 'timeout' }
      its(:data_hash) { should == nil }
    end

    context 'with a result and key-value data' do
      let(:result_string) { "200%20result=123%20foo=bar%0A" }

      its(:code)      { should == 200 }
      its(:result)    { should == 123 }
      its(:data)      { should == 'foo=bar' }
      its(:data_hash) { should == {'foo' => 'bar'} }
    end

    context 'with a 5xx error' do
      let(:result_string) { "510%20Invalid%20or%20unknown%20command%0A" }

      its(:code)      { should == 510 }
      its(:result)    { should be_nil }
      its(:data)      { should == 'Invalid or unknown command' }
      its(:data_hash) { should be_nil }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby_ami-2.4.0 spec/ruby_ami/agi_result_parser_spec.rb
ruby_ami-2.3.0 spec/ruby_ami/agi_result_parser_spec.rb
ruby_ami-2.2.1 spec/ruby_ami/agi_result_parser_spec.rb
ruby_ami-2.2.0 spec/ruby_ami/agi_result_parser_spec.rb
ruby_ami-2.1.0 spec/ruby_ami/agi_result_parser_spec.rb
ruby_ami-1.3.4 spec/ruby_ami/agi_result_parser_spec.rb