Sha256: 85d753358347f2a7c57c8f6ac7fdbeadee580b5cb68d6ce897a5055378592282

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require_relative '../../../../test_helper'

module Troo
  module Commands
    describe Show do
      let(:described_class) { Show }
      let(:klass)           { stub(type: :resource_type) }
      let(:id)              {}
      let(:type)            { :card }
      let(:id)              { '1' }
      let(:default)         { false }
      let(:resource)        {}
      let(:presenter)       { stub }

      before do
        API::Client.stubs(:perform)
        @card = Fabricate.build(:card, default: default)
        klass.stubs(:retrieve).returns(resource)
        Presenters::Card.stubs(:new).returns(presenter)
        presenter.stubs(:show).returns(@card.name)
      end

      after { database_cleanup }

      describe '.dispatch' do
        subject { described_class.dispatch(klass, id) }

        it { subject.must_be_instance_of(String) }

        context 'when a resource ID is provided' do
          context 'and the resource exists' do
            let(:resource) { @card }

            it 'presents the cards' do
              subject.must_match(/#{@card.name}/)
            end
          end

          context 'but the resource does not exist' do
            it 'returns a polite message' do
              subject.must_match(/cannot be found/)
            end
          end
        end

        context 'when a resource ID is not provided' do
          let(:id) {}

          context 'and a default resource is set' do
            let(:default) { true }
            let(:resource) { @card }

            it 'presents the cards' do
              subject.must_match(/#{@card.name}/)
            end
          end

          context 'and a default resource is not set' do
            it 'returns a polite message' do
              subject.must_match(/to set a default/)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troo-0.0.15 test/lib/troo/cli/commands/show_test.rb
troo-0.0.14 test/lib/troo/cli/commands/show_test.rb
troo-0.0.13 test/lib/troo/cli/commands/show_test.rb