fortitude 0.0.4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (355) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec-local +4 -0
  4. data/.travis.yml +50 -0
  5. data/CHANGES.md +62 -0
  6. data/CONTRIBUTORS.md +6 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.txt +22 -0
  9. data/README-erector.md +246 -0
  10. data/README.md +15 -0
  11. data/Rakefile +67 -0
  12. data/ext/FortitudeJrubyNativeExtService.java +11 -0
  13. data/ext/com/fortituderuby/ext/fortitude/FortitudeNativeLibrary.java +223 -0
  14. data/ext/fortitude_native_ext/extconf.rb +4 -0
  15. data/ext/fortitude_native_ext/fortitude_native_ext.c +333 -0
  16. data/fortitude.gemspec +42 -0
  17. data/lib/fortitude.rb +7 -0
  18. data/lib/fortitude/doctypes.rb +48 -0
  19. data/lib/fortitude/doctypes/base.rb +42 -0
  20. data/lib/fortitude/doctypes/html4.rb +21 -0
  21. data/lib/fortitude/doctypes/html4_frameset.rb +20 -0
  22. data/lib/fortitude/doctypes/html4_strict.rb +18 -0
  23. data/lib/fortitude/doctypes/html4_tags_frameset.rb +53 -0
  24. data/lib/fortitude/doctypes/html4_tags_strict.rb +274 -0
  25. data/lib/fortitude/doctypes/html4_tags_transitional.rb +115 -0
  26. data/lib/fortitude/doctypes/html4_transitional.rb +19 -0
  27. data/lib/fortitude/doctypes/html5.rb +373 -0
  28. data/lib/fortitude/doctypes/unknown_doctype.rb +20 -0
  29. data/lib/fortitude/doctypes/xhtml10.rb +20 -0
  30. data/lib/fortitude/doctypes/xhtml10_frameset.rb +18 -0
  31. data/lib/fortitude/doctypes/xhtml10_strict.rb +18 -0
  32. data/lib/fortitude/doctypes/xhtml10_transitional.rb +18 -0
  33. data/lib/fortitude/doctypes/xhtml11.rb +30 -0
  34. data/lib/fortitude/errors.rb +153 -0
  35. data/lib/fortitude/extensions/fortitude_ruby_ext.rb +76 -0
  36. data/lib/fortitude/extensions/native_extensions.rb +33 -0
  37. data/lib/fortitude/method_templates/assign_locals_from_template.rb.smpl +22 -0
  38. data/lib/fortitude/method_templates/need_assignment_template.rb.smpl +16 -0
  39. data/lib/fortitude/method_templates/need_method_template.rb.smpl +4 -0
  40. data/lib/fortitude/method_templates/simple_template.rb +50 -0
  41. data/lib/fortitude/method_templates/tag_method_template.rb.smpl +68 -0
  42. data/lib/fortitude/method_templates/text_method_template.rb.smpl +17 -0
  43. data/lib/fortitude/rails.rb +26 -0
  44. data/lib/fortitude/rails/helpers.rb +153 -0
  45. data/lib/fortitude/rails/railtie.rb +256 -0
  46. data/lib/fortitude/rails/renderer.rb +43 -0
  47. data/lib/fortitude/rails/template_handler.rb +23 -0
  48. data/lib/fortitude/rails/widget_methods.rb +13 -0
  49. data/lib/fortitude/rails/yielded_object_outputter.rb +31 -0
  50. data/lib/fortitude/rendering_context.rb +205 -0
  51. data/lib/fortitude/support/assigns_proxy.rb +77 -0
  52. data/lib/fortitude/support/class_inheritable_attributes.rb +98 -0
  53. data/lib/fortitude/support/instance_variable_set.rb +76 -0
  54. data/lib/fortitude/support/staticized_method.rb +87 -0
  55. data/lib/fortitude/tags/partial_tag_placeholder.rb +19 -0
  56. data/lib/fortitude/tags/tag.rb +189 -0
  57. data/lib/fortitude/tags/tag_return_value.rb +13 -0
  58. data/lib/fortitude/tags/tag_store.rb +53 -0
  59. data/lib/fortitude/tags/tag_support.rb +51 -0
  60. data/lib/fortitude/tags/tags_module.rb +16 -0
  61. data/lib/fortitude/tilt.rb +17 -0
  62. data/lib/fortitude/tilt/fortitude_template.rb +169 -0
  63. data/lib/fortitude/version.rb +3 -0
  64. data/lib/fortitude/widget.rb +54 -0
  65. data/lib/fortitude/widget/around_content.rb +53 -0
  66. data/lib/fortitude/widget/capturing.rb +37 -0
  67. data/lib/fortitude/widget/content.rb +61 -0
  68. data/lib/fortitude/widget/doctypes.rb +53 -0
  69. data/lib/fortitude/widget/helpers.rb +62 -0
  70. data/lib/fortitude/widget/integration.rb +76 -0
  71. data/lib/fortitude/widget/localization.rb +63 -0
  72. data/lib/fortitude/widget/modules_and_subclasses.rb +58 -0
  73. data/lib/fortitude/widget/needs.rb +164 -0
  74. data/lib/fortitude/widget/non_rails_widget_methods.rb +13 -0
  75. data/lib/fortitude/widget/rendering.rb +98 -0
  76. data/lib/fortitude/widget/start_and_end_comments.rb +69 -0
  77. data/lib/fortitude/widget/staticization.rb +50 -0
  78. data/lib/fortitude/widget/tag_like_methods.rb +102 -0
  79. data/lib/fortitude/widget/tags.rb +55 -0
  80. data/lib/fortitude/widget/temporary_overrides.rb +28 -0
  81. data/lib/fortitude/widget/widget_class_inheritable_attributes.rb +35 -0
  82. data/lib/fortitude/widgets.rb +12 -0
  83. data/lib/fortitude/widgets/html4_frameset.rb +9 -0
  84. data/lib/fortitude/widgets/html4_strict.rb +9 -0
  85. data/lib/fortitude/widgets/html4_transitional.rb +9 -0
  86. data/lib/fortitude/widgets/html5.rb +9 -0
  87. data/lib/fortitude/widgets/xhtml10_frameset.rb +9 -0
  88. data/lib/fortitude/widgets/xhtml10_strict.rb +9 -0
  89. data/lib/fortitude/widgets/xhtml10_transitional.rb +9 -0
  90. data/lib/fortitude/widgets/xhtml11.rb +9 -0
  91. data/lib/fortitude_jruby_native_ext.jar +0 -0
  92. data/spec/helpers/global_helper.rb +8 -0
  93. data/spec/helpers/rails_helpers.rb +85 -0
  94. data/spec/helpers/rails_server.rb +386 -0
  95. data/spec/helpers/system_helpers.rb +117 -0
  96. data/spec/rails/basic_rails_system_spec.rb +7 -0
  97. data/spec/rails/capture_system_spec.rb +75 -0
  98. data/spec/rails/class_loading_system_spec.rb +63 -0
  99. data/spec/rails/complex_helpers_system_spec.rb +33 -0
  100. data/spec/rails/data_passing_system_spec.rb +96 -0
  101. data/spec/rails/default_layout_system_spec.rb +15 -0
  102. data/spec/rails/development_mode_system_spec.rb +67 -0
  103. data/spec/rails/erb_integration_system_spec.rb +23 -0
  104. data/spec/rails/helpers_include_all_off_system_spec.rb +7 -0
  105. data/spec/rails/helpers_system_spec.rb +79 -0
  106. data/spec/rails/helpers_unrefined_system_spec.rb +7 -0
  107. data/spec/rails/layouts_system_spec.rb +60 -0
  108. data/spec/rails/localization_system_spec.rb +38 -0
  109. data/spec/rails/production_mode_system_spec.rb +13 -0
  110. data/spec/rails/rendering_context_system_spec.rb +64 -0
  111. data/spec/rails/rendering_system_spec.rb +158 -0
  112. data/spec/rails/rules_system_spec.rb +23 -0
  113. data/spec/rails/static_method_system_spec.rb +12 -0
  114. data/spec/rails/templates/base/app/controllers/application_controller.rb +15 -0
  115. data/spec/rails/templates/base/app/controllers/working_controller.rb +5 -0
  116. data/spec/rails/templates/base/app/views/layouts/application.html.erb +11 -0
  117. data/spec/rails/templates/base/config/routes.rb +4 -0
  118. data/spec/rails/templates/base/config/secrets.yml +22 -0
  119. data/spec/rails/templates/basic_rails_system_spec/app/controllers/basic_rails_system_spec_controller.rb +8 -0
  120. data/spec/rails/templates/basic_rails_system_spec/app/views/basic_rails_system_spec/trivial_widget.rb +5 -0
  121. data/spec/rails/templates/capture_system_spec/app/controllers/capture_system_spec_controller.rb +37 -0
  122. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/_some_erb_partial.html.erb +1 -0
  123. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/another_widget.rb +7 -0
  124. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/capture_erb_from_widget.rb +11 -0
  125. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/capture_widget_from_erb.html.erb +9 -0
  126. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/capture_widget_from_widget.rb +17 -0
  127. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/some_widget.rb +5 -0
  128. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/widget_content_for.rb +19 -0
  129. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/widget_layout_needing_content_yield_with_erb.html.erb +13 -0
  130. data/spec/rails/templates/capture_system_spec/app/views/capture_system_spec/widget_provide.rb +13 -0
  131. data/spec/rails/templates/capture_system_spec/app/views/layouts/erb_layout_needing_content.html.erb +15 -0
  132. data/spec/rails/templates/capture_system_spec/app/views/layouts/widget_layout_needing_content_content_for.rb +23 -0
  133. data/spec/rails/templates/capture_system_spec/app/views/layouts/widget_layout_needing_content_yield.rb +23 -0
  134. data/spec/rails/templates/class_loading_system_spec/app/controllers/class_loading_system_spec_controller.rb +74 -0
  135. data/spec/rails/templates/class_loading_system_spec/app/models/views/app_models_helper.rb +5 -0
  136. data/spec/rails/templates/class_loading_system_spec/app/models/views/models_widget.rb +5 -0
  137. data/spec/rails/templates/class_loading_system_spec/app/views/autoload_namespace/autoload_widget.rb +11 -0
  138. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/_loaded_underscore_widget.rb +11 -0
  139. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/_underscore_view.rb +5 -0
  140. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/_underscore_widget.rb +11 -0
  141. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/app_models.rb +6 -0
  142. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/autoload_one_widget_from_another.rb +7 -0
  143. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/class_should_not_load.rb +9 -0
  144. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/lib_views.rb +8 -0
  145. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_lib_widget_from_view_widget.rb +9 -0
  146. data/spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_models_widget_from_view_widget.rb +7 -0
  147. data/spec/rails/templates/class_loading_system_spec/app/views/some_namespace/some_other_namespace/.git_keep +0 -0
  148. data/spec/rails/templates/class_loading_system_spec/app/views/sub_widget.rb +5 -0
  149. data/spec/rails/templates/class_loading_system_spec/lib/arbitrary_name/some_widget.rb +7 -0
  150. data/spec/rails/templates/class_loading_system_spec/lib/views/class_loading_system_spec/lib_views_helper.rb +5 -0
  151. data/spec/rails/templates/class_loading_system_spec/lib/views/class_loading_system_spec/widget_defined_outside_app_views.rb +5 -0
  152. data/spec/rails/templates/class_loading_system_spec/lib/views/lib_widget.rb +5 -0
  153. data/spec/rails/templates/complex_helpers_system_spec/app/controllers/complex_helpers_system_spec_controller.rb +14 -0
  154. data/spec/rails/templates/complex_helpers_system_spec/app/views/complex_helpers_system_spec/cache_test.rb +12 -0
  155. data/spec/rails/templates/complex_helpers_system_spec/app/views/complex_helpers_system_spec/fields_for_test.rb +14 -0
  156. data/spec/rails/templates/complex_helpers_system_spec/app/views/complex_helpers_system_spec/form_for_test.rb +14 -0
  157. data/spec/rails/templates/complex_helpers_system_spec/config/environments/development.rb +31 -0
  158. data/spec/rails/templates/data_passing_system_spec/app/controllers/data_passing_system_spec_controller.rb +101 -0
  159. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/_erb_to_parallel_widget_handoff_erb.html.erb +3 -0
  160. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/_implicit_erb_to_widget_handoff_erb.html.erb +3 -0
  161. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/_implicit_variable_write_erb.html.erb +1 -0
  162. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/_widget_to_parallel_erb_handoff_erb.html.erb +1 -0
  163. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/erb_copied_variables.html.erb +1 -0
  164. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/erb_to_parallel_widget_handoff.html.erb +2 -0
  165. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/erb_to_parallel_widget_handoff_widget.rb +5 -0
  166. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/explicit_controller_variable_read.rb +6 -0
  167. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/extra_variables.rb +23 -0
  168. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/extra_variables_requested.rb +24 -0
  169. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_erb_to_widget_handoff.html.erb +2 -0
  170. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_erb_to_widget_handoff_widget.rb +7 -0
  171. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access.rb +5 -0
  172. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access_inheritance.rb +6 -0
  173. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access_inheritance_child_one.rb +7 -0
  174. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access_inheritance_child_two.rb +5 -0
  175. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access_inheritance_parent.rb +3 -0
  176. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_shared_variable_access_inner.rb +8 -0
  177. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_variable_read.rb +5 -0
  178. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_variable_read_inner.rb +7 -0
  179. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_variable_write.html.erb +2 -0
  180. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/implicit_variable_write_widget.rb +7 -0
  181. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/parent_to_child_passing.rb +7 -0
  182. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/parent_to_child_passing_child.rb +7 -0
  183. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/parent_to_child_passing_partial.rb +7 -0
  184. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/parent_to_child_passing_partial_child.rb +7 -0
  185. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/passing_data_widget.rb +8 -0
  186. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/passing_locals_and_controller_variables_widget.rb +9 -0
  187. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/passing_locals_widget.rb +8 -0
  188. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/variables_to_layout.rb +7 -0
  189. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/widget_copied_variables.rb +9 -0
  190. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/widget_to_parallel_erb_handoff.html.erb +2 -0
  191. data/spec/rails/templates/data_passing_system_spec/app/views/data_passing_system_spec/widget_to_parallel_erb_handoff_widget.rb +5 -0
  192. data/spec/rails/templates/data_passing_system_spec/app/views/layouts/data_layout.rb +14 -0
  193. data/spec/rails/templates/default_layout_system_spec/app/controllers/default_layout_system_spec_controller.rb +9 -0
  194. data/spec/rails/templates/default_layout_system_spec/app/views/default_layout_system_spec/erb_with_widget_default_layout.html.erb +1 -0
  195. data/spec/rails/templates/default_layout_system_spec/app/views/default_layout_system_spec/widget_with_widget_default_layout.rb +5 -0
  196. data/spec/rails/templates/default_layout_system_spec/app/views/layouts/application.rb +12 -0
  197. data/spec/rails/templates/development_mode_system_spec/app/controllers/development_mode_system_spec_controller.rb +9 -0
  198. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget.rb +7 -0
  199. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/sample_output.rb +9 -0
  200. data/spec/rails/templates/erb_integration_system_spec/app/controllers/erb_integration_system_spec_controller.rb +10 -0
  201. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_erb_partial_from_widget_partial.html.erb +1 -0
  202. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_fortitude_partial_with_underscore_partial.rb +5 -0
  203. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_prefers_erb_partial_partial.html.erb +1 -0
  204. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/erb_partial_from_widget.rb +7 -0
  205. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/erb_to_widget_with_render_partial.html.erb +3 -0
  206. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/erb_to_widget_with_render_partial_widget.rb +5 -0
  207. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/fortitude_partial_with_underscore.html.erb +3 -0
  208. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/prefers_erb_partial.html.erb +3 -0
  209. data/spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/prefers_erb_partial_partial.rb +5 -0
  210. data/spec/rails/templates/helpers_include_all_off_system_spec/app/controllers/helpers_include_all_off_system_spec_controller.rb +13 -0
  211. data/spec/rails/templates/helpers_include_all_off_system_spec/app/helpers/application_helper.rb +5 -0
  212. data/spec/rails/templates/helpers_include_all_off_system_spec/app/helpers/some_helper.rb +5 -0
  213. data/spec/rails/templates/helpers_include_all_off_system_spec/app/views/helpers_include_all_off_system_spec/include_all_off.rb +23 -0
  214. data/spec/rails/templates/helpers_include_all_off_system_spec/config/application.rb +28 -0
  215. data/spec/rails/templates/helpers_system_spec/app/controllers/helpers_system_spec_controller.rb +86 -0
  216. data/spec/rails/templates/helpers_system_spec/app/helpers/some_helper.rb +21 -0
  217. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/automatic_helpers_disabled.rb +37 -0
  218. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/automatic_helpers_inheritance.rb +6 -0
  219. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/automatic_helpers_inheritance_child_one.rb +34 -0
  220. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/automatic_helpers_inheritance_child_two.rb +36 -0
  221. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/automatic_helpers_inheritance_parent.rb +4 -0
  222. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/basic_helpers.rb +13 -0
  223. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/block_helpers.rb +7 -0
  224. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/built_in_outputting_helpers.rb +13 -0
  225. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/built_in_outputting_to_returning.rb +8 -0
  226. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/built_in_returning_to_outputting.rb +10 -0
  227. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/controller_helper_method.rb +5 -0
  228. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/controller_helper_module.rb +5 -0
  229. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/custom_helper_outputs.rb +6 -0
  230. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/custom_helpers_basic.rb +5 -0
  231. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/custom_helpers_with_a_block.rb +6 -0
  232. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/custom_outputting_to_returning.rb +7 -0
  233. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/custom_returning_to_outputting.rb +10 -0
  234. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/helper_settings_inheritance.rb +10 -0
  235. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/helper_settings_inheritance_parent.rb +4 -0
  236. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/helpers_that_output_when_refined.rb +9 -0
  237. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/private_helper_erb.html.erb +1 -0
  238. data/spec/rails/templates/helpers_system_spec/app/views/helpers_system_spec/private_helper_fortitude.rb +5 -0
  239. data/spec/rails/templates/helpers_system_spec/lib/some_stuff.rb +5 -0
  240. data/spec/rails/templates/helpers_unrefined_system_spec/app/controllers/helpers_unrefined_system_spec_controller.rb +7 -0
  241. data/spec/rails/templates/helpers_unrefined_system_spec/app/views/helpers_unrefined_system_spec/helpers_that_output_when_refined.rb +9 -0
  242. data/spec/rails/templates/helpers_unrefined_system_spec/config/environments/production.rb +31 -0
  243. data/spec/rails/templates/layouts_system_spec/app/controllers/layouts_system_spec_controller.rb +31 -0
  244. data/spec/rails/templates/layouts_system_spec/app/views/layouts/alternate.html.erb +11 -0
  245. data/spec/rails/templates/layouts_system_spec/app/views/layouts/application.html.erb +26 -0
  246. data/spec/rails/templates/layouts_system_spec/app/views/layouts/explicit_yield.rb +12 -0
  247. data/spec/rails/templates/layouts_system_spec/app/views/layouts/widget_layout.rb +22 -0
  248. data/spec/rails/templates/layouts_system_spec/app/views/layouts_system_spec/erb_inside_widget_layout.html.erb +8 -0
  249. data/spec/rails/templates/layouts_system_spec/app/views/layouts_system_spec/the_render_widget.rb +5 -0
  250. data/spec/rails/templates/layouts_system_spec/app/views/layouts_system_spec/widget_inside_erb_layout.rb +8 -0
  251. data/spec/rails/templates/layouts_system_spec/app/views/layouts_system_spec/widget_inside_widget_layout.rb +8 -0
  252. data/spec/rails/templates/layouts_system_spec/app/views/layouts_system_spec/yield_from_widget_explicitly.rb +5 -0
  253. data/spec/rails/templates/localization_system_spec/app/controllers/localization_system_spec_controller.rb +31 -0
  254. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/content_method.rb +13 -0
  255. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/dot_notation.rb +5 -0
  256. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/explicit_html.rb +13 -0
  257. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/i18n_t.rb +5 -0
  258. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/native_support.rb +7 -0
  259. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/readjust_base.rb +7 -0
  260. data/spec/rails/templates/localization_system_spec/app/views/localization_system_spec/t.rb +5 -0
  261. data/spec/rails/templates/localization_system_spec/config/locales/en.yml +21 -0
  262. data/spec/rails/templates/localization_system_spec/config/locales/fr.yml +14 -0
  263. data/spec/rails/templates/localization_system_spec/config/locales/pt.yml +2 -0
  264. data/spec/rails/templates/production_mode_system_spec/app/controllers/production_mode_system_spec_controller.rb +5 -0
  265. data/spec/rails/templates/production_mode_system_spec/app/views/production_mode_system_spec/sample_output.rb +9 -0
  266. data/spec/rails/templates/rendering_context_system_spec/app/controllers/rendering_context_system_spec_controller.rb +72 -0
  267. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/_start_end_widget_through_partials_partial.html.erb +1 -0
  268. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/_uses_direct_context_for_all_widgets_partial.html.erb +1 -0
  269. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/_uses_specified_context_through_nesting_partial.html.erb +2 -0
  270. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/render_widget.rb +5 -0
  271. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/start_end_widget_basic.rb +12 -0
  272. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/start_end_widget_basic_inner.rb +7 -0
  273. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/start_end_widget_through_partials.rb +16 -0
  274. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/start_end_widget_through_partials_partial_widget.rb +7 -0
  275. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_direct_context_for_all_widgets.rb +7 -0
  276. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_direct_context_for_all_widgets_widget.rb +5 -0
  277. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_direct_context_in_view.rb +5 -0
  278. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_specified_context_in_partials.html.erb +3 -0
  279. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_specified_context_in_partials_partial.rb +5 -0
  280. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_specified_context_in_view.rb +5 -0
  281. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_specified_context_through_nesting.rb +6 -0
  282. data/spec/rails/templates/rendering_context_system_spec/app/views/rendering_context_system_spec/uses_specified_context_through_nesting_inner_partial.rb +5 -0
  283. data/spec/rails/templates/rendering_context_system_spec/lib/simple_rc.rb +17 -0
  284. data/spec/rails/templates/rendering_system_spec/app/controllers/rendering_system_spec_controller.rb +111 -0
  285. data/spec/rails/templates/rendering_system_spec/app/views/layouts/application.html.erb +19 -0
  286. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/_layout_for_partial.html.erb +3 -0
  287. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/_the_partial.html.erb +1 -0
  288. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/partial_with_layout.rb +5 -0
  289. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_collection.html.erb +3 -0
  290. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_collection_as.html.erb +3 -0
  291. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_file_from_widget.rb +7 -0
  292. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_html_safe_strings.rb +16 -0
  293. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_inline_from_widget.rb +11 -0
  294. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_object.html.erb +3 -0
  295. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_partial_from_widget.rb +7 -0
  296. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_partial_with_layout.html.erb +3 -0
  297. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_partial_with_widget_layout.html.erb +3 -0
  298. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_template_from_widget.rb +7 -0
  299. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/render_text_from_widget.rb +7 -0
  300. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/stream_widget.rb +13 -0
  301. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/trivial_widget.rb +5 -0
  302. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/widget_layout_for_partial.rb +7 -0
  303. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/widget_with_name.rb +7 -0
  304. data/spec/rails/templates/rendering_system_spec/app/views/rendering_system_spec/word.rb +7 -0
  305. data/spec/rails/templates/rendering_system_spec/app/views/widget_to_render.rb +7 -0
  306. data/spec/rails/templates/rules_system_spec/app/controllers/rules_system_spec_controller.rb +22 -0
  307. data/spec/rails/templates/rules_system_spec/app/views/layouts/fortitude_layout_with_p.rb +19 -0
  308. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/_intervening_partial_erb_partial.html.erb +1 -0
  309. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/intervening_partial.rb +9 -0
  310. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/intervening_partial_fortitude_partial.rb +9 -0
  311. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalid_start_tag_in_partial.html.erb +3 -0
  312. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalid_start_tag_in_partial_partial.rb +9 -0
  313. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalid_start_tag_in_view.rb +9 -0
  314. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalidly_nested_tag.rb +11 -0
  315. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalidly_nested_tag_in_partial.html.erb +3 -0
  316. data/spec/rails/templates/rules_system_spec/app/views/rules_system_spec/invalidly_nested_tag_in_partial_partial.rb +11 -0
  317. data/spec/rails/templates/static_method_system_spec/app/controllers/static_method_system_spec_controller.rb +15 -0
  318. data/spec/rails/templates/static_method_system_spec/app/helpers/some_helper.rb +10 -0
  319. data/spec/rails/templates/static_method_system_spec/app/views/static_method_system_spec/allows_helper_access.rb +8 -0
  320. data/spec/rails/templates/static_method_system_spec/app/views/static_method_system_spec/localization.rb +7 -0
  321. data/spec/rails/templates/static_method_system_spec/config/locales/en.yml +4 -0
  322. data/spec/rails/templates/static_method_system_spec/config/locales/fr.yml +4 -0
  323. data/spec/system/around_content_system_spec.rb +399 -0
  324. data/spec/system/assigns_system_spec.rb +316 -0
  325. data/spec/system/attribute_rules_system_spec.rb +227 -0
  326. data/spec/system/basic_system_spec.rb +9 -0
  327. data/spec/system/content_inheritance_system_spec.rb +13 -0
  328. data/spec/system/convenience_methods_system_spec.rb +30 -0
  329. data/spec/system/doctypes_system_spec.rb +228 -0
  330. data/spec/system/erector_compatibility_system_spec.rb +84 -0
  331. data/spec/system/escaping_system_spec.rb +43 -0
  332. data/spec/system/formatting_system_spec.rb +63 -0
  333. data/spec/system/helpers_system_spec.rb +235 -0
  334. data/spec/system/id_uniqueness_system_spec.rb +205 -0
  335. data/spec/system/inline_system_spec.rb +58 -0
  336. data/spec/system/localization_system_spec.rb +94 -0
  337. data/spec/system/method_precedence_system_spec.rb +48 -0
  338. data/spec/system/needs_system_spec.rb +381 -0
  339. data/spec/system/other_outputters_system_spec.rb +117 -0
  340. data/spec/system/rails_not_available_spec.rb +11 -0
  341. data/spec/system/rebuild_notifications_system_spec.rb +208 -0
  342. data/spec/system/rendering_context_system_spec.rb +83 -0
  343. data/spec/system/setting_inheritance_system_spec.rb +585 -0
  344. data/spec/system/shared_variable_system_spec.rb +120 -0
  345. data/spec/system/start_end_comments_system_spec.rb +363 -0
  346. data/spec/system/static_method_system_spec.rb +348 -0
  347. data/spec/system/tag_rendering_system_spec.rb +260 -0
  348. data/spec/system/tag_return_value_system_spec.rb +41 -0
  349. data/spec/system/tag_rules_system_spec.rb +196 -0
  350. data/spec/system/tag_updating_system_spec.rb +171 -0
  351. data/spec/system/tilt_system_spec.rb +382 -0
  352. data/spec/system/unparsed_data_system_spec.rb +16 -0
  353. data/spec/system/void_tags_system_spec.rb +90 -0
  354. data/spec/system/widget_return_values_system_spec.rb +107 -0
  355. metadata +759 -0
