File: detector_spec.rb

package info (click to toggle)
ruby-cliver 0.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: ruby: 760; makefile: 3
file content (78 lines) | stat: -rw-r--r-- 2,385 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# encoding: utf-8
require 'cliver'

describe Cliver::Detector do
  let(:detector) { Cliver::Detector.new(*args) }
  let(:defaults) do
    {
      :version_pattern => Cliver::Detector::DEFAULT_VERSION_PATTERN,
      :command_arg =>     Cliver::Detector::DEFAULT_COMMAND_ARG,
    }
  end
  let(:args) { [] }
  subject { detector }

  it { should respond_to :to_proc }

  its(:command_arg) { should eq defaults[:command_arg] }
  its(:version_pattern) { should eq defaults[:version_pattern] }

  context 'with one string argument' do
    let(:version_arg) { '--release-version' }
    let(:args) { [version_arg] }

    its(:command_arg) { should eq [version_arg] }
    its(:version_pattern) { should eq defaults[:version_pattern] }
  end

  context 'with one regexp argument' do
    let(:regexp_arg) { /.*/ }
    let(:args) { [regexp_arg] }

    its(:command_arg) { should eq defaults[:command_arg] }
    its(:version_pattern) { should eq regexp_arg }
  end

  context 'with both arguments' do
    let(:version_arg) { '--release-version' }
    let(:regexp_arg) { /.*/ }
    let(:args) { [version_arg, regexp_arg] }

    its(:command_arg) { should eq [version_arg] }
    its(:version_pattern) { should eq regexp_arg }
  end

  context 'detecting a command' do
    before(:each) do
      Cliver::ShellCapture.stub(:new => capture)
    end

    context 'that reports version on stdout' do
      let(:capture) { double('capture', :stdout => '1.1',
                                        :stderr => 'Warning: There is a monkey 1.2 metres left of you.',
                                        :command_found => true) }

      it 'should prefer the stdout output' do
        expect(detector.detect_version('foo')).to eq('1.1')
      end
    end

    context 'that reports version on stderr' do
      let(:capture) { double('capture', :stdout => '',
                                        :stderr => 'Version: 1.666',
                                        :command_found => true) }

      it 'should prefer the stderr output' do
        expect(detector.detect_version('foo')).to eq('1.666')
      end
    end

    context 'that does not exist' do
      let(:capture) { Cliver::ShellCapture.new('acommandnosystemshouldhave123') }

      it 'should raise an exception' do
        expect { detector.detect_version('foo') }.to raise_error(Cliver::Dependency::NotFound)
      end
    end
  end
end