hanami 2.0.0.alpha8 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +442 -241
  3. data/FEATURES.md +30 -9
  4. data/README.md +1 -3
  5. data/hanami.gemspec +21 -11
  6. data/lib/hanami/app.rb +141 -0
  7. data/lib/hanami/assets/application_configuration.rb +10 -4
  8. data/lib/hanami/configuration/actions/content_security_policy.rb +5 -5
  9. data/lib/hanami/configuration/actions/cookies.rb +2 -2
  10. data/lib/hanami/configuration/actions.rb +10 -4
  11. data/lib/hanami/configuration/logger.rb +4 -4
  12. data/lib/hanami/configuration/router.rb +2 -6
  13. data/lib/hanami/configuration/sessions.rb +1 -1
  14. data/lib/hanami/configuration/views.rb +9 -4
  15. data/lib/hanami/configuration.rb +118 -46
  16. data/lib/hanami/constants.rb +24 -2
  17. data/lib/hanami/errors.rb +1 -1
  18. data/lib/hanami/{application → extensions}/action/slice_configured_action.rb +9 -9
  19. data/lib/hanami/extensions/action.rb +79 -0
  20. data/lib/hanami/extensions/view/context.rb +106 -0
  21. data/lib/hanami/{application → extensions}/view/slice_configured_context.rb +10 -10
  22. data/lib/hanami/{application → extensions}/view/slice_configured_view.rb +12 -6
  23. data/lib/hanami/extensions/view.rb +33 -0
  24. data/lib/hanami/extensions.rb +10 -0
  25. data/lib/hanami/providers/inflector.rb +13 -0
  26. data/lib/hanami/providers/logger.rb +13 -0
  27. data/lib/hanami/providers/rack.rb +27 -0
  28. data/lib/hanami/providers/routes.rb +33 -0
  29. data/lib/hanami/providers/settings.rb +23 -0
  30. data/lib/hanami/rake_tasks.rb +61 -0
  31. data/lib/hanami/routes.rb +51 -0
  32. data/lib/hanami/server.rb +1 -1
  33. data/lib/hanami/settings/dotenv_store.rb +58 -0
  34. data/lib/hanami/settings.rb +90 -0
  35. data/lib/hanami/setup.rb +4 -2
  36. data/lib/hanami/{application → slice}/router.rb +18 -13
  37. data/lib/hanami/slice/routes_helper.rb +37 -0
  38. data/lib/hanami/{application → slice}/routing/middleware/stack.rb +43 -5
  39. data/lib/hanami/slice/routing/resolver.rb +97 -0
  40. data/lib/hanami/{application → slice}/view_name_inferrer.rb +3 -3
  41. data/lib/hanami/slice.rb +246 -73
  42. data/lib/hanami/slice_configurable.rb +4 -17
  43. data/lib/hanami/slice_name.rb +6 -6
  44. data/lib/hanami/slice_registrar.rb +119 -0
  45. data/lib/hanami/version.rb +1 -1
  46. data/lib/hanami/web/rack_logger.rb +1 -1
  47. data/lib/hanami.rb +34 -26
  48. data/spec/integration/application_middleware_stack_spec.rb +84 -0
  49. data/spec/integration/assets/cdn_spec.rb +48 -0
  50. data/spec/integration/assets/fingerprint_spec.rb +42 -0
  51. data/spec/integration/assets/helpers_spec.rb +50 -0
  52. data/spec/integration/assets/serve_spec.rb +70 -0
  53. data/spec/integration/assets/subresource_integrity_spec.rb +54 -0
  54. data/spec/integration/body_parsers_spec.rb +50 -0
  55. data/spec/integration/cli/assets/precompile_spec.rb +147 -0
  56. data/spec/integration/cli/assets_spec.rb +14 -0
  57. data/spec/integration/cli/console_spec.rb +105 -0
  58. data/spec/integration/cli/db/apply_spec.rb +74 -0
  59. data/spec/integration/cli/db/console_spec.rb +40 -0
  60. data/spec/integration/cli/db/create_spec.rb +50 -0
  61. data/spec/integration/cli/db/drop_spec.rb +54 -0
  62. data/spec/integration/cli/db/migrate_spec.rb +108 -0
  63. data/spec/integration/cli/db/prepare_spec.rb +36 -0
  64. data/spec/integration/cli/db/rollback_spec.rb +96 -0
  65. data/spec/integration/cli/db/version_spec.rb +38 -0
  66. data/spec/integration/cli/db_spec.rb +21 -0
  67. data/spec/integration/cli/destroy/action_spec.rb +143 -0
  68. data/spec/integration/cli/destroy/app_spec.rb +118 -0
  69. data/spec/integration/cli/destroy/mailer_spec.rb +74 -0
  70. data/spec/integration/cli/destroy/migration_spec.rb +70 -0
  71. data/spec/integration/cli/destroy/model_spec.rb +113 -0
  72. data/spec/integration/cli/destroy_spec.rb +18 -0
  73. data/spec/integration/cli/generate/action_spec.rb +469 -0
  74. data/spec/integration/cli/generate/app_spec.rb +215 -0
  75. data/spec/integration/cli/generate/mailer_spec.rb +189 -0
  76. data/spec/integration/cli/generate/migration_spec.rb +72 -0
  77. data/spec/integration/cli/generate/model_spec.rb +290 -0
  78. data/spec/integration/cli/generate/secret_spec.rb +56 -0
  79. data/spec/integration/cli/generate_spec.rb +19 -0
  80. data/spec/integration/cli/new/database_spec.rb +235 -0
  81. data/spec/integration/cli/new/hanami_head_spec.rb +27 -0
  82. data/spec/integration/cli/new/template_spec.rb +118 -0
  83. data/spec/integration/cli/new/test_spec.rb +274 -0
  84. data/spec/integration/cli/new_spec.rb +970 -0
  85. data/spec/integration/cli/plugins_spec.rb +39 -0
  86. data/spec/integration/cli/routes_spec.rb +49 -0
  87. data/spec/integration/cli/server_spec.rb +626 -0
  88. data/spec/integration/cli/version_spec.rb +85 -0
  89. data/spec/integration/early_hints_spec.rb +35 -0
  90. data/spec/integration/handle_exceptions_spec.rb +244 -0
  91. data/spec/integration/head_spec.rb +89 -0
  92. data/spec/integration/http_headers_spec.rb +29 -0
  93. data/spec/integration/mailer_spec.rb +32 -0
  94. data/spec/integration/middleware_spec.rb +81 -0
  95. data/spec/integration/mount_applications_spec.rb +88 -0
  96. data/spec/integration/project_initializers_spec.rb +40 -0
  97. data/spec/integration/rackup_spec.rb +35 -0
  98. data/spec/integration/rake/with_minitest_spec.rb +67 -0
  99. data/spec/integration/rake/with_rspec_spec.rb +69 -0
  100. data/spec/integration/routing_helpers_spec.rb +61 -0
  101. data/spec/integration/security/content_security_policy_spec.rb +46 -0
  102. data/spec/integration/security/csrf_protection_spec.rb +42 -0
  103. data/spec/integration/security/force_ssl_spec.rb +29 -0
  104. data/spec/integration/security/x_content_type_options_spec.rb +46 -0
  105. data/spec/integration/security/x_frame_options_spec.rb +46 -0
  106. data/spec/integration/security/x_xss_protection_spec.rb +46 -0
  107. data/spec/integration/send_file_spec.rb +51 -0
  108. data/spec/integration/sessions_spec.rb +247 -0
  109. data/spec/integration/static_middleware_spec.rb +21 -0
  110. data/spec/integration/streaming_spec.rb +41 -0
  111. data/spec/integration/unsafe_send_file_spec.rb +52 -0
  112. data/spec/isolation/hanami/application/already_configured_spec.rb +19 -0
  113. data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +10 -0
  114. data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +14 -0
  115. data/spec/isolation/hanami/application/not_configured_spec.rb +9 -0
  116. data/spec/isolation/hanami/application/routes/configured_spec.rb +44 -0
  117. data/spec/isolation/hanami/application/routes/not_configured_spec.rb +16 -0
  118. data/spec/isolation/hanami/boot/success_spec.rb +50 -0
  119. data/spec/new_integration/action/configuration_spec.rb +26 -0
  120. data/spec/new_integration/action/cookies_spec.rb +58 -0
  121. data/spec/new_integration/action/csrf_protection_spec.rb +54 -0
  122. data/spec/new_integration/action/routes_spec.rb +73 -0
  123. data/spec/new_integration/action/sessions_spec.rb +50 -0
  124. data/spec/new_integration/action/view_integration_spec.rb +165 -0
  125. data/spec/new_integration/action/view_rendering/automatic_rendering_spec.rb +247 -0
  126. data/spec/new_integration/action/view_rendering/paired_view_inference_spec.rb +115 -0
  127. data/spec/new_integration/action/view_rendering_spec.rb +107 -0
  128. data/spec/new_integration/code_loading/loading_from_app_spec.rb +152 -0
  129. data/spec/new_integration/code_loading/loading_from_slice_spec.rb +165 -0
  130. data/spec/new_integration/container/application_routes_helper_spec.rb +48 -0
  131. data/spec/new_integration/container/auto_injection_spec.rb +53 -0
  132. data/spec/new_integration/container/auto_registration_spec.rb +86 -0
  133. data/spec/new_integration/container/autoloader_spec.rb +80 -0
  134. data/spec/new_integration/container/imports_spec.rb +253 -0
  135. data/spec/new_integration/container/prepare_container_spec.rb +123 -0
  136. data/spec/new_integration/container/shutdown_spec.rb +91 -0
  137. data/spec/new_integration/container/standard_bootable_components_spec.rb +124 -0
  138. data/spec/new_integration/rack_app/middleware_spec.rb +215 -0
  139. data/spec/new_integration/rack_app/non_booted_rack_app_spec.rb +105 -0
  140. data/spec/new_integration/rack_app/rack_app_spec.rb +524 -0
  141. data/spec/new_integration/settings_spec.rb +115 -0
  142. data/spec/new_integration/slices/external_slice_spec.rb +92 -0
  143. data/spec/new_integration/slices/slice_configuration_spec.rb +40 -0
  144. data/spec/new_integration/slices/slice_routing_spec.rb +226 -0
  145. data/spec/new_integration/slices/slice_settings_spec.rb +141 -0
  146. data/spec/new_integration/slices_spec.rb +101 -0
  147. data/spec/new_integration/view/configuration_spec.rb +49 -0
  148. data/spec/new_integration/view/context/assets_spec.rb +67 -0
  149. data/spec/new_integration/view/context/inflector_spec.rb +48 -0
  150. data/spec/new_integration/view/context/request_spec.rb +61 -0
  151. data/spec/new_integration/view/context/routes_spec.rb +86 -0
  152. data/spec/new_integration/view/context/settings_spec.rb +50 -0
  153. data/spec/new_integration/view/inflector_spec.rb +57 -0
  154. data/spec/new_integration/view/part_namespace_spec.rb +96 -0
  155. data/spec/new_integration/view/path_spec.rb +56 -0
  156. data/spec/new_integration/view/template_spec.rb +68 -0
  157. data/spec/new_integration/view/views_spec.rb +103 -0
  158. data/spec/spec_helper.rb +16 -0
  159. data/spec/support/app_integration.rb +91 -0
  160. data/spec/support/coverage.rb +1 -0
  161. data/spec/support/fixtures/hanami-plugin/Gemfile +8 -0
  162. data/spec/support/fixtures/hanami-plugin/README.md +35 -0
  163. data/spec/support/fixtures/hanami-plugin/Rakefile +4 -0
  164. data/spec/support/fixtures/hanami-plugin/bin/console +15 -0
  165. data/spec/support/fixtures/hanami-plugin/bin/setup +8 -0
  166. data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +28 -0
  167. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +19 -0
  168. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +7 -0
  169. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +8 -0
  170. data/spec/support/rspec.rb +27 -0
  171. data/spec/support/shared_examples/cli/generate/app.rb +494 -0
  172. data/spec/support/shared_examples/cli/generate/migration.rb +32 -0
  173. data/spec/support/shared_examples/cli/generate/model.rb +81 -0
  174. data/spec/support/shared_examples/cli/new.rb +97 -0
  175. data/spec/unit/hanami/configuration/actions/content_security_policy_spec.rb +102 -0
  176. data/spec/unit/hanami/configuration/actions/cookies_spec.rb +46 -0
  177. data/spec/unit/hanami/configuration/actions/csrf_protection_spec.rb +57 -0
  178. data/spec/unit/hanami/configuration/actions/default_values_spec.rb +52 -0
  179. data/spec/unit/hanami/configuration/actions/sessions_spec.rb +50 -0
  180. data/spec/unit/hanami/configuration/actions_spec.rb +78 -0
  181. data/spec/unit/hanami/configuration/base_url_spec.rb +25 -0
  182. data/spec/unit/hanami/configuration/inflector_spec.rb +35 -0
  183. data/spec/unit/hanami/configuration/logger_spec.rb +203 -0
  184. data/spec/unit/hanami/configuration/views_spec.rb +120 -0
  185. data/spec/unit/hanami/configuration_spec.rb +43 -0
  186. data/spec/unit/hanami/env_spec.rb +54 -0
  187. data/spec/unit/hanami/routes_spec.rb +25 -0
  188. data/spec/unit/hanami/settings/dotenv_store_spec.rb +119 -0
  189. data/spec/unit/hanami/settings_spec.rb +56 -0
  190. data/spec/unit/hanami/slice_configurable_spec.rb +104 -0
  191. data/spec/unit/hanami/slice_name_spec.rb +47 -0
  192. data/spec/unit/hanami/slice_spec.rb +17 -0
  193. data/spec/unit/hanami/version_spec.rb +7 -0
  194. data/spec/unit/hanami/web/rack_logger_spec.rb +78 -0
  195. metadata +353 -57
  196. data/lib/hanami/application/action.rb +0 -72
  197. data/lib/hanami/application/container/providers/inflector.rb +0 -7
  198. data/lib/hanami/application/container/providers/logger.rb +0 -7
  199. data/lib/hanami/application/container/providers/rack_logger.rb +0 -15
  200. data/lib/hanami/application/container/providers/rack_monitor.rb +0 -12
  201. data/lib/hanami/application/container/providers/routes_helper.rb +0 -9
  202. data/lib/hanami/application/container/providers/settings.rb +0 -7
  203. data/lib/hanami/application/routes.rb +0 -55
  204. data/lib/hanami/application/routes_helper.rb +0 -34
  205. data/lib/hanami/application/routing/resolver/node.rb +0 -50
  206. data/lib/hanami/application/routing/resolver/trie.rb +0 -59
  207. data/lib/hanami/application/routing/resolver.rb +0 -87
  208. data/lib/hanami/application/routing/router.rb +0 -36
  209. data/lib/hanami/application/settings/dotenv_store.rb +0 -60
  210. data/lib/hanami/application/settings.rb +0 -93
  211. data/lib/hanami/application/slice_registrar.rb +0 -106
  212. data/lib/hanami/application/view/context.rb +0 -95
  213. data/lib/hanami/application/view.rb +0 -24
  214. data/lib/hanami/application.rb +0 -273
  215. data/lib/hanami/cli/application/cli.rb +0 -40
  216. data/lib/hanami/cli/application/command.rb +0 -47
  217. data/lib/hanami/cli/application/commands/console.rb +0 -81
  218. data/lib/hanami/cli/application/commands.rb +0 -16
  219. data/lib/hanami/cli/base_command.rb +0 -48
  220. data/lib/hanami/cli/commands/command.rb +0 -171
  221. data/lib/hanami/cli/commands/server.rb +0 -88
  222. data/lib/hanami/cli/commands.rb +0 -65
  223. data/lib/hanami/configuration/middleware.rb +0 -20
  224. data/lib/hanami/configuration/source_dirs.rb +0 -42
