hanami 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -1
  3. data/hanami.gemspec +5 -5
  4. data/lib/hanami/app.rb +4 -4
  5. data/lib/hanami/assets/{app_configuration.rb → app_config.rb} +10 -10
  6. data/lib/hanami/assets/{configuration.rb → config.rb} +4 -4
  7. data/lib/hanami/{configuration → config}/actions/content_security_policy.rb +2 -2
  8. data/lib/hanami/{configuration → config}/actions/cookies.rb +6 -5
  9. data/lib/hanami/{configuration → config}/actions/sessions.rb +2 -2
  10. data/lib/hanami/{configuration → config}/actions.rb +11 -12
  11. data/lib/hanami/{configuration → config}/logger.rb +2 -2
  12. data/lib/hanami/config/null_config.rb +14 -0
  13. data/lib/hanami/{configuration → config}/router.rb +8 -8
  14. data/lib/hanami/{configuration → config}/sessions.rb +2 -2
  15. data/lib/hanami/{configuration → config}/views.rb +10 -10
  16. data/lib/hanami/{configuration.rb → config.rb} +30 -30
  17. data/lib/hanami/errors.rb +3 -0
  18. data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
  19. data/lib/hanami/providers/inflector.rb +0 -2
  20. data/lib/hanami/providers/logger.rb +1 -3
  21. data/lib/hanami/providers/rack.rb +0 -2
  22. data/lib/hanami/providers/routes.rb +0 -2
  23. data/lib/hanami/routes.rb +48 -21
  24. data/lib/hanami/settings/env_store.rb +3 -3
  25. data/lib/hanami/settings.rb +87 -5
  26. data/lib/hanami/slice/routing/middleware/stack.rb +45 -1
  27. data/lib/hanami/slice.rb +52 -37
  28. data/lib/hanami/slice_configurable.rb +1 -1
  29. data/lib/hanami/slice_registrar.rb +6 -0
  30. data/lib/hanami/version.rb +1 -1
  31. data/lib/hanami.rb +0 -1
  32. data/spec/{new_integration → integration}/action/cookies_spec.rb +0 -0
  33. data/spec/{new_integration → integration}/action/csrf_protection_spec.rb +0 -0
  34. data/spec/{new_integration → integration}/action/routes_spec.rb +3 -5
  35. data/spec/{new_integration → integration}/action/sessions_spec.rb +0 -0
  36. data/spec/{new_integration → integration}/action/slice_configuration_spec.rb +0 -0
  37. data/spec/{new_integration → integration}/action/view_integration_spec.rb +0 -0
  38. data/spec/{new_integration → integration}/action/view_rendering/automatic_rendering_spec.rb +0 -0
  39. data/spec/{new_integration → integration}/action/view_rendering/paired_view_inference_spec.rb +0 -0
  40. data/spec/{new_integration → integration}/action/view_rendering_spec.rb +0 -0
  41. data/spec/{new_integration → integration}/code_loading/loading_from_app_spec.rb +0 -0
  42. data/spec/{new_integration → integration}/code_loading/loading_from_lib_spec.rb +0 -0
  43. data/spec/{new_integration → integration}/code_loading/loading_from_slice_spec.rb +0 -0
  44. data/spec/{new_integration → integration}/container/application_routes_helper_spec.rb +1 -3
  45. data/spec/{new_integration → integration}/container/auto_injection_spec.rb +0 -0
  46. data/spec/{new_integration → integration}/container/auto_registration_spec.rb +0 -0
  47. data/spec/{new_integration → integration}/container/autoloader_spec.rb +0 -0
  48. data/spec/{new_integration → integration}/container/imports_spec.rb +0 -0
  49. data/spec/{new_integration → integration}/container/prepare_container_spec.rb +2 -0
  50. data/spec/{new_integration → integration}/container/shutdown_spec.rb +0 -0
  51. data/spec/{new_integration → integration}/container/standard_bootable_components_spec.rb +0 -0
  52. data/spec/{new_integration → integration}/dotenv_loading_spec.rb +0 -0
  53. data/spec/integration/rack_app/body_parser_spec.rb +108 -0
  54. data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +37 -15
  55. data/spec/{new_integration → integration}/rack_app/non_booted_rack_app_spec.rb +3 -5
  56. data/spec/{new_integration → integration}/rack_app/rack_app_spec.rb +28 -48
  57. data/spec/integration/settings/access_in_slice_class_body_spec.rb +82 -0
  58. data/spec/integration/settings/access_to_constants_spec.rb +46 -0
  59. data/spec/{new_integration → integration}/settings/loading_from_env_spec.rb +0 -0
  60. data/spec/{new_integration → integration}/settings/settings_component_loading_spec.rb +0 -0
  61. data/spec/{new_integration/slices/slice_settings_spec.rb → integration/settings/slice_registration_spec.rb} +5 -1
  62. data/spec/{new_integration → integration}/settings/using_types_spec.rb +4 -11
  63. data/spec/{new_integration → integration}/setup_spec.rb +20 -0
  64. data/spec/{new_integration → integration}/slices/external_slice_spec.rb +2 -4
  65. data/spec/{new_integration → integration}/slices/slice_configuration_spec.rb +0 -0
  66. data/spec/{new_integration → integration}/slices/slice_loading_spec.rb +0 -0
  67. data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
  68. data/spec/{new_integration → integration}/slices_spec.rb +0 -0
  69. data/spec/{new_integration → integration}/view/context/assets_spec.rb +0 -0
  70. data/spec/{new_integration → integration}/view/context/inflector_spec.rb +0 -0
  71. data/spec/{new_integration → integration}/view/context/request_spec.rb +0 -0
  72. data/spec/{new_integration → integration}/view/context/routes_spec.rb +1 -3
  73. data/spec/{new_integration → integration}/view/context/settings_spec.rb +0 -0
  74. data/spec/{new_integration → integration}/view/inflector_spec.rb +0 -0
  75. data/spec/{new_integration → integration}/view/part_namespace_spec.rb +0 -0
  76. data/spec/{new_integration → integration}/view/path_spec.rb +0 -0
  77. data/spec/{new_integration → integration}/view/slice_configuration_spec.rb +0 -0
  78. data/spec/{new_integration → integration}/view/template_spec.rb +0 -0
  79. data/spec/{new_integration → integration}/view/views_spec.rb +0 -0
  80. data/spec/support/app_integration.rb +18 -15
  81. data/spec/unit/hanami/{configuration → config}/actions/content_security_policy_spec.rb +10 -10
  82. data/spec/unit/hanami/{configuration → config}/actions/cookies_spec.rb +6 -6
  83. data/spec/unit/hanami/{configuration → config}/actions/csrf_protection_spec.rb +12 -12
  84. data/spec/unit/hanami/config/actions/default_values_spec.rb +54 -0
  85. data/spec/unit/hanami/{configuration → config}/actions/sessions_spec.rb +5 -5
  86. data/spec/unit/hanami/{configuration → config}/actions_spec.rb +13 -25
  87. data/spec/unit/hanami/{configuration → config}/base_url_spec.rb +2 -2
  88. data/spec/unit/hanami/{configuration → config}/inflector_spec.rb +2 -2
  89. data/spec/unit/hanami/{configuration → config}/logger_spec.rb +4 -4
  90. data/spec/unit/hanami/config/router_spec.rb +44 -0
  91. data/spec/unit/hanami/{configuration → config}/slices_spec.rb +2 -2
  92. data/spec/unit/hanami/{configuration → config}/views_spec.rb +15 -27
  93. data/spec/unit/hanami/{configuration_spec.rb → config_spec.rb} +3 -3
  94. data/spec/unit/hanami/settings_spec.rb +65 -10
  95. data/spec/unit/hanami/slice_configurable_spec.rb +21 -2
  96. data/spec/unit/hanami/version_spec.rb +1 -1
  97. metadata +162 -294
  98. data/lib/hanami/configuration/null_configuration.rb +0 -14
  99. data/lib/hanami/providers/settings.rb +0 -98
  100. data/lib/hanami/server.rb +0 -29
  101. data/spec/integration/application_middleware_stack_spec.rb +0 -84
  102. data/spec/integration/assets/cdn_spec.rb +0 -48
  103. data/spec/integration/assets/fingerprint_spec.rb +0 -42
  104. data/spec/integration/assets/helpers_spec.rb +0 -50
  105. data/spec/integration/assets/serve_spec.rb +0 -70
  106. data/spec/integration/assets/subresource_integrity_spec.rb +0 -54
  107. data/spec/integration/body_parsers_spec.rb +0 -50
  108. data/spec/integration/cli/assets/precompile_spec.rb +0 -147
  109. data/spec/integration/cli/assets_spec.rb +0 -14
  110. data/spec/integration/cli/console_spec.rb +0 -105
  111. data/spec/integration/cli/db/apply_spec.rb +0 -74
  112. data/spec/integration/cli/db/console_spec.rb +0 -40
  113. data/spec/integration/cli/db/create_spec.rb +0 -50
  114. data/spec/integration/cli/db/drop_spec.rb +0 -54
  115. data/spec/integration/cli/db/migrate_spec.rb +0 -108
  116. data/spec/integration/cli/db/prepare_spec.rb +0 -36
  117. data/spec/integration/cli/db/rollback_spec.rb +0 -96
  118. data/spec/integration/cli/db/version_spec.rb +0 -38
  119. data/spec/integration/cli/db_spec.rb +0 -21
  120. data/spec/integration/cli/destroy/action_spec.rb +0 -143
  121. data/spec/integration/cli/destroy/app_spec.rb +0 -118
  122. data/spec/integration/cli/destroy/mailer_spec.rb +0 -74
  123. data/spec/integration/cli/destroy/migration_spec.rb +0 -70
  124. data/spec/integration/cli/destroy/model_spec.rb +0 -113
  125. data/spec/integration/cli/destroy_spec.rb +0 -18
  126. data/spec/integration/cli/generate/action_spec.rb +0 -469
  127. data/spec/integration/cli/generate/app_spec.rb +0 -215
  128. data/spec/integration/cli/generate/mailer_spec.rb +0 -189
  129. data/spec/integration/cli/generate/migration_spec.rb +0 -72
  130. data/spec/integration/cli/generate/model_spec.rb +0 -290
  131. data/spec/integration/cli/generate/secret_spec.rb +0 -56
  132. data/spec/integration/cli/generate_spec.rb +0 -19
  133. data/spec/integration/cli/new/database_spec.rb +0 -235
  134. data/spec/integration/cli/new/hanami_head_spec.rb +0 -27
  135. data/spec/integration/cli/new/template_spec.rb +0 -118
  136. data/spec/integration/cli/new/test_spec.rb +0 -274
  137. data/spec/integration/cli/new_spec.rb +0 -970
  138. data/spec/integration/cli/plugins_spec.rb +0 -39
  139. data/spec/integration/cli/routes_spec.rb +0 -49
  140. data/spec/integration/cli/server_spec.rb +0 -626
  141. data/spec/integration/cli/version_spec.rb +0 -85
  142. data/spec/integration/early_hints_spec.rb +0 -35
  143. data/spec/integration/handle_exceptions_spec.rb +0 -244
  144. data/spec/integration/head_spec.rb +0 -89
  145. data/spec/integration/http_headers_spec.rb +0 -29
  146. data/spec/integration/mailer_spec.rb +0 -32
  147. data/spec/integration/middleware_spec.rb +0 -81
  148. data/spec/integration/mount_applications_spec.rb +0 -88
  149. data/spec/integration/project_initializers_spec.rb +0 -40
  150. data/spec/integration/rackup_spec.rb +0 -35
  151. data/spec/integration/rake/with_minitest_spec.rb +0 -67
  152. data/spec/integration/rake/with_rspec_spec.rb +0 -69
  153. data/spec/integration/routing_helpers_spec.rb +0 -61
  154. data/spec/integration/security/content_security_policy_spec.rb +0 -46
  155. data/spec/integration/security/csrf_protection_spec.rb +0 -42
  156. data/spec/integration/security/force_ssl_spec.rb +0 -29
  157. data/spec/integration/security/x_content_type_options_spec.rb +0 -46
  158. data/spec/integration/security/x_frame_options_spec.rb +0 -46
  159. data/spec/integration/security/x_xss_protection_spec.rb +0 -46
  160. data/spec/integration/send_file_spec.rb +0 -51
  161. data/spec/integration/sessions_spec.rb +0 -247
  162. data/spec/integration/static_middleware_spec.rb +0 -21
  163. data/spec/integration/streaming_spec.rb +0 -41
  164. data/spec/integration/unsafe_send_file_spec.rb +0 -52
  165. data/spec/new_integration/settings/access_to_constants_spec.rb +0 -169
  166. data/spec/support/fixtures/hanami-plugin/Gemfile +0 -8
  167. data/spec/support/fixtures/hanami-plugin/README.md +0 -35
  168. data/spec/support/fixtures/hanami-plugin/Rakefile +0 -4
  169. data/spec/support/fixtures/hanami-plugin/bin/console +0 -15
  170. data/spec/support/fixtures/hanami-plugin/bin/setup +0 -8
  171. data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +0 -28
  172. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +0 -19
  173. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +0 -7
  174. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +0 -8
  175. data/spec/unit/hanami/configuration/actions/default_values_spec.rb +0 -52
  176. data/spec/unit/hanami/routes_spec.rb +0 -25
