File: searcher_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (38 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'
require 'puppet/module_tool/applications'
require 'puppet_spec/modules'

describe Puppet::ModuleTool::Applications::Searcher do
  include PuppetSpec::Files

  describe "when searching" do
    let(:forge) { double('forge', :host => 'http://nowhe.re') }
    let(:searcher) do
      described_class.new('search_term', forge)
    end

    it "should return results from a forge query when successful" do
      results = 'mock results'
      expect(forge).to receive(:search).with('search_term').and_return(results)

      search_result = searcher.run
      expect(search_result).to eq({
        :result => :success,
        :answers => results,
      })
    end

    it "should return an error when the forge query throws an exception" do
      expect(forge).to receive(:search).with('search_term').and_raise(Puppet::Forge::Errors::ForgeError.new("something went wrong"))

      search_result = searcher.run
      expect(search_result).to eq({
        :result => :failure,
        :error => {
          :oneline   => 'something went wrong',
          :multiline => 'something went wrong',
        },
      })
    end
  end
end