Sha256: ef0f44284a023266399719bfb40bab311d7c5c44bd86eaa95ba52258e5e8f3b2

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'
require 'routemaster/cli/top_level'
require 'webmock/rspec'

describe Routemaster::CLI::Sub, type: :cli do
  before { allow_bus_pulse 'bus.dev', 's3cr3t' }

  describe 'add' do
    context 'with correct arguments' do
      let(:argv) { %w[sub add https://my-service.dev cats dogs -b bus.dev -t s3cr3t] }

      it { 
        expect(client).to receive(:subscribe).with(topics: %w[cats dogs], callback: 'https://my-service.dev')
        perform
      }
    end
  end

  describe 'del' do
    context 'with a list of topics' do
      let(:argv) { %w[sub del cats dogs -b bus.dev -t s3cr3t] }
      it { 
        expect(client).to receive(:unsubscribe).with('cats', 'dogs')
        perform
      }
    end

    context 'without arguments' do
      let(:argv) { %w[sub del -b bus.dev -t s3cr3t] }
      it { 
        expect(client).to receive(:unsubscribe_all).with(no_args)
        perform
      }
    end
  end

  describe 'list' do
    context 'with correct arguments' do
      let(:argv) { %w[sub list -b bus.dev -t s3cr3t] }
      before {
        allow(client).to receive(:monitor_subscriptions).and_return([
          Routemaster::Client::Subscription.new(
            'subscriber' => 'service--f000-b44r-b44r',
            'callback' => 'https://serviced.dev',
            'topics' => %w[cats dogs],
            'events' => {
              'queued' => 1234
            })
        ])
      }

      it { 
        expect(client).to receive(:monitor_subscriptions).with(no_args)
        perform
      }
      it {
        expect { perform }.to change { stdout.string }.to a_string_matching(/service--f000-b44r-b44r/)
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
routemaster-client-3.1.1 spec/cli/sub_spec.rb