Sha256: 252feac45aed2e59edfc76ce974e53b9a3140f6f0caa18e384a0b5a91e5aa31d

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

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

module Vedeu
  describe CommandRepository do
    let(:described_class) { CommandRepository }
    let(:input)           { }

    before do
      Command.create({ name:    'apple',
                       entity:   DummyCommand,
                       options: { keypress: 'a', keyword: 'apple' } })
      Command.create({ name:    'banana',
                       entity:   DummyCommand,
                       options: { keypress: 'b', keyword: 'banana' } })
    end

    after do
      CommandRepository.reset
    end

    describe '.by_keypress' do
      let(:subject) { described_class.by_keypress(input) }

      context 'when the command was found by keypress' do
        let(:input) { 'b' }

        it 'returns the Command instance' do
          subject.must_be_instance_of(Command)
        end

        it 'returns the correct command' do
          subject.name.must_equal('banana')
        end

        it 'returns the correct command' do
          subject.name.wont_equal('apple')
        end

        it 'returns the correct command' do
          subject.keypress.must_equal('b')
        end
      end
    end

    describe '.by_keyword' do
      let(:subject) { described_class.by_keyword(input) }

      context 'when the command was found by keyword' do
        let(:input) { 'apple' }

        it 'returns the Command instance' do
          subject.must_be_instance_of(Command)
        end

        it 'returns the correct command' do
          subject.keypress.must_equal('a')
        end

        it 'returns the correct command' do
          subject.keypress.wont_equal('b')
        end

        it 'returns the correct command' do
          subject.name.wont_equal('banana')
        end
      end
    end

    describe '.entity' do
      let(:subject) { described_class.entity }

      it 'returns Command' do
        subject.must_equal(Command)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.0.21 test/lib/vedeu/repository/command_repository_test.rb