|
127 | 127 | end |
128 | 128 | end |
129 | 129 |
|
| 130 | + context 'with a file that does not define OctocatalogDiff::Config' do |
| 131 | + let(:filename) { OctocatalogDiff::Spec.fixture_path('cli-configs/not-class.rb') } |
| 132 | + |
| 133 | + it 'should raise ConfigurationFileContentError' do |
| 134 | + pattern = Regexp.new('must define OctocatalogDiff::Config!') |
| 135 | + expect do |
| 136 | + described_class.load_config_file(filename, @logger) |
| 137 | + end.to raise_error(OctocatalogDiff::API::V1::Config::ConfigurationFileContentError, pattern) |
| 138 | + end |
| 139 | + |
| 140 | + it 'should log fatal message' do |
| 141 | + exception = nil |
| 142 | + begin |
| 143 | + described_class.load_config_file(filename, @logger) |
| 144 | + rescue OctocatalogDiff::API::V1::Config::ConfigurationFileContentError => exc |
| 145 | + exception = exc |
| 146 | + end |
| 147 | + expect(exception).to be_a_kind_of(OctocatalogDiff::API::V1::Config::ConfigurationFileContentError) |
| 148 | + expect(exception.message).to eq('Configuration must define OctocatalogDiff::Config!') |
| 149 | + expect(@logger_str.string).to match(/Configuration must define OctocatalogDiff::Config!/) |
| 150 | + end |
| 151 | + end |
| 152 | + |
130 | 153 | context 'with a file that does not define a hash' do |
| 154 | + let(:filename) { OctocatalogDiff::Spec.fixture_path('cli-configs/not-hash.rb') } |
| 155 | + |
| 156 | + it 'should raise ConfigurationFileContentError' do |
| 157 | + pattern = Regexp.new('Configuration must be Hash not Array!') |
| 158 | + expect do |
| 159 | + described_class.load_config_file(filename, @logger) |
| 160 | + end.to raise_error(OctocatalogDiff::API::V1::Config::ConfigurationFileContentError, pattern) |
| 161 | + end |
| 162 | + |
| 163 | + it 'should log fatal message' do |
| 164 | + exception = nil |
| 165 | + begin |
| 166 | + described_class.load_config_file(filename, @logger) |
| 167 | + rescue OctocatalogDiff::API::V1::Config::ConfigurationFileContentError => exc |
| 168 | + exception = exc |
| 169 | + end |
| 170 | + expect(exception).to be_a_kind_of(OctocatalogDiff::API::V1::Config::ConfigurationFileContentError) |
| 171 | + expect(exception.message).to eq('Configuration must be Hash not Array!') |
| 172 | + expect(@logger_str.string).to match(/Configuration must be Hash not Array!/) |
| 173 | + end |
131 | 174 | end |
132 | 175 |
|
133 | 176 | context 'with a valid file' do |
|
147 | 190 | end |
148 | 191 |
|
149 | 192 | describe '#first_file' do |
| 193 | + before(:each) do |
| 194 | + allow(File).to receive(:'file?') { |x| x =~ /^present/ } |
| 195 | + end |
| 196 | + |
| 197 | + it 'should accept an empty array and return nil' do |
| 198 | + expect(described_class.first_file([])).to be_nil |
| 199 | + end |
| 200 | + |
| 201 | + it 'should accept a single missing file and return nil' do |
| 202 | + expect(described_class.first_file(['missing1'])).to be_nil |
| 203 | + end |
| 204 | + |
| 205 | + it 'should accept a multiple missing files and return nil' do |
| 206 | + expect(described_class.first_file(%w(missing1 missing2 missing3))).to be_nil |
| 207 | + end |
| 208 | + |
| 209 | + it 'should accept nil in the array and still work' do |
| 210 | + expect(described_class.first_file(['missing1', nil, 'missing2', 'present1'])).to eq('present1') |
| 211 | + end |
| 212 | + |
| 213 | + it 'should flatten arrays and still work' do |
| 214 | + expect(described_class.first_file(['missing1', [nil, 'missing2'], ['present1']])).to eq('present1') |
| 215 | + end |
150 | 216 | end |
151 | 217 | end |
0 commit comments