From 741d3d336f1a5a90ad5f81cb2dbab0a1add9ae45 Mon Sep 17 00:00:00 2001 From: Chris Welham <71787007+apexatoll@users.noreply.github.com> Date: Tue, 17 Oct 2023 02:53:32 +0100 Subject: [PATCH] Add external config feature spec --- spec/features/external_config_spec.rb | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 spec/features/external_config_spec.rb diff --git a/spec/features/external_config_spec.rb b/spec/features/external_config_spec.rb new file mode 100644 index 0000000..c35918f --- /dev/null +++ b/spec/features/external_config_spec.rb @@ -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