spec/integration/slices_spec.rb in hanami-2.1.0.beta2.1 vs spec/integration/slices_spec.rb in hanami-2.1.0.rc1
- old
+ new
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe "Slices", :app_integration do
- it "Loading a slice uses a defined slice class" do
+ specify "Loading a slice from a slice class in the app's config dir" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp
@@ -29,11 +29,11 @@
expect(Hanami.app.slices[:main]).to be Main::Slice
end
end
- it "Loading a slice with a defined slice class but no slice dir" do
+ specify "Loading a slice from a slice class in the app's config dir, even when no slice dir exists" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp
@@ -53,11 +53,11 @@
expect(Hanami.app.slices[:main]).to be Main::Slice
end
end
- specify "Loading a nested slice with a defined slice class" do
+ specify "Loading a nested slice from a slice class in its parent's config dir" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp
@@ -79,21 +79,291 @@
expect(Hanami.app.slices[:main].slices[:nested]).to be Main::Nested::Slice
end
end
- it "Loading a slice generates a slice class if none is defined" do
+ specify "Loading a slice from a slice class in its own config dir" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp
class App < Hanami::App
end
end
RUBY
+ write "slices/main/config/slice.rb", <<~RUBY
+ module Main
+ class Slice < Hanami::Slice
+ def self.loaded_from = "own config dir"
+ end
+ end
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main]).to be Main::Slice
+ expect(Hanami.app.slices[:main].loaded_from).to eq "own config dir"
+ end
+ end
+
+ specify "Loading a slice from a slice class in the app's config dir, in preference to a slice class in its own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "config/slices/main.rb", <<~RUBY
+ require "hanami"
+
+ module Main
+ class Slice < Hanami::Slice
+ def self.loaded_from = "app config dir"
+ end
+ end
+ RUBY
+
+ write "slices/main/config/slice.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main]).to be Main::Slice
+ expect(Hanami.app.slices[:main].loaded_from).to eq "app config dir"
+ end
+ end
+
+ specify "Loading a nested slice from a slice class in its own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "slices/main/slices/nested/config/slice.rb", <<~RUBY
+ module Main
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "own config dir"
+ end
+ end
+ end
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main]).to be Main::Slice
+ expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "own config dir"
+ end
+ end
+
+ specify "Loading a deeply nested slice from a slice class in its own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ # It does NOT look up "grandparent" (or above) configs; only the parent and the app
+ write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
+ module Main
+ module Deeply
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "own config dir"
+ end
+ end
+ end
+ end
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "own config dir"
+ end
+ end
+
+ specify "Loading a nested slice from a slice class in its parent's config dir, in preference to a slice class in its own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "slices/main/config/slices/nested.rb", <<~RUBY
+ require "hanami"
+
+ module Main
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "parent config dir"
+ end
+ end
+ end
+ RUBY
+
+ write "slices/main/slices/nested/config/slice.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main]).to be Main::Slice
+ expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "parent config dir"
+ end
+ end
+
+ specify "Loading a deeply nested slice from a slice class in its parent's config dir, in preference to a slice class in its own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ # It does NOT look up "grandparent" (or above) configs; only the parent and the app
+ write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ write "slices/main/slices/deeply/config/slices/nested.rb", <<~RUBY
+ module Main
+ module Deeply
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "parent config dir"
+ end
+ end
+ end
+ end
+ RUBY
+
+ write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "parent config dir"
+ end
+ end
+
+ specify "Loading a nested slice from a slice class in the app's config dir, in preference to a slice class in the slice's parent config dir or the slice's own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "config/slices/main/nested.rb", <<~RUBY
+ require "hanami"
+
+ module Main
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "app config dir"
+ end
+ end
+ end
+ RUBY
+
+ write "slices/main/config/slices/nested.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ write "slices/main/slices/nested/config/slice.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main]).to be Main::Slice
+ expect(Hanami.app.slices[:main].slices[:nested].loaded_from).to eq "app config dir"
+ end
+ end
+
+ specify "Loading a deeply nested slice from a slice class in the app's config dir, in preference to a slice class in the slice's parent config dir or the slice's own config dir" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
+ write "config/slices/main/deeply/nested.rb", <<~RUBY
+ module Main
+ module Deeply
+ module Nested
+ class Slice < Hanami::Slice
+ def self.loaded_from = "app config dir"
+ end
+ end
+ end
+ end
+ RUBY
+
+ write "slices/main/config/slices/deeply/nested.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ write "slices/main/slices/deeply/slices/nested/config/slice.rb", <<~RUBY
+ raise "This should not be loaded"
+ RUBY
+
+ require "hanami/prepare"
+
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested]).to be Main::Deeply::Nested::Slice
+ expect(Hanami.app.slices[:main].slices[:deeply].slices[:nested].loaded_from).to eq "app config dir"
+ end
+ end
+
+ specify "Loading a slice generates a slice class if none is defined" do
+ with_tmp_directory(Dir.mktmpdir) do
+ write "config/app.rb", <<~RUBY
+ require "hanami"
+
+ module TestApp
+ class App < Hanami::App
+ end
+ end
+ RUBY
+
write "slices/main/lib/foo.rb", <<~RUBY
module Main
class Foo; end
end
RUBY
@@ -176,10 +446,10 @@
expect(Hanami.app.slices[:main].slices[:nested]).to be Admin::Slice
end
end
- it "Registering a slice with a block creates a slice class and evals the block" do
+ specify "Registering a slice with a block creates a slice class and evals the block" do
with_tmp_directory(Dir.mktmpdir) do
write "config/app.rb", <<~RUBY
require "hanami"
module TestApp