|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Script::Dependency do |
| 4 | + subject do |
| 5 | + options = load_fixture('script/commands')[fixture] |
| 6 | + Script::Command.new(options).dependencies.first |
| 7 | + end |
| 8 | + |
| 9 | + let(:fixture) { :dependencies } |
| 10 | + |
| 11 | + describe '::from_config' do |
| 12 | + context 'with an unrecognized configuration' do |
| 13 | + it 'returns an empty instahnce' do |
| 14 | + expect(described_class.from_config('curl', 1)).to be_a described_class |
| 15 | + end |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + describe '#label' do |
| 20 | + context 'when initialized with a string' do |
| 21 | + it 'returns the string' do |
| 22 | + expect(subject.label).to eq 'curl' |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context 'when initialized with a command => help hash' do |
| 27 | + let(:fixture) { :dependencies_simple_hash } |
| 28 | + |
| 29 | + it 'returns the command' do |
| 30 | + expect(subject.label).to eq 'curl' |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context 'when initialized with a label => config hash' do |
| 35 | + let(:fixture) { :dependencies_full_hash } |
| 36 | + |
| 37 | + it 'returns the label' do |
| 38 | + expect(subject.label).to eq 'http_client' |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#commands' do |
| 44 | + context 'when initialized with a string' do |
| 45 | + it 'returns an array with that string as its only element' do |
| 46 | + expect(subject.commands).to eq ['curl'] |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context 'when initialized with a command => help hash' do |
| 51 | + let(:fixture) { :dependencies_simple_hash } |
| 52 | + |
| 53 | + it 'returns an array with the command as its only element' do |
| 54 | + expect(subject.commands).to eq ['curl'] |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context 'when initialized with a label => config hash' do |
| 59 | + let(:fixture) { :dependencies_full_hash } |
| 60 | + |
| 61 | + it 'returns the commands provided by the config' do |
| 62 | + expect(subject.commands).to match_array %w[curl wget] |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe '#help' do |
| 68 | + context 'when initialized with a string' do |
| 69 | + it 'returns nil' do |
| 70 | + expect(subject.help).to be_nil |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + context 'when initialized with a command => help hash' do |
| 75 | + let(:fixture) { :dependencies_simple_hash } |
| 76 | + |
| 77 | + it 'returns the provided help' do |
| 78 | + expect(subject.help).to eq 'Please install curl' |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + context 'when initialized with a label => config hash' do |
| 83 | + let(:fixture) { :dependencies_full_hash } |
| 84 | + |
| 85 | + it 'returns the help provided by the config' do |
| 86 | + expect(subject.help).to eq 'Please install curl or wget' |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + describe '#name' do |
| 92 | + context 'when there is only one command' do |
| 93 | + it 'returns it' do |
| 94 | + expect(subject.name).to eq 'curl' |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context 'when there are more than one commands' do |
| 99 | + let(:fixture) { :dependencies_full_hash } |
| 100 | + |
| 101 | + it 'returns a string suitable for the error message' do |
| 102 | + expect(subject.name).to eq 'http_client (curl/wget)' |
| 103 | + end |
| 104 | + end |
| 105 | + end |
| 106 | +end |
0 commit comments