@@ -0,0 +1,235 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "hanami new", type: :integration do
4
+ describe "--database" do
5
+ context "postgres" do
6
+ it "generates project" do
7
+ project = "bookshelf_postgresql"
8
+ output = [
9
+ "create db/migrations/.gitkeep",
10
+ "create db/schema.sql"
11
+ ]
12
+
13
+ run_cmd "hanami new #{project} --database=postgres", output
14
+
15
+ within_project_directory(project) do
16
+ #
17
+ # .env.development
18
+ #
19
+ development_url = Platform.match do
20
+ engine(:ruby) { "postgresql://localhost/#{project}_development" }
21
+ engine(:jruby) { "jdbc:postgresql://localhost/#{project}_development" }
22
+ end
23
+
24
+ expect(".env.development").to have_file_content(%r{DATABASE_URL="#{development_url}"})
25
+
26
+ #
27
+ # .env.test
28
+ #
29
+ test_url = Platform.match do
30
+ engine(:ruby) { "postgresql://localhost/#{project}_test" }
31
+ engine(:jruby) { "jdbc:postgresql://localhost/#{project}_test" }
32
+ end
33
+
34
+ expect(".env.test").to have_file_content(%r{DATABASE_URL="#{test_url}"})
35
+
36
+ #
37
+ # Gemfile
38
+ #
39
+ gem_name = Platform.match do
40
+ engine(:ruby) { "pg" }
41
+ engine(:jruby) { "jdbc-postgres" }
42
+ end
43
+
44
+ expect("Gemfile").to have_file_content(%r{gem '#{gem_name}'})
45
+
46
+ #
47
+ # config/environment.rb
48
+ #
49
+ expect("config/environment.rb").to have_file_content(%r{ adapter :sql, ENV.fetch\('DATABASE_URL'\)})
50
+ expect("config/environment.rb").to have_file_content(%r{ migrations 'db/migrations'})
51
+ expect("config/environment.rb").to have_file_content(%r{ schema 'db/schema.sql'})
52
+
53
+ #
54
+ # db/migrations/.gitkeep
55
+ #
56
+ expect("db/migrations/.gitkeep").to be_an_existing_file
57
+
58
+ #
59
+ # db/schema.sql
60
+ #
61
+ expect("db/schema.sql").to be_an_existing_file
62
+
63
+ #
64
+ # .gitignore
65
+ #
66
+ expect(".gitignore").to have_file_content <<-END
67
+ /public/assets*
68
+ /tmp
69
+ .env.local
70
+ .env.*.local
71
+ END
72
+ end
73
+ end
74
+ end # postgres
75
+
76
+ describe "sqlite" do
77
+ it "generates project" do
78
+ project = "bookshelf_sqlite"
79
+ output = [
80
+ "create db/migrations/.gitkeep",
81
+ "create db/schema.sql"
82
+ ]
83
+
84
+ run_cmd "hanami new #{project} --database=sqlite", output
85
+
86
+ within_project_directory(project) do
87
+ #
88
+ # .env.development
89
+ #
90
+ development_url = Platform.match do
91
+ engine(:ruby) { "sqlite://db/#{project}_development.sqlite" }
92
+ engine(:jruby) { "jdbc:sqlite://db/#{project}_development.sqlite" }
93
+ end
94
+
95
+ expect(".env.development").to have_file_content(%r{DATABASE_URL="#{development_url}"})
96
+
97
+ #
98
+ # .env.test
99
+ #
100
+ test_url = Platform.match do
101
+ engine(:ruby) { "sqlite://db/#{project}_test.sqlite" }
102
+ engine(:jruby) { "jdbc:sqlite://db/#{project}_test.sqlite" }
103
+ end
104
+
105
+ expect(".env.test").to have_file_content(%r{DATABASE_URL="#{test_url}"})
106
+
107
+ #
108
+ # Gemfile
109
+ #
110
+ gem_name = Platform.match do
111
+ engine(:ruby) { "sqlite3" }
112
+ engine(:jruby) { "jdbc-sqlite3" }
113
+ end
114
+
115
+ expect("Gemfile").to have_file_content(%r{gem '#{gem_name}'})
116
+
117
+ #
118
+ # config/environment.rb
119
+ #
120
+ expect("config/environment.rb").to have_file_content(%r{ adapter :sql, ENV.fetch\('DATABASE_URL'\)})
121
+ expect("config/environment.rb").to have_file_content(%r{ migrations 'db/migrations'})
122
+ expect("config/environment.rb").to have_file_content(%r{ schema 'db/schema.sql'})
123
+
124
+ #
125
+ # db/migrations/.gitkeep
126
+ #
127
+ expect("db/migrations/.gitkeep").to be_an_existing_file
128
+
129
+ #
130
+ # db/schema.sql
131
+ #
132
+ expect("db/schema.sql").to be_an_existing_file
133
+
134
+ #
135
+ # .gitignore
136
+ #
137
+ expect(".gitignore").to have_file_content <<-END
138
+ /db/*.sqlite
139
+ /public/assets*
140
+ /tmp
141
+ .env.local
142
+ .env.*.local
143
+ END
144
+ end
145
+ end
146
+ end # sqlite
147
+
148
+ context "mysql" do
149
+ it "generates project" do
150
+ project = "bookshelf_mysql"
151
+ output = [
152
+ "create db/migrations/.gitkeep",
153
+ "create db/schema.sql"
154
+ ]
155
+
156
+ run_cmd "hanami new #{project} --database=mysql", output
157
+
158
+ within_project_directory(project) do
159
+ #
160
+ # .env.development
161
+ #
162
+ development_url = Platform.match do
163
+ engine(:ruby) { "mysql2://localhost/#{project}_development" }
164
+ engine(:jruby) { "jdbc:mysql://localhost/#{project}_development" }
165
+ end
166
+
167
+ expect(".env.development").to have_file_content(%r{DATABASE_URL="#{development_url}"})
168
+
169
+ #
170
+ # .env.test
171
+ #
172
+ test_url = Platform.match do
173
+ engine(:ruby) { "mysql2://localhost/#{project}_test" }
174
+ engine(:jruby) { "jdbc:mysql://localhost/#{project}_test" }
175
+ end
176
+
177
+ expect(".env.test").to have_file_content(%r{DATABASE_URL="#{test_url}"})
178
+
179
+ #
180
+ # Gemfile
181
+ #
182
+ gem_name = Platform.match do
183
+ engine(:ruby) { "mysql2" }
184
+ engine(:jruby) { "jdbc-mysql" }
185
+ end
186
+
187
+ expect("Gemfile").to have_file_content(%r{gem '#{gem_name}'})
188
+
189
+ #
190
+ # config/environment.rb
191
+ #
192
+ expect("config/environment.rb").to have_file_content(%r{ adapter :sql, ENV.fetch\('DATABASE_URL'\)})
193
+ expect("config/environment.rb").to have_file_content(%r{ migrations 'db/migrations'})
194
+ expect("config/environment.rb").to have_file_content(%r{ schema 'db/schema.sql'})
195
+
196
+ #
197
+ # db/migrations/.gitkeep
198
+ #
199
+ expect("db/migrations/.gitkeep").to be_an_existing_file
200
+
201
+ #
202
+ # db/schema.sql
203
+ #
204
+ expect("db/schema.sql").to be_an_existing_file
205
+
206
+ #
207
+ # .gitignore
208
+ #
209
+ expect(".gitignore").to have_file_content <<-END
210
+ /public/assets*
211
+ /tmp
212
+ .env.local
213
+ .env.*.local
214
+ END
215
+ end
216
+ end
217
+ end # mysql
218
+
219
+ context "missing" do
220
+ it "returns error" do
221
+ output = "`' is not a valid database engine"
222
+
223
+ run_cmd "hanami new bookshelf --database=", output, exit_status: 1
224
+ end
225
+ end # missing
226
+
227
+ context "unknown" do
228
+ it "returns error" do
229
+ output = "`foo' is not a valid database engine"
230
+
231
+ run_cmd "hanami new bookshelf --database=foo", output, exit_status: 1
232
+ end
233
+ end # unknown
234
+ end # database
235
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "hanami new", type: :integration do
4
+ describe "--hanami-head" do
5
+ it "generates project" do
6
+ project = "bookshelf_hanami_head"
7
+
8
+ run_cmd "hanami new #{project} --hanami-head"
9
+
10
+ within_project_directory(project) do
11
+ #
12
+ # Gemfile
13
+ #
14
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-utils', require: false, git: 'https://github.com/hanami/utils.git', branch: 'develop'})
15
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-validations', require: false, git: 'https://github.com/hanami/validations.git', branch: 'develop'})
16
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-router', require: false, git: 'https://github.com/hanami/router.git', branch: 'develop'})
17
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-controller', require: false, git: 'https://github.com/hanami/controller.git', branch: 'develop'})
18
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-view', require: false, git: 'https://github.com/hanami/view.git', branch: 'develop'})
19
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-helpers', require: false, git: 'https://github.com/hanami/helpers.git', branch: 'develop'})
20
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-mailer', require: false, git: 'https://github.com/hanami/mailer.git', branch: 'develop'})
21
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-assets', require: false, git: 'https://github.com/hanami/assets.git', branch: 'develop'})
22
+ expect('Gemfile').to have_file_content(%r{gem 'hanami-model', require: false, git: 'https://github.com/hanami/model.git', branch: 'develop'})
23
+ expect('Gemfile').to have_file_content(%r{gem 'hanami', git: 'https://github.com/hanami/hanami.git', branch: 'develop'})
24
+ end
25
+ end
26
+ end # hanami-head
27
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "hanami new", type: :integration do
4
+ describe "--template" do
5
+ context "erb" do
6
+ it "generates project" do
7
+ project = "bookshelf_erb"
8
+ output = [
9
+ "create apps/web/templates/app.html.erb"
10
+ ]
11
+
12
+ run_cmd "hanami new #{project} --template=erb", output
13
+
14
+ within_project_directory(project) do
15
+ #
16
+ # .hanamirc
17
+ #
18
+ expect(".hanamirc").to have_file_content(%r{template=erb})
19
+
20
+ #
21
+ # apps/web/templates/app.html.erb
22
+ #
23
+ expect("apps/web/templates/app.html.erb").to have_file_content <<~END
24
+ <!DOCTYPE html>
25
+ <html>
26
+ <head>
27
+ <title>Web</title>
28
+ <%= favicon %>
29
+ </head>
30
+ <body>
31
+ <%= yield %>
32
+ </body>
33
+ </html>
34
+ END
35
+ end
36
+ end
37
+ end # erb
38
+
39
+ context "haml" do
40
+ it "generates project" do
41
+ project = "bookshelf_erb"
42
+ output = [
43
+ "create apps/web/templates/app.html.haml"
44
+ ]
45
+
46
+ run_cmd "hanami new #{project} --template=haml", output
47
+
48
+ within_project_directory(project) do
49
+ #
50
+ # .hanamirc
51
+ #
52
+ expect(".hanamirc").to have_file_content(%r{template=haml})
53
+
54
+ #
55
+ # apps/web/templates/app.html.haml
56
+ #
57
+ expect("apps/web/templates/app.html.haml").to have_file_content <<~END
58
+ !!!
59
+ %html
60
+ %head
61
+ %title Web
62
+ = favicon
63
+ %body
64
+ = yield
65
+ END
66
+ end
67
+ end
68
+ end # haml
69
+
70
+ context "slim" do
71
+ it "generates project" do
72
+ project = "bookshelf_erb"
73
+ output = [
74
+ "create apps/web/templates/app.html.slim"
75
+ ]
76
+
77
+ run_cmd "hanami new #{project} --template=slim", output
78
+
79
+ within_project_directory(project) do
80
+ #
81
+ # .hanamirc
82
+ #
83
+ expect(".hanamirc").to have_file_content(%r{template=slim})
84
+
85
+ #
86
+ # apps/web/templates/app.html.slim
87
+ #
88
+ expect("apps/web/templates/app.html.slim").to have_file_content <<~END
89
+ doctype html
90
+ html
91
+ head
92
+ title
93
+ | Web
94
+ = favicon
95
+ body
96
+ = yield
97
+ END
98
+ end
99
+ end
100
+ end # slim
101
+
102
+ context "missing" do
103
+ it "returns error" do
104
+ output = "`' is not a valid template engine. Please use one of: `erb', `haml', `slim'"
105
+
106
+ run_cmd "hanami new bookshelf --template=", output, exit_status: 1
107
+ end
108
+ end # missing
109
+
110
+ context "unknown" do
111
+ it "returns error" do
112
+ output = "`foo' is not a valid template engine. Please use one of: `erb', `haml', `slim'"
113
+
114
+ run_cmd "hanami new bookshelf --template=foo", output, exit_status: 1
115
+ end
116
+ end # unknown
117
+ end # template
118
+ end
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "hanami new", type: :integration do
4
+ describe "--test" do
5
+ context "minitest" do
6
+ it "generates project" do
7
+ project = "bookshelf_minitest"
8
+ output = [
9
+ "create spec/spec_helper.rb",
10
+ "create spec/features_helper.rb",
11
+ "create spec/web/views/app_layout_spec.rb"
12
+ ]
13
+
14
+ run_cmd "hanami new #{project} --test=minitest", output
15
+
16
+ within_project_directory(project) do
17
+ #
18
+ # .hanamirc
19
+ #
20
+ expect(".hanamirc").to have_file_content(%r{test=minitest})
21
+
22
+ #
23
+ # spec/spec_helper.rb
24
+ #
25
+ expect("spec/spec_helper.rb").to have_file_content <<~END
26
+ # Require this file for unit tests
27
+ ENV['HANAMI_ENV'] ||= 'test'
28
+
29
+ require_relative '../config/environment'
30
+ require 'minitest/autorun'
31
+
32
+ Hanami.boot
33
+ END
34
+
35
+ #
36
+ # spec/features_helper.rb
37
+ #
38
+ expect("spec/features_helper.rb").to have_file_content <<~END
39
+ # Require this file for feature tests
40
+ require_relative './spec_helper'
41
+
42
+ require 'capybara'
43
+ require 'capybara/dsl'
44
+
45
+ Capybara.app = Hanami.app
46
+
47
+ class MiniTest::Spec
48
+ include Capybara::DSL
49
+ end
50
+ END
51
+
52
+ #
53
+ # spec/<app>/views/app_layout_spec.rb
54
+ #
55
+ expect("spec/web/views/app_layout_spec.rb").to have_file_content <<-END
56
+ require "spec_helper"
57
+
58
+ describe Web::Views::AppLayout do
59
+ let(:layout) { Web::Views::AppLayout.new({ format: :html }, "contents") }
60
+ let(:rendered) { layout.render }
61
+
62
+ it 'contains app name' do
63
+ _(rendered).must_include('Web')
64
+ end
65
+ end
66
+ END
67
+ end
68
+ end
69
+ end # minitest
70
+
71
+ describe "rspec" do
72
+ it "generates project" do
73
+ project = "bookshelf_rspec"
74
+ output = [
75
+ "create .rspec",
76
+ "create spec/spec_helper.rb",
77
+ "create spec/features_helper.rb",
78
+ "create spec/support/capybara.rb",
79
+ "create spec/web/views/app_layout_spec.rb"
80
+ ]
81
+
82
+ run_cmd "hanami new #{project} --test=rspec", output
83
+
84
+ within_project_directory(project) do
85
+ #
86
+ # .hanamirc
87
+ #
88
+ expect(".hanamirc").to have_file_content(%r{test=rspec})
89
+
90
+ #
91
+ # .rspec
92
+ #
93
+ expect(".rspec").to have_file_content <<~END
94
+ --color
95
+ --require spec_helper
96
+ END
97
+
98
+ #
99
+ # spec/spec_helper.rb
100
+ #
101
+ expect("spec/spec_helper.rb").to have_file_content <<~END
102
+ # Require this file for unit tests
103
+ ENV['HANAMI_ENV'] ||= 'test'
104
+
105
+ require_relative '../config/environment'
106
+ Hanami.boot
107
+ Hanami::Utils.require!("\#{__dir__}/support")
108
+
109
+ # This file was generated by the `rspec --init` command. Conventionally, all
110
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
111
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
112
+ # this file to always be loaded, without a need to explicitly require it in any
113
+ # files.
114
+ #
115
+ # Given that it is always loaded, you are encouraged to keep this file as
116
+ # light-weight as possible. Requiring heavyweight dependencies from this file
117
+ # will add to the boot time of your test suite on EVERY test run, even for an
118
+ # individual file that may not need all of that loaded. Instead, consider making
119
+ # a separate helper file that requires the additional dependencies and performs
120
+ # the additional setup, and require it from the spec files that actually need
121
+ # it.
122
+ #
123
+ # The `.rspec` file also contains a few flags that are not defaults but that
124
+ # users commonly want.
125
+ #
126
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
127
+ RSpec.configure do |config|
128
+ # rspec-expectations config goes here. You can use an alternate
129
+ # assertion/expectation library such as wrong or the stdlib/minitest
130
+ # assertions if you prefer.
131
+ config.expect_with :rspec do |expectations|
132
+ # This option will default to `true` in RSpec 4. It makes the `description`
133
+ # and `failure_message` of custom matchers include text for helper methods
134
+ # defined using `chain`, e.g.:
135
+ # be_bigger_than(2).and_smaller_than(4).description
136
+ # # => "be bigger than 2 and smaller than 4"
137
+ # ...rather than:
138
+ # # => "be bigger than 2"
139
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
140
+ end
141
+
142
+ # rspec-mocks config goes here. You can use an alternate test double
143
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
144
+ config.mock_with :rspec do |mocks|
145
+ # Prevents you from mocking or stubbing a method that does not exist on
146
+ # a real object. This is generally recommended, and will default to
147
+ # `true` in RSpec 4.
148
+ mocks.verify_partial_doubles = true
149
+ end
150
+
151
+ # The settings below are suggested to provide a good initial experience
152
+ # with RSpec, but feel free to customize to your heart's content.
153
+ =begin
154
+ # These two settings work together to allow you to limit a spec run
155
+ # to individual examples or groups you care about by tagging them with
156
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
157
+ # get run.
158
+ config.filter_run :focus
159
+ config.run_all_when_everything_filtered = true
160
+
161
+ # Allows RSpec to persist some state between runs in order to support
162
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
163
+ # you configure your source control system to ignore this file.
164
+ config.example_status_persistence_file_path = "spec/examples.txt"
165
+
166
+ # Limits the available syntax to the non-monkey patched syntax that is
167
+ # recommended. For more details, see:
168
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
169
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
170
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
171
+ config.disable_monkey_patching!
172
+
173
+ # This setting enables warnings. It's recommended, but in many cases may
174
+ # be too noisy due to issues in dependencies.
175
+ config.warnings = false
176
+
177
+ # Many RSpec users commonly either run the entire suite or an individual
178
+ # file, and it's useful to allow more verbose output when running an
179
+ # individual spec file.
180
+ if config.files_to_run.one?
181
+ # Use the documentation formatter for detailed output,
182
+ # unless a formatter has already been configured
183
+ # (e.g. via a command-line flag).
184
+ config.default_formatter = 'doc'
185
+ end
186
+
187
+ # Print the 10 slowest examples and example groups at the
188
+ # end of the spec run, to help surface which specs are running
189
+ # particularly slow.
190
+ config.profile_examples = 10
191
+
192
+ # Run specs in random order to surface order dependencies. If you find an
193
+ # order dependency and want to debug it, you can fix the order by providing
194
+ # the seed, which is printed after each run.
195
+ # --seed 1234
196
+ config.order = :random
197
+
198
+ # Seed global randomization in this process using the `--seed` CLI option.
199
+ # Setting this allows you to use `--seed` to deterministically reproduce
200
+ # test failures related to randomization by passing the same `--seed` value
201
+ # as the one that triggered the failure.
202
+ Kernel.srand config.seed
203
+ =end
204
+ end
205
+ END
206
+
207
+ #
208
+ # spec/features_helper.rb
209
+ #
210
+ expect("spec/features_helper.rb").to have_file_content <<~END
211
+ # Require this file for feature tests
212
+ require_relative './spec_helper'
213
+
214
+ require 'capybara'
215
+ require 'capybara/rspec'
216
+
217
+ RSpec.configure do |config|
218
+ config.include RSpec::FeatureExampleGroup
219
+
220
+ config.include Capybara::DSL, feature: true
221
+ config.include Capybara::RSpecMatchers, feature: true
222
+ end
223
+ END
224
+
225
+ #
226
+ # spec/support/capybara.rb
227
+ #
228
+ expect("spec/support/capybara.rb").to have_file_content <<~END
229
+ module RSpec
230
+ module FeatureExampleGroup
231
+ def self.included(group)
232
+ group.metadata[:type] = :feature
233
+ Capybara.app = Hanami.app
234
+ end
235
+ end
236
+ end
237
+ END
238
+
239
+ #
240
+ # spec/<app>/views/app_layout_spec.rb
241
+ #
242
+ expect("spec/web/views/app_layout_spec.rb").to have_file_content <<~END
243
+ require "spec_helper"
244
+
245
+ RSpec.describe Web::Views::AppLayout, type: :view do
246
+ let(:layout) { Web::Views::AppLayout.new({ format: :html }, "contents") }
247
+ let(:rendered) { layout.render }
248
+
249
+ it 'contains app name' do
250
+ expect(rendered).to include('Web')
251
+ end
252
+ end
253
+ END
254
+ end
255
+ end
256
+ end # rspec
257
+
258
+ context "missing" do
259
+ it "returns error" do
260
+ output = "`' is not a valid test framework. Please use one of: `rspec', `minitest'"
261
+
262
+ run_cmd "hanami new bookshelf --test=", output, exit_status: 1
263
+ end
264
+ end # missing
265
+
266
+ context "unknown" do
267
+ it "returns error" do
268
+ output = "`foo' is not a valid test framework. Please use one of: `rspec', `minitest'"
269
+
270
+ run_cmd "hanami new bookshelf --test=foo", output, exit_status: 1
271
+ end
272
+ end # unknown
273
+ end # test
274
+ end