@@ -17,9 +17,7 @@ RSpec.describe "App view / Context / Routes", :app_integration do
17
17
  write "config/routes.rb", <<~RUBY
18
18
  module TestApp
19
19
  class Routes < Hanami::Routes
20
- define do
21
- root to: "home.index"
22
- end
20
+ root to: "home.index"
23
21
  end
24
22
  end
25
23
  RUBY
@@ -23,6 +23,23 @@ RSpec.shared_context "Application integration" do
23
23
  let(:app_modules) { %i[TestApp Admin Main Search] }
24
24
  end
25
25
 
26
+ def autoloaders_teardown!
27
+ # Tear down Zeitwerk (from zeitwerk's own test/support/loader_test)
28
+ Zeitwerk::Registry.loaders.reject! do |loader|
29
+ test_loader = loader.dirs.any? { |dir|
30
+ dir.include?("/spec/") || dir.include?(Dir.tmpdir) ||
31
+ dir.include?("/slices/") || dir.include?("/app")
32
+ }
33
+
34
+ if test_loader
35
+ loader.unregister
36
+ true
37
+ else
38
+ false
39
+ end
40
+ end
41
+ end
42
+
26
43
  RSpec.configure do |config|
27
44
  config.include RSpec::Support::Files, :app_integration
28
45
  config.include RSpec::Support::WithTmpDirectory, :app_integration
