Sha256: f3ef6603544e4a0184b268497cf2862652c775548d396bcba992775a75a9061f

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# -*- encoding : utf-8 -*-
require File.expand_path('../test_helper', __FILE__)

describe Gitdocs::Search do
  describe 'initialize' do
    subject { Gitdocs::Search.new(:repositories) }
    it { subject.instance_variable_get(:@repositories).must_equal :repositories }
  end

  describe '#search' do
    subject { Gitdocs::Search.new([repository1, repository2]).search(term) }

    let(:repository1) { mock }
    let(:repository2) { mock }

    before do
      repository1.stubs(:root).returns('root')
      repository2.stubs(:root).returns('root')
    end

    describe 'term is missing' do
      let(:term) { nil }
      it { subject.must_equal({}) }
    end

    describe 'term is empty' do
      let(:term) { '' }
      it { subject.must_equal({}) }
    end

    describe 'term is non-empty' do
      let(:term) { 'term' }
      before do
        repository1.stubs(:grep).with(term).multiple_yields(
          %w(file1 context1)
        )
        repository2.stubs(:grep).with(term).multiple_yields(
          %w(file2 context2a),
          %w(file2 context2b),
          %w(file3 context3)
        )
      end

      it do
        subject.must_equal(
          Gitdocs::Search::RepoDescriptor.new('root', 0) => [
            Gitdocs::Search::SearchResult.new('file1', 'context1')
          ],
          Gitdocs::Search::RepoDescriptor.new('root', 1) => [
            Gitdocs::Search::SearchResult.new('file2', 'context2a ... context2b'),
            Gitdocs::Search::SearchResult.new('file3', 'context3')
          ]
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitdocs-0.5.0 test/unit/search_test.rb