|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Overcommit::Hook::PreCommit::MetadataJsonLint do |
| 4 | + let(:config) { Overcommit::ConfigurationLoader.default_configuration } |
| 5 | + let(:context) { double('context') } |
| 6 | + subject { described_class.new(config, context) } |
| 7 | + |
| 8 | + context 'metadata.json not modified' do |
| 9 | + before do |
| 10 | + subject.stub(:applicable_files).and_return(%w[file1.pp file2.pp]) |
| 11 | + end |
| 12 | + |
| 13 | + it { should pass } |
| 14 | + end |
| 15 | + |
| 16 | + context 'metadata.json is modified' do |
| 17 | + before do |
| 18 | + subject.stub(:applicable_files).and_return(%w[file1.pp file2.pp metadata.json]) |
| 19 | + end |
| 20 | + |
| 21 | + context 'when metadata-json-lint exits successfully' do |
| 22 | + let(:result) { double('result') } |
| 23 | + |
| 24 | + before do |
| 25 | + result.stub(:success?).and_return(true) |
| 26 | + subject.stub(:execute).and_return(result) |
| 27 | + end |
| 28 | + |
| 29 | + context 'with no output' do |
| 30 | + before do |
| 31 | + result.stub(:stdout).and_return('') |
| 32 | + end |
| 33 | + |
| 34 | + it { should pass } |
| 35 | + end |
| 36 | + |
| 37 | + context 'and it reports a warning' do |
| 38 | + before do |
| 39 | + result.stub(:stdout).and_return(normalize_indent(<<-OUT)) |
| 40 | + (WARN) requirements: The 'pe' requirement is no longer supported by the Forge. |
| 41 | + OUT |
| 42 | + end |
| 43 | + |
| 44 | + it { should warn } |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context 'when metadata-json-lint exits unsuccessfully' do |
| 49 | + let(:result) { double('result') } |
| 50 | + |
| 51 | + before do |
| 52 | + result.stub(:success?).and_return(false) |
| 53 | + subject.stub(:execute).and_return(result) |
| 54 | + end |
| 55 | + |
| 56 | + context 'and it reports a warning' do |
| 57 | + before do |
| 58 | + result.stub(:stdout).and_return(normalize_indent(<<-OUT)) |
| 59 | + (WARN) requirements: The 'pe' requirement is no longer supported by the Forge. |
| 60 | + OUT |
| 61 | + end |
| 62 | + |
| 63 | + it { should warn } |
| 64 | + end |
| 65 | + |
| 66 | + context 'and it reports an error' do |
| 67 | + before do |
| 68 | + result.stub(:stdout).and_return(normalize_indent(<<-OUT)) |
| 69 | + (ERR) requirements: The 'pe' requirement is no longer supported by the Forge. |
| 70 | + OUT |
| 71 | + end |
| 72 | + |
| 73 | + it { should fail_hook } |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | +end |
0 commit comments