@@ -36,21 +53,7 @@ RSpec.configure do |config|
36
53
  end
37
54
 
38
55
  config.after :each, :app_integration do
39
- # Tear down Zeitwerk (from zeitwerk's own test/support/loader_test)
40
- Zeitwerk::Registry.loaders.each(&:unload)
41
- Zeitwerk::Registry.loaders.clear
42
-
43
- # This private interface changes between 2.5.4 and 2.6.0
44
- if Zeitwerk::Registry.respond_to?(:loaders_managing_gems)
45
- Zeitwerk::Registry.loaders_managing_gems.clear
46
- else
47
- Zeitwerk::Registry.gem_loaders_by_root_file.clear
48
- Zeitwerk::Registry.autoloads.clear
49
- Zeitwerk::Registry.inceptions.clear
50
- end
51
-
52
- Zeitwerk::ExplicitNamespace.cpaths.clear
53
- Zeitwerk::ExplicitNamespace.tracer.disable
56
+ autoloaders_teardown!
54
57
 
55
58
  Hanami.instance_variable_set(:@_bundled, {})
56
59
  Hanami.remove_instance_variable(:@_app) if Hanami.instance_variable_defined?(:@_app)
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration/actions"
3
+ require "hanami/config/actions"
4
4
 
5
- RSpec.describe Hanami::Configuration::Actions, "#content_security_policy" do
6
- let(:configuration) { described_class.new }
7
- subject(:content_security_policy) { configuration.content_security_policy }
5
+ RSpec.describe Hanami::Config::Actions, "#content_security_policy" do
6
+ let(:config) { described_class.new }
7
+ subject(:content_security_policy) { config.content_security_policy }
8
8
 
