Skip to content

Commit

Permalink
Add external config feature spec
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Oct 17, 2023
1 parent 44587d2 commit 741d3d3
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions spec/features/external_config_spec.rb
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

0 comments on commit 741d3d3

Please sign in to comment.