Sha256: 9547a012566365b22ea4ba5733b14da3f5ff334f338184800917be2fa5ae75d3

Contents?: true

Size: 1.94 KB

Versions: 13

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

class EncodesTest < Test::Unit::TestCase
  context "An Encodes includer" do
    setup do
      @enc = Enc.new
    end

    context "ruby request encoder" do
      should "return BERT-RPC encoded request" do
        bert = "\203h\004d\000\004calld\000\005mymodd\000\005myfunl\000\000\000\003a\001a\002a\003j"
        assert_equal bert, @enc.encode_ruby_request(t[:call, :mymod, :myfun, [1, 2, 3]])
      end
    end

    context "bert response decoder" do
      should "return response when reply" do
        req = @enc.encode_ruby_request(t[:reply, [1, 2, 3]])
        res = @enc.decode_bert_response(req)
        assert_equal [1, 2, 3], res
      end

      should "return nil when noreply" do
        req = @enc.encode_ruby_request(t[:noreply])
        res = @enc.decode_bert_response(req)
        assert_equal nil, res
      end

      should "raise a ProtocolError error when protocol level error is returned" do
        req = @enc.encode_ruby_request(t[:error, [:protocol, 1, "class", "invalid", []]])
        assert_raises(BERTRPC::ProtocolError) do
          @enc.decode_bert_response(req)
        end
      end

      should "raise a ServerError error when server level error is returned" do
        req = @enc.encode_ruby_request(t[:error, [:server, 1, "class", "invalid", []]])
        assert_raises(BERTRPC::ServerError) do
          @enc.decode_bert_response(req)
        end
      end

      should "raise a UserError error when user level error is returned" do
        req = @enc.encode_ruby_request([:error, [:user, 1, "class", "invalid", []]])
        assert_raises(BERTRPC::UserError) do
          @enc.decode_bert_response(req)
        end
      end

      should "raise a ProxyError error when proxy level error is returned" do
        req = @enc.encode_ruby_request([:error, [:proxy, 1, "class", "invalid", []]])
        assert_raises(BERTRPC::ProxyError) do
          @enc.decode_bert_response(req)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
bertrpc-1.3.1 test/encodes_test.rb
fd-bertrpc-1.3.1 test/encodes_test.rb
fd-bertrpc-1.3.0 test/encodes_test.rb
bertrpc-1.3.0 test/encodes_test.rb
bertrpc-1.2.1 test/encodes_test.rb
bertrpc-1.2.0 test/encodes_test.rb
bertrpc-0.4.2 test/encodes_test.rb
bertrpc-1.1.2 test/encodes_test.rb
bertrpc-0.4.1 test/encodes_test.rb
bertrpc-1.1.1 test/encodes_test.rb
bertrpc-1.1.0 test/encodes_test.rb
bertrpc-1.0.0 test/encodes_test.rb
bertrpc-0.4.0 test/encodes_test.rb