Skip to content

Commit 89cb1de

Browse files
author
Kevin Paulisse
committed
Finish test coverage for OctocatalogDiff API config
1 parent 6449f4d commit 89cb1de

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

spec/octocatalog-diff/tests/api/v1/config_spec.rb

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'ostruct'
4-
53
require_relative '../../spec_helper'
64

75
require OctocatalogDiff::Spec.require_path('/api/v1/config')
@@ -20,6 +18,56 @@
2018
end
2119

2220
describe '#config' do
21+
let(:filename) { '/fizz/buzz.rb' }
22+
23+
context 'with missing configuration file' do
24+
let(:pattern) { Regexp.new("Unable to find configuration file in #{filename}") }
25+
26+
context 'in test mode' do
27+
it 'should raise ConfigurationFileNotFoundError' do
28+
expect(File).to receive(:'file?').with(filename).and_return(false)
29+
expect do
30+
described_class.config(logger: @logger, filename: filename, test: true)
31+
end.to raise_error(OctocatalogDiff::API::V1::Config::ConfigurationFileNotFoundError, pattern)
32+
end
33+
end
34+
35+
context 'in normal mode' do
36+
it 'should return {}' do
37+
expect(File).to receive(:'file?').with(filename).and_return(false)
38+
result = described_class.config(logger: @logger, filename: filename)
39+
expect(result).to eq({})
40+
expect(@logger_str.string).to match(pattern)
41+
end
42+
end
43+
end
44+
45+
context 'with found configuration file' do
46+
let(:pattern) { Regexp.new('Loaded 1 settings from /fizz/buzz.rb') }
47+
let(:debug_pattern) { Regexp.new(':foo => \(String\) "bar"') }
48+
49+
context 'in test mode' do
50+
it 'should print settings to log and return settings' do
51+
expect(File).to receive(:'file?').with(filename).and_return(true)
52+
expect(described_class).to receive(:load_config_file).and_return(foo: 'bar')
53+
result = described_class.config(logger: @logger, filename: filename, test: true)
54+
expect(result).to eq(foo: 'bar')
55+
expect(@logger_str.string).to match(pattern)
56+
expect(@logger_str.string).to match(debug_pattern)
57+
end
58+
end
59+
60+
context 'in normal mode' do
61+
it 'should return settings' do
62+
expect(File).to receive(:'file?').with(filename).and_return(true)
63+
expect(described_class).to receive(:load_config_file).and_return(foo: 'bar')
64+
result = described_class.config(logger: @logger, filename: filename)
65+
expect(result).to eq(foo: 'bar')
66+
expect(@logger_str.string).to match(pattern)
67+
expect(@logger_str.string).not_to match(debug_pattern)
68+
end
69+
end
70+
end
2371
end
2472

2573
describe '#debug_config_file' do

0 commit comments

Comments
 (0)