9
9
  context "no CSP config specified" do
10
10
  context "without assets_server_url" do
@@ -34,7 +34,7 @@ RSpec.describe Hanami::Configuration::Actions, "#content_security_policy" do
34
34
  end
35
35
 
36
36
  context "with assets_server_url" do
37
- let(:configuration) { described_class.new(assets_server_url: assets_server_url) }
37
+ let(:config) { described_class.new(assets_server_url: assets_server_url) }
38
38
  let(:assets_server_url) { "http://localhost:8080" }
39
39
 
40
40
  it "includes server url" do
@@ -85,18 +85,18 @@ RSpec.describe Hanami::Configuration::Actions, "#content_security_policy" do
85
85
 
86
86
  context "with CSP enabled" do
87
87
  it "sets default header" do
88
- configuration.finalize!
88
+ config.finalize!
89
89
 
90
- expect(configuration.default_headers.fetch("Content-Security-Policy")).to eq(content_security_policy.to_str)
90
+ expect(config.default_headers.fetch("Content-Security-Policy")).to eq(content_security_policy.to_str)
91
91
  end
92
92
  end
93
93
 
94
94
  context "with CSP disabled" do
95
95
  it "doesn't set default header" do
96
- configuration.content_security_policy = false
97
- configuration.finalize!
96
+ config.content_security_policy = false
97
+ config.finalize!
98
98
 
