-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
RSpec.describe "External application config", with_gem: :some_gem do | ||
before do | ||
gem.main_file.write(main_file) | ||
end | ||
|
||
let(:external_config) { Kangaru.application.config.external.serialise } | ||
|
||
shared_examples :does_not_set_external_config do | ||
it "does not raise any errors" do | ||
expect { gem.load! }.not_to raise_error | ||
end | ||
|
||
it "does not set any external config" do | ||
gem.load! | ||
expect(external_config).to be_empty | ||
end | ||
end | ||
|
||
shared_examples :sets_external_config do | ||
it "does not raise any errors" do | ||
expect { gem.load! }.not_to raise_error | ||
end | ||
|
||
it "sets the external config" do | ||
gem.load! | ||
expect(external_config).to eq(frodo: { race: "hobbit", age: 48 }) | ||
end | ||
end | ||
|
||
context "when config_path is not set" do | ||
let(:main_file) do | ||
<<~RUBY | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples :does_not_set_external_config | ||
end | ||
|
||
context "when config_path is set" do | ||
let(:main_file) do | ||
<<~RUBY | ||
require "kangaru" | ||
module SomeGem | ||
extend Kangaru::Initialiser | ||
Kangaru.application.configure do |config| | ||
config.application.config_path = "#{config_path}" | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
let(:config_path) { gem.dir.join("config.yml") } | ||
|
||
context "and no config exists at the specified path" do | ||
include_examples :does_not_set_external_config | ||
end | ||
|
||
context "and config exists at the specified path" do | ||
let(:config_file) do | ||
<<~YAML | ||
frodo: | ||
race: hobbit | ||
age: 48 | ||
YAML | ||
end | ||
|
||
before { config_path.write(config_file) } | ||
|
||
include_examples :sets_external_config | ||
end | ||
end | ||
end |