Sha256: b2330a2ffa7e9041c0ebb31154d3f4ef2643b8e1db8b509023cb6351f5968d5b

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require 'rabbit_rpc'

describe RabbitRPC::RequestHandler do
  let!(:sample_service) do
    class UserService
      def self.create
        'woot'
      end
    end
  end
  let(:message)         { RabbitRPC::Message.new 'UserService.create' }
  let(:one_way_message) { RabbitRPC::Message.new 'UserService.one_way_create' }
  let(:invalid_message) { RabbitRPC::Message.new 'Usvice.create' }
  let(:invalid_args_message) { RabbitRPC::Message.new 'UserService.create', 'args' }

  describe '#execute' do
    it 'succesfully executes the request method' do
      RabbitRPC::RequestHandler.new(message.pack).execute.should == 'woot'
    end

    it 'identifies whether the method expects a response' do
      handler = RabbitRPC::RequestHandler.new(message.pack)
      handler.execute
      handler.one_way.should be_false

      handler = RabbitRPC::RequestHandler.new(one_way_message.pack)
      handler.execute
      handler.one_way.should be_true
    end

    it 'returns an exception message in the event of errors' do
      RabbitRPC::RequestHandler.new(invalid_message.pack).execute.should == {
        ok: false,
        message: 'Error processing request'
      }
    end

    it 'returns an error notifying an Argument error' do
      RabbitRPC::RequestHandler.new(invalid_args_message.pack).execute.should == {
        ok: false,
        message: 'wrong number of arguments (1 for 0)'
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_rpc-0.0.2 spec/request_handler_spec.rb