99
- expect(configuration.default_headers.key?("Content-Security-Policy")).to be(false)
99
+ expect(config.default_headers.key?("Content-Security-Policy")).to be(false)
100
100
  end
101
101
  end
102
102
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration/actions"
3
+ require "hanami/config/actions"
4
4
 
5
- RSpec.describe Hanami::Configuration::Actions, "#cookies" do
6
- let(:configuration) { described_class.new }
7
- subject(:cookies) { configuration.cookies }
5
+ RSpec.describe Hanami::Config::Actions, "#cookies" do
6
+ let(:config) { described_class.new }
7
+ subject(:cookies) { config.cookies }
8
8
 
9
9
  context "default config" do
10
10
  it "is enabled" do
@@ -18,7 +18,7 @@ RSpec.describe Hanami::Configuration::Actions, "#cookies" do
18
18
 
19
19
  context "options given" do
20
20
  before do
21
- configuration.cookies = {max_age: 300}
21
+ config.cookies = {max_age: 300}
22
22
  end
23
23
 
24
24
  it "is enabled" do
@@ -32,7 +32,7 @@ RSpec.describe Hanami::Configuration::Actions, "#cookies" do
32
32
 
33
33
  context "nil value given" do
34
34
  before do
35
- configuration.cookies = nil
35
+ config.cookies = nil
36
36
  end
37
37
 
38
38
  it "is not enabled" do
@@ -1,32 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration/actions"
3
+ require "hanami/config/actions"
4
4
 
5
- RSpec.describe Hanami::Configuration::Actions, "#csrf_protection" do
6
- let(:configuration) { described_class.new }
7
- subject(:value) { configuration.csrf_protection }
5
+ RSpec.describe Hanami::Config::Actions, "#csrf_protection" do
6
+ let(:config) { described_class.new }
7
+ subject(:value) { config.csrf_protection }
8
8
 
9
- context "non-finalized configuration" do
9
+ context "non-finalized config" do
10
10
  it "returns a default of nil" do
11
11
  is_expected.to be_nil
12
12
  end
13
13
 
14
14
  it "can be explicitly enabled" do
15
- configuration.csrf_protection = true
15
+ config.csrf_protection = true
16
16
  is_expected.to be true
17
17
  end
18
18
 
19
19
  it "can be explicitly disabled" do
20
- configuration.csrf_protection = false
20
+ config.csrf_protection = false
21
21
  is_expected.to be false
22
22
  end
23
23
  end
24
24
 
25
- context "finalized configuration" do
25
+ context "finalized config" do
26
26
  context "sessions enabled" do
27
27
  before do
28
- configuration.sessions = :cookie, {secret: "abc"}
29
- configuration.finalize!
28
+ config.sessions = :cookie, {secret: "abc"}
29
+ config.finalize!
30
30
  end
31
31
 
32
32
  it "is true" do
@@ -35,7 +35,7 @@ RSpec.describe Hanami::Configuration::Actions, "#csrf_protection" do
35
35
 
36
36
  context "explicitly disabled" do
37
37
  before do
38
- configuration.csrf_protection = false
38
+ config.csrf_protection = false
39
39
  end
40
40
 
41
41
  it "is false" do
@@ -46,7 +46,7 @@ RSpec.describe Hanami::Configuration::Actions, "#csrf_protection" do
46
46
 
47
47
  context "sessions not enabled" do
48
48
  before do
49
- configuration.finalize!
49
+ config.finalize!
50
50
  end
51
51
 
