Sha256: f8cae2bf2ab0de70aea5cc33bcbbfb7dd2ae9060aa45f7edfa9d6d48a818fa72

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

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

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

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

    after { CommandRepository.reset }

    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

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.0.25 test/lib/vedeu/repository/command_repository_test.rb
vedeu-0.0.24 test/lib/vedeu/repository/command_repository_test.rb