@@ -0,0 +1,8 @@
1
+ require 'fortitude'
2
+ require 'helpers/rails_helpers'
3
+ require 'helpers/system_helpers'
4
+
5
+ RSpec.configure do |c|
6
+ c.include RailsHelpers, :type => :rails
7
+ c.include SystemHelpers, :type => :system
8
+ end
@@ -0,0 +1,85 @@
1
+ require 'active_support'
2
+ require 'json'
3
+ require 'helpers/rails_server'
4
+
5
+ module RailsHelpers
6
+ extend ActiveSupport::Concern
7
+
8
+ attr_reader :rails_server
9
+
10
+ def rails_template_name
11
+ @rails_template_name || raise("No Rails template name!")
12
+ end
13
+
14
+ def full_path(subpath)
15
+ "#{rails_template_name}/#{subpath}"
16
+ end
17
+
18
+ def get(subpath, options = { })
19
+ @rails_server.get(full_path(subpath), options)
20
+ end
21
+
22
+ def get_response(subpath, options = { })
23
+ @rails_server.get_response(full_path(subpath), options)
24
+ end
25
+
26
+ def get_success(subpath, options = { })
27
+ data = get(subpath, options)
28
+ data.should match(/rails_spec_application/i) unless options[:no_layout]
29
+ data
30
+ end
31
+
32
+ def expect_match(subpath, *args)
33
+ options = args.extract_options!
34
+ regexes = args
35
+
36
+ data = get_success(subpath, options)
37
+ regexes.each do |regex|
38
+ data.should match(regex)
39
+ end
40
+
41
+ data
42
+ end
43
+
44
+ def expect_exception(subpath, class_name, message)
45
+ data = get(subpath)
46
+
47
+ json = begin
48
+ JSON.parse(data)
49
+ rescue => e
50
+ raise %{Expected a JSON response from '#{subpath}' (because we expected an exception),
51
+ but we couldn't parse it as JSON; when we tried, we got:
52
+
53
+ (#{e.class.name}) #{e.message}
54
+
55
+ The data is:
56
+
57
+ #{data.inspect}}
58
+ end
59
+
60
+ json['exception'].should be
61
+ json['exception']['class'].should == class_name.to_s
62
+ json['exception']['message'].should match(message)
63
+ end
64
+
65
+ module ClassMethods
66
+ def rails_template_name
67
+ @rails_template_name || raise("No Rails template name!")
68
+ end
69
+
70
+ def uses_rails_with_template(template_name, options = { })
71
+ before :all do
72
+ @rails_template_name = template_name
73
+
74
+ templates = [ 'base', template_name ].map { |t| "rails/templates/#{t}" }
75
+
76
+ @rails_server = Spec::Helpers::RailsServer.new(template_name, templates, options)
77
+ @rails_server.start!
78
+ end
79
+
80
+ after :all do
81
+ @rails_server.stop!
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,386 @@
1
+ require 'fileutils'
2
+ require 'find'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Spec
7
+ module Helpers
8
+ class RailsServer
9
+ class CommandFailedError < StandardError
10
+ attr_reader :directory, :command, :result, :output
11
+
12
+ def initialize(directory, command, result, output)
13
+ @directory = directory
14
+ @command = command
15
+ @result = result
16
+ @output = output
17
+
18
+ super(%{Command failed: in directory '#{directory}', we tried to run:
19
+ % #{command}
20
+ but got result: #{result.inspect}
21
+ and output:
22
+ #{output}})
23
+ end
24
+ end
25
+
26
+ class << self
27
+ def run_bundle_install!(name)
28
+ @bundle_installs_run ||= { }
29
+
30
+ cmd = "bundle install"
31
+ description = "running bundle install for #{name.inspect}"
32
+
33
+ can_run_locally = @bundle_installs_run[name] || (ENV['FORTITUDE_SPECS_RAILS_GEMS_INSTALLED'] == 'true')
34
+
35
+ if can_run_locally
36
+ cmd << " --local"
37
+ else
38
+ description << " (WITHOUT --local flag)"
39
+ say %{NOTE: We're running 'bundle install' without the --local flag, meaning it will
40
+ go out and access rubygems.org for the lists of the latest gems. This is a slow operation.
41
+ If you run multiple Rails specs at once, this will only happen once.
42
+
43
+ However, this only actually needs to happen once, ever, for a given Rails version; if you set
44
+ FORTITUDE_SPECS_RAILS_GEMS_INSTALLED=true (e.g.,
45
+ FORTITUDE_SPECS_RAILS_GEMS_INSTALLED=true bundle exec rspec spec/rails/...),
46
+ then we will skip this command and your spec will run much faster.}
47
+ end
48
+
49
+ # Sigh. Travis CI sometimes fails this with the following exception:
50
+ #
51
+ # Gem::RemoteFetcher::FetchError: Errno::ETIMEDOUT: Connection timed out - connect(2)
52
+ #
53
+ # So, we catch the command failure, look to see if this is the problem, and, if so, retry
54
+ iterations = 0
55
+ while true
56
+ begin
57
+ safe_system(cmd, description)
58
+ break
59
+ rescue CommandFailedError => cfe
60
+ raise if (cfe.output !~ /Gem::RemoteFetcher::FetchError.*connect/i) || (iterations >= 5)
61
+ say %{Got an exception trying to run 'bundle install'; sleeping and trying again (iteration #{iterations}):
62
+
63
+ #{cfe.output}}
64
+ # keep going
65
+ end
66
+
67
+ sleep 1
68
+ iterations += 1
69
+ end
70
+
71
+ @bundle_installs_run[name] ||= true
72
+ end
73
+
74
+ def say(s, newline = true)
75
+ if newline
76
+ $stdout.puts s
77
+ else
78
+ $stdout << s
79
+ end
80
+ $stdout.flush
81
+ end
82
+
83
+ def safe_system(cmd, notice = nil, options = { })
84
+ say("#{notice}...", false) if notice
85
+
86
+ total_cmd = if options[:background]
87
+ "#{cmd} 2>&1 &"
88
+ else
89
+ "#{cmd} 2>&1"
90
+ end
91
+
92
+ output = `#{total_cmd}`
93
+ raise CommandFailedError.new(Dir.pwd, total_cmd, $?, output) unless $?.success?
94
+ say "OK" if notice
95
+
96
+ output
97
+ end
98
+ end
99
+
100
+ attr_reader :rails_root
101
+
102
+ def initialize(name, template_paths, options = { })
103
+ @name = name || (raise ArgumentError, "Must specify a name")
104
+ @rails_version = ENV['FORTITUDE_SPECS_RAILS_VERSION'] || options[:rails_version]
105
+
106
+ @rails_root = File.expand_path(File.join(File.dirname(__FILE__), "../../tmp/spec/rails", rails_version.to_s, @name.to_s))
107
+
108
+ @port = 20_000 + rand(10_000)
109
+
110
+ @gem_root = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
111
+ @spec_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
112
+ @template_paths = Array(template_paths).map { |t| File.expand_path(File.join(@spec_root, t)) }
113
+
114
+ @options = options
115
+ @server_pid = nil
116
+ end
117
+
118
+ def rails_version
119
+ @rails_version || :default
120
+ end
121
+
122
+ def say(*args)
123
+ self.class.say(*args)
124
+ end
125
+
126
+ def safe_system(*args)
127
+ self.class.safe_system(*args)
128
+ end
129
+
130
+ def start!
131
+ unless @server_pid
132
+ do_start!
133
+ end
134
+ end
135
+
136
+ def stop!
137
+ if @server_pid
138
+ stop_server!
139
+ end
140
+ end
141
+
142
+ def get(path, options = { })
143
+ get_response(path, options).body.strip
144
+ end
145
+
146
+ def uri_for(path)
147
+ uri_string = "http://localhost:#{@port}/#{path}"
148
+ URI.parse(uri_string)
149
+ end
150
+
151
+ def get_response(path, options = { })
152
+ uri = uri_for(path)
153
+ data = Net::HTTP.get_response(uri)
154
+ unless data.code.to_s == '200' || options[:ignore_status_code]
155
+ raise "'#{uri}' returned #{data.code.inspect}, not 200; body was: #{data.body.strip}"
156
+ end
157
+ data
158
+ end
159
+
160
+ private
161
+ def rails_env
162
+ (@options[:rails_env] || 'production').to_s
163
+ end
164
+
165
+ def do_start!
166
+ Bundler.with_clean_env do
167
+ with_rails_env do
168
+ setup_directories!
169
+
170
+ in_rails_root_parent do
171
+ splat_bootstrap_gemfile!
172
+ rails_new!
173
+ update_gemfile!
174
+ end
175
+
176
+ in_rails_root do
177
+ self.class.run_bundle_install!(:primary)
178
+ splat_template_files!
179
+ start_server!
180
+ verify_server!
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ def with_rails_env
187
+ old_rails_env = ENV['RAILS_ENV']
188
+ begin
189
+ ENV['RAILS_ENV'] = rails_env
190
+ yield
191
+ ensure
192
+ ENV['RAILS_ENV'] = old_rails_env
193
+ end
194
+ end
195
+
196
+
197
+ def setup_directories!
198
+ return if @directories_setup
199
+
200
+ @template_paths.each do |template_path|
201
+ raise Errno::ENOENT, "You must specify template paths that exist; this doesn't: '#{template_path}'" unless File.directory?(template_path)
202
+ end
203
+ FileUtils.rm_rf(@rails_root) if File.exist?(@rails_root)
204
+ FileUtils.mkdir_p(@rails_root)
205
+
206
+ @directories_setup = true
207
+ end
208
+
209
+ def in_rails_root(&block)
210
+ Dir.chdir(@rails_root, &block)
211
+ end
212
+
213
+ def in_rails_root_parent(&block)
214
+ Dir.chdir(File.dirname(@rails_root), &block)
215
+ end
216
+
217
+ def splat_bootstrap_gemfile!
218
+ File.open("Gemfile", "w") do |f|
219
+ rails_version_spec = if @rails_version then ", \"= #{@rails_version}\"" else "" end
220
+ f << <<-EOS
221
+ source 'https://rubygems.org'
222
+
223
+ gem 'rails'#{rails_version_spec}
224
+ EOS
225
+ end
226
+
227
+ self.class.run_bundle_install!(:bootstrap)
228
+ end
229
+
230
+ def rails_new!
231
+ # This is a little trick to specify the exact version of Rails you want to create it with...
232
+ # http://stackoverflow.com/questions/379141/specifying-rails-version-to-use-when-creating-a-new-application
233
+ rails_version_spec = @rails_version ? "_#{@rails_version}_" : ""
234
+ safe_system("bundle exec rails #{rails_version_spec} new #{File.basename(@rails_root)} -d sqlite3 -f -B", "creating a new Rails installation for '#{@name}'")
235
+ end
236
+
237
+ def update_gemfile!
238
+ gemfile = File.join(@rails_root, 'Gemfile')
239
+ gemfile_contents = File.read(gemfile)
240
+ gemfile_contents << "\ngem 'fortitude', :path => '#{@gem_root}'\n"
241
+
242
+ # Since Rails 3.0.20 was released, a new version of the I18n gem, 0.5.2, was released that moves a constant
243
+ # into a different namespace. (See https://github.com/mislav/will_paginate/issues/347 for more details.)
244
+ # So, if we're running Rails 3.0.x, we lock the 'i18n' gem to an earlier version.
245
+ gemfile_contents << "\ngem 'i18n', '= 0.5.0'\n" if @rails_version && @rails_version =~ /^3\.0\./
246
+
247
+ # Apparently execjs released a version 2.2.0 that will happily install on Ruby 1.8.7, but which contains some
248
+ # new-style hash syntax. As a result, we pin the version backwards in this one specific case.
249
+ gemfile_contents << "\ngem 'execjs', '~> 2.0.0'\n" if RUBY_VERSION =~ /^1\.8\./
250
+
251
+ File.open(gemfile, 'w') { |f| f << gemfile_contents }
252
+ end
253
+
254
+ def with_env(new_env)
255
+ old_env = { }
256
+ new_env.keys.each { |k| old_env[k] = ENV[k] }
257
+
258
+ begin
259
+ set_env(new_env)
260
+ yield
261
+ ensure
262
+ set_env(old_env)
263
+ end
264
+ end
265
+
266
+ def set_env(new_env)
267
+ new_env.each do |k,v|
268
+ if v
269
+ ENV[k] = v
270
+ else
271
+ ENV.delete(k)
272
+ end
273
+ end
274
+ end
275
+
276
+ def splat_template_files!
277
+ @template_paths.each do |template_path|
278
+ Find.find(template_path) do |file|
279
+ next unless File.file?(file)
280
+
281
+ if file[0..(template_path.length)] == "#{template_path}/"
282
+ subpath = file[(template_path.length + 1)..-1]
283
+ else
284
+ raise "#{file} isn't under #{template_path}?!?"
285
+ end
286
+ dest_file = File.join(@rails_root, subpath)
287
+
288
+ FileUtils.mkdir_p(File.dirname(dest_file))
289
+ FileUtils.cp(file, dest_file)
290
+ end
291
+ end
292
+ end
293
+
294
+ def start_server!
295
+ output = File.join(@rails_root, 'log', 'rails-server.out')
296
+ cmd = "rails server -p #{@port} > '#{output}'"
297
+ safe_system(cmd, "starting 'rails server' on port #{@port}", :background => true)
298
+
299
+ server_pid_file = File.join(@rails_root, 'tmp', 'pids', 'server.pid')
300
+
301
+ start_time = Time.now
302
+ while Time.now < start_time + 15
303
+ if File.exist?(server_pid_file)
304
+ server_pid = File.read(server_pid_file).strip
305
+ if server_pid =~ /^(\d{1,10})$/i
306
+ @server_pid = Integer(server_pid)
307
+ break
308
+ end
309
+ end
310
+ sleep 0.1
311
+ end
312
+ end
313
+
314
+ def verify_server!
315
+ server_verify_url = "http://localhost:#{@port}/working/rails_is_working"
316
+ uri = URI.parse(server_verify_url)
317
+
318
+ data = nil
319
+ start_time = Time.now
320
+ while (! data)
321
+ begin
322
+ data = Net::HTTP.get_response(uri)
323
+ rescue Errno::ECONNREFUSED, EOFError
324
+ raise if Time.now > (start_time + 20)
325
+ # keep waiting
326
+ sleep 0.1
327
+ end
328
+ end
329
+
330
+ unless data.code.to_s == '200'
331
+ raise "'#{server_verify_url}' returned #{data.code.inspect}, not 200"
332
+ end
333
+ result = data.body.strip
334
+
335
+ unless result =~ /^Rails\s+version\s*:\s*(\d+\.\d+\.\d+)$/
336
+ raise "'#{server_verify_url}' returned: #{result.inspect}"
337
+ end
338
+ actual_version = $1
339
+
340
+ if @rails_version && (actual_version != @rails_version)
341
+ raise "We seem to have spawned the wrong version of Rails; wanted: #{@rails_version.inspect} but got: #{actual_version.inspect}"
342
+ end
343
+
344
+ say "Successfully spawned a server running Rails #{actual_version} on port #{@port}."
345
+ end
346
+
347
+ def is_alive?(pid)
348
+ cmd = "ps -o pid #{pid}"
349
+ results = `#{cmd}`
350
+ results.split(/[\r\n]+/).each do |line|
351
+ line = line.strip.downcase
352
+ next if line == 'pid'
353
+ if line =~ /^\d+$/i
354
+ return true if Integer(line) == pid
355
+ else
356
+ raise "Unexpected output from '#{cmd}': #{results}"
357
+ end
358
+ end
359
+
360
+ false
361
+ end
362
+
363
+ def stop_server!
364
+ # We do this because under 1.8.7 SIGTERM doesn't seem to work, and it's actually fine to slaughter this
365
+ # process mercilessly -- we don't need anything it has at this point, anyway.
366
+ Process.kill("KILL", @server_pid)
367
+
368
+ start_time = Time.now
369
+
370
+ while true
371
+ if is_alive?(@server_pid)
372
+ raise "Unable to kill server at PID #{@server_pid}!" if (Time.now - start_time) > 20
373
+ say "Waiting for server at PID #{@server_pid} to die."
374
+ sleep 0.1
375
+ else
376
+ break
377
+ end
378
+ end
379
+
380
+ say "Successfully terminated Rails server at PID #{@server_pid}."
381
+
382
+ @server_pid = nil
383
+ end
384
+ end
385
+ end
386
+ end