52
52
  it "is true" do
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/config/actions"
4
+
5
+ RSpec.describe Hanami::Config::Actions, "default values" do
6
+ subject(:config) { described_class.new }
7
+
8
+ describe "sessions" do
9
+ specify { expect(config.sessions).not_to be_enabled }
10
+ end
11
+
12
+ describe "name_inference_base" do
13
+ specify { expect(config.name_inference_base).to eq "actions" }
14
+ end
15
+
16
+ describe "view_context_identifier" do
17
+ specify { expect(config.view_context_identifier).to eq "views.context" }
18
+ end
19
+
20
+ describe "view_name_inferrer" do
21
+ specify { expect(config.view_name_inferrer).to eq Hanami::Slice::ViewNameInferrer }
22
+ end
23
+
24
+ describe "view_name_inference_base" do
25
+ specify { expect(config.view_name_inference_base).to eq "views" }
26
+ end
27
+
28
+ describe "new default values applied to base action settings" do
29
+ describe "default_request_format" do
30
+ specify { expect(config.default_request_format).to eq :html }
31
+ end
32
+
33
+ describe "default_response_format" do
34
+ specify { expect(config.default_response_format).to eq :html }
35
+ end
36
+
37
+ describe "content_security_policy" do
38
+ specify { expect(config.content_security_policy).to be_kind_of(Hanami::Config::Actions::ContentSecurityPolicy) }
39
+ end
40
+
41
+ describe "default_headers" do
42
+ specify {
43
+ config.finalize!
44
+
45
+ expect(config.default_headers).to eq(
46
+ "X-Frame-Options" => "DENY",
47
+ "X-Content-Type-Options" => "nosniff",
48
+ "X-XSS-Protection" => "1; mode=block",
49
+ "Content-Security-Policy" => config.content_security_policy.to_str
50
+ )
51
+ }
52
+ end
53
+ end
54
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration/actions"
3
+ require "hanami/config/actions"
4
4
 
5
- RSpec.describe Hanami::Configuration::Actions, "#sessions" do
6
- let(:configuration) { described_class.new }
7
- subject(:sessions) { configuration.sessions }
5
+ RSpec.describe Hanami::Config::Actions, "#sessions" do
6
+ let(:config) { described_class.new }
7
+ subject(:sessions) { config.sessions }
8
8
 
9
9
  context "no session config specified" do
10
10
  it "is not enabled" do
@@ -26,7 +26,7 @@ RSpec.describe Hanami::Configuration::Actions, "#sessions" do
26
26
 
27
27
  context "valid session config provided" do
28
28
  before do
29
- configuration.sessions = :cookie, {secret: "abc"}
29
+ config.sessions = :cookie, {secret: "abc"}
30
30
  end
31
31
 
32
32
  it "is enabled" do
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration"
4
- require "hanami/configuration/actions"
5
- require "hanami/action/configuration"
3
+ require "hanami/config"
4
+ require "hanami/action"
6
5
 
7
- RSpec.describe Hanami::Configuration, "#actions" do
8
- let(:configuration) { described_class.new(app_name: app_name, env: :development) }
6
+ RSpec.describe Hanami::Config, "#actions" do
7
+ let(:config) { described_class.new(app_name: app_name, env: :development) }
9
8
  let(:app_name) { "MyApp::app" }
10
9
 
11
- subject(:actions) { configuration.actions }
10
+ subject(:actions) { config.actions }
12
11
 
13
- context "Hanami::Action available" do
14
- it "is a full actions configuration" do
15
- is_expected.to be_an_instance_of(Hanami::Configuration::Actions)
12
+ context "hanami-controller is bundled" do
13
+ it "is a full actions config" do
14
+ is_expected.to be_an_instance_of(Hanami::Config::Actions)
16
15
 
17
16
  is_expected.to respond_to(:default_response_format)
18
17
  is_expected.to respond_to(:default_response_format=)
@@ -43,30 +42,19 @@ RSpec.describe Hanami::Configuration, "#actions" do
43
42
  end
44
43
 
45
44
  it "includes all base action settings" do
46
- expect(actions.settings).to include(Hanami::Action::Configuration.settings)
45
+ expect(actions.settings).to include(Hanami::Action.settings)
47
46
  end
48
47
  end
49
48
  end
50
49
 
51
- context "Hanami::Action not available" do
50
+ context "hanami-controller is not bundled" do
52
51
  before do
53
- load_error = LoadError.new.tap do |error|
54
- error.instance_variable_set :@path, "hanami/action"
55
- end
56
-
57
- allow_any_instance_of(described_class)
58
- .to receive(:require)
59
- .with(anything)
60
- .and_call_original
61
-
62
- allow_any_instance_of(described_class)
63
- .to receive(:require)
64
- .with("hanami/action")
65
- .and_raise load_error
52
+ allow(Hanami).to receive(:bundled?).and_call_original
53
+ expect(Hanami).to receive(:bundled?).with("hanami-controller").and_return(false)
66
54
  end
