Sha256: 71d3e0e9834acaf253d65d5f8448a9288fb54a3b882fd4abc01a4ab09d933054

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 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 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.pre7 test/unit/search_test.rb