fortitude 0.0.5-java → 0.0.6-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +20 -20
- data/CHANGES.md +19 -0
- data/CONTRIBUTORS.md +2 -0
- data/fortitude.gemspec +1 -0
- data/lib/fortitude/rails/railtie.rb +27 -75
- data/lib/fortitude/rails/rendering_methods.rb +77 -0
- data/lib/fortitude/tags/tags_module.rb +1 -0
- data/lib/fortitude/tilt/fortitude_template.rb +3 -1
- data/lib/fortitude/version.rb +1 -1
- data/lib/fortitude/widget/modules_and_subclasses.rb +2 -0
- data/spec/helpers/fortitude_rails_helpers.rb +19 -0
- data/spec/helpers/global_helper.rb +4 -2
- data/spec/rails/capture_system_spec.rb +1 -1
- data/spec/rails/development_mode_system_spec.rb +100 -6
- data/spec/rails/mailer_system_spec.rb +31 -0
- data/spec/rails/rendering_system_spec.rb +3 -3
- data/spec/rails/templates/development_mode_system_spec/app/controllers/development_mode_system_spec_controller.rb +16 -0
- data/spec/rails/templates/development_mode_system_spec/app/controllers/replaced_controller.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/mailers/development_mode_mailer.rb +17 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb +7 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_view_test.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget_with_html_extension.html.rb +8 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/layouts/mail_layout.rb +7 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/replaced/reload_widget.rb +7 -0
- data/spec/rails/templates/development_mode_system_spec/app/views/shared/some_module.rb +5 -0
- data/spec/rails/templates/development_mode_system_spec/config/environments/development.rb +39 -0
- data/spec/rails/templates/mailer_system_spec/app/controllers/mailer_system_spec_controller.rb +17 -0
- data/spec/rails/templates/mailer_system_spec/app/mailers/basic_mailer.rb +25 -0
- data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/basic_mail.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_erb_layout_and_fortitude_view.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout_and_erb_view.html.erb +1 -0
- data/spec/rails/templates/mailer_system_spec/app/views/layouts/erb_layout.html.erb +1 -0
- data/spec/rails/templates/mailer_system_spec/app/views/layouts/fortitude_layout.rb +8 -0
- data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_erb_layout_and_fortitude_view.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout_and_erb_view.rb +5 -0
- data/spec/rails/templates/mailer_system_spec/config/environments/production.rb +84 -0
- data/spec/rails/templates/rendering_system_spec/app/views/layouts/application.html.erb +1 -1
- data/spec/rails/templates/rules_system_spec/app/views/layouts/fortitude_layout_with_p.rb +1 -1
- data/spec/system/tilt_system_spec.rb +15 -0
- metadata +73 -16
- data/spec/helpers/rails_helpers.rb +0 -85
- data/spec/helpers/rails_server.rb +0 -390
- data/spec/rails/templates/base/app/controllers/application_controller.rb +0 -15
- data/spec/rails/templates/base/app/controllers/working_controller.rb +0 -5
- data/spec/rails/templates/base/app/views/layouts/application.html.erb +0 -11
- data/spec/rails/templates/base/config/routes.rb +0 -4
- data/spec/rails/templates/base/config/secrets.yml +0 -22
@@ -54,6 +54,16 @@ class SimpleTemplateWithVariables < Fortitude::Widgets::Html5
|
|
54
54
|
text "foo: \#{foo}, bar: \#{bar}"
|
55
55
|
end
|
56
56
|
end
|
57
|
+
EOS
|
58
|
+
|
59
|
+
SIMPLE_TEMPLATE_WITH_VARIABLES_ALL_DEFAULTED = <<-EOS
|
60
|
+
class SimpleTemplateWithVariablesAllDefaulted < Fortitude::Widgets::Html5
|
61
|
+
needs :foo => 'something', :bar => 'whatever'
|
62
|
+
|
63
|
+
def content
|
64
|
+
text "foo: \#{foo}, bar: \#{bar}"
|
65
|
+
end
|
66
|
+
end
|
57
67
|
EOS
|
58
68
|
|
59
69
|
SIMPLE_TEMPLATE_WITH_VARIABLES_NO_EXTRA_ASSIGNS = <<-EOS
|
@@ -83,6 +93,11 @@ EOS
|
|
83
93
|
expect(result).to eq("foo: the_foo, bar: the_bar")
|
84
94
|
end
|
85
95
|
|
96
|
+
it "should allow passing nil for locals to the template, and should act like there are no variables" do
|
97
|
+
result = render_text_with_tilt("simple_template_with_variables.rb", SIMPLE_TEMPLATE_WITH_VARIABLES_ALL_DEFAULTED, context_object, nil)
|
98
|
+
expect(result).to eq("foo: something, bar: whatever")
|
99
|
+
end
|
100
|
+
|
86
101
|
def context_object(variable_mappings = { }, klass = Object.class, &block)
|
87
102
|
out = klass.new
|
88
103
|
variable_mappings.each do |name, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortitude
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Andrew Geweke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
version: '2.0'
|
109
109
|
prerelease: false
|
110
110
|
type: :development
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: oop_rails_server
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.0.3
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.0.3
|
123
|
+
prerelease: false
|
124
|
+
type: :development
|
111
125
|
description: 'Views Are Code: use all the power of Ruby to build views in your own
|
112
126
|
language.'
|
113
127
|
email:
|
@@ -162,6 +176,7 @@ files:
|
|
162
176
|
- lib/fortitude/rails/helpers.rb
|
163
177
|
- lib/fortitude/rails/railtie.rb
|
164
178
|
- lib/fortitude/rails/renderer.rb
|
179
|
+
- lib/fortitude/rails/rendering_methods.rb
|
165
180
|
- lib/fortitude/rails/template_handler.rb
|
166
181
|
- lib/fortitude/rails/widget_methods.rb
|
167
182
|
- lib/fortitude/rails/yielded_object_outputter.rb
|
@@ -209,9 +224,8 @@ files:
|
|
209
224
|
- lib/fortitude/widgets/xhtml10_transitional.rb
|
210
225
|
- lib/fortitude/widgets/xhtml11.rb
|
211
226
|
- lib/fortitude_jruby_native_ext.jar
|
227
|
+
- spec/helpers/fortitude_rails_helpers.rb
|
212
228
|
- spec/helpers/global_helper.rb
|
213
|
-
- spec/helpers/rails_helpers.rb
|
214
|
-
- spec/helpers/rails_server.rb
|
215
229
|
- spec/helpers/system_helpers.rb
|
216
230
|
- spec/rails/basic_rails_system_spec.rb
|
217
231
|
- spec/rails/capture_system_spec.rb
|
@@ -227,16 +241,12 @@ files:
|
|
227
241
|
- spec/rails/helpers_unrefined_system_spec.rb
|
228
242
|
- spec/rails/layouts_system_spec.rb
|
229
243
|
- spec/rails/localization_system_spec.rb
|
244
|
+
- spec/rails/mailer_system_spec.rb
|
230
245
|
- spec/rails/production_mode_system_spec.rb
|
231
246
|
- spec/rails/rendering_context_system_spec.rb
|
232
247
|
- spec/rails/rendering_system_spec.rb
|
233
248
|
- spec/rails/rules_system_spec.rb
|
234
249
|
- spec/rails/static_method_system_spec.rb
|
235
|
-
- spec/rails/templates/base/app/controllers/application_controller.rb
|
236
|
-
- spec/rails/templates/base/app/controllers/working_controller.rb
|
237
|
-
- spec/rails/templates/base/app/views/layouts/application.html.erb
|
238
|
-
- spec/rails/templates/base/config/routes.rb
|
239
|
-
- spec/rails/templates/base/config/secrets.yml
|
240
250
|
- spec/rails/templates/basic_rails_system_spec/app/controllers/basic_rails_system_spec_controller.rb
|
241
251
|
- spec/rails/templates/basic_rails_system_spec/app/views/basic_rails_system_spec/double_render_one.rb
|
242
252
|
- spec/rails/templates/basic_rails_system_spec/app/views/basic_rails_system_spec/double_render_three.rb
|
@@ -319,8 +329,21 @@ files:
|
|
319
329
|
- spec/rails/templates/default_layout_system_spec/app/views/default_layout_system_spec/widget_with_widget_default_layout.rb
|
320
330
|
- spec/rails/templates/default_layout_system_spec/app/views/layouts/application.rb
|
321
331
|
- spec/rails/templates/development_mode_system_spec/app/controllers/development_mode_system_spec_controller.rb
|
332
|
+
- spec/rails/templates/development_mode_system_spec/app/controllers/replaced_controller.rb
|
333
|
+
- spec/rails/templates/development_mode_system_spec/app/mailers/development_mode_mailer.rb
|
334
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
|
335
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
|
336
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
|
337
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
|
338
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb
|
339
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_view_test.rb
|
322
340
|
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget.rb
|
341
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget_with_html_extension.html.rb
|
323
342
|
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/sample_output.rb
|
343
|
+
- spec/rails/templates/development_mode_system_spec/app/views/layouts/mail_layout.rb
|
344
|
+
- spec/rails/templates/development_mode_system_spec/app/views/replaced/reload_widget.rb
|
345
|
+
- spec/rails/templates/development_mode_system_spec/app/views/shared/some_module.rb
|
346
|
+
- spec/rails/templates/development_mode_system_spec/config/environments/development.rb
|
324
347
|
- spec/rails/templates/erb_integration_system_spec/app/controllers/erb_integration_system_spec_controller.rb
|
325
348
|
- spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_erb_partial_from_widget_partial.html.erb
|
326
349
|
- spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_fortitude_partial_with_underscore_partial.rb
|
@@ -391,6 +414,19 @@ files:
|
|
391
414
|
- spec/rails/templates/localization_system_spec/config/locales/en.yml
|
392
415
|
- spec/rails/templates/localization_system_spec/config/locales/fr.yml
|
393
416
|
- spec/rails/templates/localization_system_spec/config/locales/pt.yml
|
417
|
+
- spec/rails/templates/mailer_system_spec/app/controllers/mailer_system_spec_controller.rb
|
418
|
+
- spec/rails/templates/mailer_system_spec/app/mailers/basic_mailer.rb
|
419
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/basic_mail.rb
|
420
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_erb_layout_and_fortitude_view.rb
|
421
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout.rb
|
422
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout_and_erb_view.html.erb
|
423
|
+
- spec/rails/templates/mailer_system_spec/app/views/layouts/erb_layout.html.erb
|
424
|
+
- spec/rails/templates/mailer_system_spec/app/views/layouts/fortitude_layout.rb
|
425
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail.rb
|
426
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_erb_layout_and_fortitude_view.rb
|
427
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout.rb
|
428
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout_and_erb_view.rb
|
429
|
+
- spec/rails/templates/mailer_system_spec/config/environments/production.rb
|
394
430
|
- spec/rails/templates/production_mode_system_spec/app/controllers/production_mode_system_spec_controller.rb
|
395
431
|
- spec/rails/templates/production_mode_system_spec/app/views/production_mode_system_spec/sample_output.rb
|
396
432
|
- spec/rails/templates/rendering_context_system_spec/app/controllers/rendering_context_system_spec_controller.rb
|
@@ -513,9 +549,8 @@ signing_key:
|
|
513
549
|
specification_version: 4
|
514
550
|
summary: 'Views Are Code: use all the power of Ruby to build views in your own language.'
|
515
551
|
test_files:
|
552
|
+
- spec/helpers/fortitude_rails_helpers.rb
|
516
553
|
- spec/helpers/global_helper.rb
|
517
|
-
- spec/helpers/rails_helpers.rb
|
518
|
-
- spec/helpers/rails_server.rb
|
519
554
|
- spec/helpers/system_helpers.rb
|
520
555
|
- spec/rails/basic_rails_system_spec.rb
|
521
556
|
- spec/rails/capture_system_spec.rb
|
@@ -531,16 +566,12 @@ test_files:
|
|
531
566
|
- spec/rails/helpers_unrefined_system_spec.rb
|
532
567
|
- spec/rails/layouts_system_spec.rb
|
533
568
|
- spec/rails/localization_system_spec.rb
|
569
|
+
- spec/rails/mailer_system_spec.rb
|
534
570
|
- spec/rails/production_mode_system_spec.rb
|
535
571
|
- spec/rails/rendering_context_system_spec.rb
|
536
572
|
- spec/rails/rendering_system_spec.rb
|
537
573
|
- spec/rails/rules_system_spec.rb
|
538
574
|
- spec/rails/static_method_system_spec.rb
|
539
|
-
- spec/rails/templates/base/app/controllers/application_controller.rb
|
540
|
-
- spec/rails/templates/base/app/controllers/working_controller.rb
|
541
|
-
- spec/rails/templates/base/app/views/layouts/application.html.erb
|
542
|
-
- spec/rails/templates/base/config/routes.rb
|
543
|
-
- spec/rails/templates/base/config/secrets.yml
|
544
575
|
- spec/rails/templates/basic_rails_system_spec/app/controllers/basic_rails_system_spec_controller.rb
|
545
576
|
- spec/rails/templates/basic_rails_system_spec/app/views/basic_rails_system_spec/double_render_one.rb
|
546
577
|
- spec/rails/templates/basic_rails_system_spec/app/views/basic_rails_system_spec/double_render_three.rb
|
@@ -623,8 +654,21 @@ test_files:
|
|
623
654
|
- spec/rails/templates/default_layout_system_spec/app/views/default_layout_system_spec/widget_with_widget_default_layout.rb
|
624
655
|
- spec/rails/templates/default_layout_system_spec/app/views/layouts/application.rb
|
625
656
|
- spec/rails/templates/development_mode_system_spec/app/controllers/development_mode_system_spec_controller.rb
|
657
|
+
- spec/rails/templates/development_mode_system_spec/app/controllers/replaced_controller.rb
|
658
|
+
- spec/rails/templates/development_mode_system_spec/app/mailers/development_mode_mailer.rb
|
659
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
|
660
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
|
661
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
|
662
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
|
663
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb
|
664
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_view_test.rb
|
626
665
|
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget.rb
|
666
|
+
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget_with_html_extension.html.rb
|
627
667
|
- spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/sample_output.rb
|
668
|
+
- spec/rails/templates/development_mode_system_spec/app/views/layouts/mail_layout.rb
|
669
|
+
- spec/rails/templates/development_mode_system_spec/app/views/replaced/reload_widget.rb
|
670
|
+
- spec/rails/templates/development_mode_system_spec/app/views/shared/some_module.rb
|
671
|
+
- spec/rails/templates/development_mode_system_spec/config/environments/development.rb
|
628
672
|
- spec/rails/templates/erb_integration_system_spec/app/controllers/erb_integration_system_spec_controller.rb
|
629
673
|
- spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_erb_partial_from_widget_partial.html.erb
|
630
674
|
- spec/rails/templates/erb_integration_system_spec/app/views/erb_integration_system_spec/_fortitude_partial_with_underscore_partial.rb
|
@@ -695,6 +739,19 @@ test_files:
|
|
695
739
|
- spec/rails/templates/localization_system_spec/config/locales/en.yml
|
696
740
|
- spec/rails/templates/localization_system_spec/config/locales/fr.yml
|
697
741
|
- spec/rails/templates/localization_system_spec/config/locales/pt.yml
|
742
|
+
- spec/rails/templates/mailer_system_spec/app/controllers/mailer_system_spec_controller.rb
|
743
|
+
- spec/rails/templates/mailer_system_spec/app/mailers/basic_mailer.rb
|
744
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/basic_mail.rb
|
745
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_erb_layout_and_fortitude_view.rb
|
746
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout.rb
|
747
|
+
- spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout_and_erb_view.html.erb
|
748
|
+
- spec/rails/templates/mailer_system_spec/app/views/layouts/erb_layout.html.erb
|
749
|
+
- spec/rails/templates/mailer_system_spec/app/views/layouts/fortitude_layout.rb
|
750
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail.rb
|
751
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_erb_layout_and_fortitude_view.rb
|
752
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout.rb
|
753
|
+
- spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout_and_erb_view.rb
|
754
|
+
- spec/rails/templates/mailer_system_spec/config/environments/production.rb
|
698
755
|
- spec/rails/templates/production_mode_system_spec/app/controllers/production_mode_system_spec_controller.rb
|
699
756
|
- spec/rails/templates/production_mode_system_spec/app/views/production_mode_system_spec/sample_output.rb
|
700
757
|
- spec/rails/templates/rendering_context_system_spec/app/controllers/rendering_context_system_spec_controller.rb
|
@@ -1,85 +0,0 @@
|
|
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
|
@@ -1,390 +0,0 @@
|
|
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
|
-
Array(@options[:additional_gemfile_lines] || [ ]).each do |gemfile_line|
|
252
|
-
gemfile_contents << "\n#{gemfile_line}\n"
|
253
|
-
end
|
254
|
-
|
255
|
-
File.open(gemfile, 'w') { |f| f << gemfile_contents }
|
256
|
-
end
|
257
|
-
|
258
|
-
def with_env(new_env)
|
259
|
-
old_env = { }
|
260
|
-
new_env.keys.each { |k| old_env[k] = ENV[k] }
|
261
|
-
|
262
|
-
begin
|
263
|
-
set_env(new_env)
|
264
|
-
yield
|
265
|
-
ensure
|
266
|
-
set_env(old_env)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def set_env(new_env)
|
271
|
-
new_env.each do |k,v|
|
272
|
-
if v
|
273
|
-
ENV[k] = v
|
274
|
-
else
|
275
|
-
ENV.delete(k)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def splat_template_files!
|
281
|
-
@template_paths.each do |template_path|
|
282
|
-
Find.find(template_path) do |file|
|
283
|
-
next unless File.file?(file)
|
284
|
-
|
285
|
-
if file[0..(template_path.length)] == "#{template_path}/"
|
286
|
-
subpath = file[(template_path.length + 1)..-1]
|
287
|
-
else
|
288
|
-
raise "#{file} isn't under #{template_path}?!?"
|
289
|
-
end
|
290
|
-
dest_file = File.join(@rails_root, subpath)
|
291
|
-
|
292
|
-
FileUtils.mkdir_p(File.dirname(dest_file))
|
293
|
-
FileUtils.cp(file, dest_file)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def start_server!
|
299
|
-
output = File.join(@rails_root, 'log', 'rails-server.out')
|
300
|
-
cmd = "rails server -p #{@port} > '#{output}'"
|
301
|
-
safe_system(cmd, "starting 'rails server' on port #{@port}", :background => true)
|
302
|
-
|
303
|
-
server_pid_file = File.join(@rails_root, 'tmp', 'pids', 'server.pid')
|
304
|
-
|
305
|
-
start_time = Time.now
|
306
|
-
while Time.now < start_time + 15
|
307
|
-
if File.exist?(server_pid_file)
|
308
|
-
server_pid = File.read(server_pid_file).strip
|
309
|
-
if server_pid =~ /^(\d{1,10})$/i
|
310
|
-
@server_pid = Integer(server_pid)
|
311
|
-
break
|
312
|
-
end
|
313
|
-
end
|
314
|
-
sleep 0.1
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
def verify_server!
|
319
|
-
server_verify_url = "http://localhost:#{@port}/working/rails_is_working"
|
320
|
-
uri = URI.parse(server_verify_url)
|
321
|
-
|
322
|
-
data = nil
|
323
|
-
start_time = Time.now
|
324
|
-
while (! data)
|
325
|
-
begin
|
326
|
-
data = Net::HTTP.get_response(uri)
|
327
|
-
rescue Errno::ECONNREFUSED, EOFError
|
328
|
-
raise if Time.now > (start_time + 20)
|
329
|
-
# keep waiting
|
330
|
-
sleep 0.1
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
unless data.code.to_s == '200'
|
335
|
-
raise "'#{server_verify_url}' returned #{data.code.inspect}, not 200"
|
336
|
-
end
|
337
|
-
result = data.body.strip
|
338
|
-
|
339
|
-
unless result =~ /^Rails\s+version\s*:\s*(\d+\.\d+\.\d+)$/
|
340
|
-
raise "'#{server_verify_url}' returned: #{result.inspect}"
|
341
|
-
end
|
342
|
-
actual_version = $1
|
343
|
-
|
344
|
-
if @rails_version && (actual_version != @rails_version)
|
345
|
-
raise "We seem to have spawned the wrong version of Rails; wanted: #{@rails_version.inspect} but got: #{actual_version.inspect}"
|
346
|
-
end
|
347
|
-
|
348
|
-
say "Successfully spawned a server running Rails #{actual_version} on port #{@port}."
|
349
|
-
end
|
350
|
-
|
351
|
-
def is_alive?(pid)
|
352
|
-
cmd = "ps -o pid #{pid}"
|
353
|
-
results = `#{cmd}`
|
354
|
-
results.split(/[\r\n]+/).each do |line|
|
355
|
-
line = line.strip.downcase
|
356
|
-
next if line == 'pid'
|
357
|
-
if line =~ /^\d+$/i
|
358
|
-
return true if Integer(line) == pid
|
359
|
-
else
|
360
|
-
raise "Unexpected output from '#{cmd}': #{results}"
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
false
|
365
|
-
end
|
366
|
-
|
367
|
-
def stop_server!
|
368
|
-
# We do this because under 1.8.7 SIGTERM doesn't seem to work, and it's actually fine to slaughter this
|
369
|
-
# process mercilessly -- we don't need anything it has at this point, anyway.
|
370
|
-
Process.kill("KILL", @server_pid)
|
371
|
-
|
372
|
-
start_time = Time.now
|
373
|
-
|
374
|
-
while true
|
375
|
-
if is_alive?(@server_pid)
|
376
|
-
raise "Unable to kill server at PID #{@server_pid}!" if (Time.now - start_time) > 20
|
377
|
-
say "Waiting for server at PID #{@server_pid} to die."
|
378
|
-
sleep 0.1
|
379
|
-
else
|
380
|
-
break
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
|
-
say "Successfully terminated Rails server at PID #{@server_pid}."
|
385
|
-
|
386
|
-
@server_pid = nil
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|