67
55
 
68
56
  it "does not expose any settings" do
69
- is_expected.not_to be_an_instance_of(Hanami::Configuration::Actions)
57
+ is_expected.not_to be_an_instance_of(Hanami::Config::Actions)
70
58
  is_expected.not_to respond_to(:default_response_format)
71
59
  is_expected.not_to respond_to(:default_response_format=)
72
60
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration"
3
+ require "hanami/config"
4
4
  require "uri"
5
5
 
6
- RSpec.describe Hanami::Configuration, "base_url" do
6
+ RSpec.describe Hanami::Config, "base_url" do
7
7
  subject(:config) { described_class.new(app_name: app_name, env: :development) }
8
8
  let(:app_name) { "MyApp::app" }
9
9
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration"
3
+ require "hanami/config"
4
4
 
5
- RSpec.describe Hanami::Configuration do
5
+ RSpec.describe Hanami::Config do
6
6
  subject(:config) { described_class.new(app_name: app_name, env: :development) }
7
7
  let(:app_name) { "MyApp::app" }
8
8
 
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration/logger"
3
+ require "hanami/config/logger"
4
4
  require "hanami/slice_name"
5
5
  require "dry/inflector"
6
6
  require "logger"
7
7
 
8
- RSpec.describe Hanami::Configuration::Logger do
8
+ RSpec.describe Hanami::Config::Logger do
9
9
  subject { described_class.new(app_name: app_name, env: env) }
10
10
  let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::app"), inflector: -> { Dry::Inflector.new }) }
11
11
  let(:env) { :development }
@@ -165,7 +165,7 @@ RSpec.describe Hanami::Configuration::Logger do
165
165
  end
166
166
  end
167
167
 
168
- RSpec.describe Hanami::Configuration do
168
+ RSpec.describe Hanami::Config do
169
169
  subject(:config) { described_class.new(app_name: app_name, env: env) }
170
170
  let(:app_name) { Hanami::SliceName.new(double(name: "SOS::app"), inflector: -> { Dry::Inflector.new }) }
171
171
  let(:env) { :development }
@@ -180,7 +180,7 @@ RSpec.describe Hanami::Configuration do
180
180
  end
181
181
 
182
182
  describe "#app_name" do
183
- it "defaults to Hanami::Configuration#app_name" do
183
+ it "defaults to Hanami::Config#app_name" do
184
184
  expect(config.logger.app_name).to eq(config.app_name)
185
185
  end
186
186
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/config"
4
+
5
+ RSpec.describe Hanami::Config, "#router" do
6
+ let(:config) { described_class.new(app_name: app_name, env: :development) }
7
+ let(:app_name) { "MyApp::app" }
8
+
9
+ subject(:router) { config.router }
10
+
11
+ context "hanami-router is bundled" do
12
+ it "is a full router configuration" do
13
+ is_expected.to be_an_instance_of(Hanami::Config::Router)
14
+
15
+ is_expected.to respond_to(:resolver)
16
+ end
17
+
18
+ it "loads the middleware stack" do
19
+ subject
20
+
21
+ expect(config.middleware_stack).not_to be_nil
22
+ end
23
+
24
+ it "can be finalized" do
25
+ is_expected.to respond_to(:finalize!)
26
+ end
27
+ end
28
+
29
+ context "hanami-router is not bundled" do
30
+ before do
31
+ allow(Hanami).to receive(:bundled?).and_call_original
32
+ expect(Hanami).to receive(:bundled?).with("hanami-router").and_return(false)
33
+ end
34
+
35
+ it "does not expose any settings" do
36
+ is_expected.not_to be_an_instance_of(Hanami::Config::Router)
37
+ is_expected.not_to respond_to(:resolver)
38
+ end
39
+
40
+ it "can be finalized" do
41
+ is_expected.to respond_to(:finalize!)
42
+ end
43
+ end
44
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/inflector"
4
- require "hanami/configuration"
4
+ require "hanami/config"
5
5
  require "hanami/slice_name"
6
6
 
7
- RSpec.describe Hanami::Configuration, "#slices" do
7
+ RSpec.describe Hanami::Config, "#slices" do
8
8
  subject(:config) { described_class.new(app_name: app_name, env: :development) }
9
9
  let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::App"), inflector: Dry::Inflector.new) }
10
10
 
@@ -1,25 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/configuration"
4
- require "hanami/configuration/views"
3
+ require "hanami/config"
5
4
  require "saharspec/matchers/dont"
6
5
 
7
- RSpec.describe Hanami::Configuration, "#views" do
8
- let(:configuration) { described_class.new(app_name: app_name, env: :development) }
6
+ RSpec.describe Hanami::Config, "#views" do
7
+ let(:config) { described_class.new(app_name: app_name, env: :development) }
9
8
  let(:app_name) { "MyApp::app" }
10
9
 
11
- subject(:views) { configuration.views }
10
+ subject(:views) { config.views }
12
11
 
13
- context "Hanami::View available" do
14
- it "exposes Hanami::Views's app configuration" do
15
- is_expected.to be_an_instance_of(Hanami::Configuration::Views)
12
+ context "hanami-view is bundled" do
13
+ it "exposes Hanami::Views's app config" do
14
+ is_expected.to be_an_instance_of(Hanami::Config::Views)
16
15
 
17
16
  is_expected.to respond_to(:finalize!)
18
17
  is_expected.to respond_to(:layouts_dir)
19
18
  is_expected.to respond_to(:layouts_dir=)
20
19
  end
21
20
 
22
- it "includes base view configuration" do
21
+ it "includes base view config" do
23
22
  expect(views).to respond_to(:paths)
24
23
  expect(views).to respond_to(:paths=)
25
24
  end
@@ -39,11 +38,11 @@ RSpec.describe Hanami::Configuration, "#views" do
39
38
  end
40
39
  end
41
40
 
42
- it "preserves default values from the base view configuration" do
41
+ it "preserves default values from the base view config" do
43
42
  expect(views.layouts_dir).to eq Hanami::View.config.layouts_dir
44
43
  end
45
44
 
46
- it "allows settings to be configured independently of the base view configuration" do
45
+ it "allows settings to be configured independently of the base view config" do
47
46
  expect { views.layouts_dir = "custom_layouts" }
48
47
  .to change { views.layouts_dir }.to("custom_layouts")
49
48
  .and(dont.change { Hanami::View.config.layouts_dir })
@@ -71,7 +70,7 @@ RSpec.describe Hanami::Configuration, "#views" do
71
70
  end
72
71
  end
73
72
 
74
- describe "finalized configuration" do
73
+ describe "finalized config" do
75
74
  before do
76
75
  views.finalize!
77
76
  end
@@ -90,25 +89,14 @@ RSpec.describe Hanami::Configuration, "#views" do
90
89
  end
91
90
  end
92
91
 
93
- context "Hanami::View not available" do
92
+ context "hanami-view is not bundled" do
94
93
  before do
95
- load_error = LoadError.new.tap do |error|
96
- error.instance_variable_set :@path, "hanami/view"
97
- end
98
-
99
- allow_any_instance_of(described_class)
100
- .to receive(:require)
101
- .with(anything)
102
- .and_call_original
103
-
104
- allow_any_instance_of(described_class)
105
- .to receive(:require)
106
- .with("hanami/view")
107
- .and_raise load_error
94
+ allow(Hanami).to receive(:bundled?).and_call_original
95
+ expect(Hanami).to receive(:bundled?).with("hanami-view").and_return(false)
108
96
  end
109
97
 
110
98
  it "does not expose any settings" do
111
- is_expected.not_to be_an_instance_of(Hanami::Configuration::Views)
99
+ is_expected.not_to be_an_instance_of(Hanami::Config::Views)
112
100
  is_expected.not_to respond_to(:layouts_dir)
113
101
  is_expected.not_to respond_to(:layouts_dir=)
114
102
  end
@@ -1,11 +1,11 @@
1
- require "hanami/configuration"
1
+ require "hanami/config"
2
2
 
3
- RSpec.describe Hanami::Configuration do
3
+ RSpec.describe Hanami::Config do
4
4
  let(:config) { described_class.new(app_name: app_name, env: env) }
5
5
  let(:app_name) { "MyApp::app" }
6
6
  let(:env) { :development }
7
7
 
8
- describe "environment-specific configuration" do
8
+ describe "environment-specific config" do
9
9
  before do
10
10
  config.logger.level = :debug__set_without_env
11
11
  end