nitro 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/CHANGELOG +752 -543
  2. data/INSTALL +38 -38
  3. data/README +264 -225
  4. data/Rakefile +48 -49
  5. data/bin/nitro +3 -3
  6. data/bin/nitrogen +6 -6
  7. data/doc/AUTHORS +10 -10
  8. data/doc/CHANGELOG.1 +1939 -1939
  9. data/doc/CHANGELOG.2 +954 -954
  10. data/doc/LICENSE +3 -3
  11. data/doc/MIGRATION +28 -0
  12. data/doc/RELEASES +814 -643
  13. data/doc/config.txt +5 -5
  14. data/install.rb +7 -17
  15. data/lib/nitro.rb +38 -9
  16. data/lib/nitro/adapter/cgi.rb +311 -312
  17. data/lib/nitro/adapter/fastcgi.rb +18 -25
  18. data/lib/nitro/adapter/webrick.rb +128 -137
  19. data/lib/nitro/adapter/wee.rb +51 -0
  20. data/lib/nitro/caching.rb +20 -20
  21. data/lib/nitro/caching/actions.rb +43 -43
  22. data/lib/nitro/caching/fragments.rb +46 -46
  23. data/lib/nitro/caching/invalidation.rb +11 -11
  24. data/lib/nitro/caching/output.rb +65 -65
  25. data/lib/nitro/caching/stores.rb +67 -67
  26. data/lib/nitro/compiler.rb +262 -0
  27. data/lib/nitro/compiler/elements.rb +0 -0
  28. data/lib/nitro/compiler/errors.rb +65 -0
  29. data/lib/nitro/compiler/localization.rb +25 -0
  30. data/lib/nitro/compiler/markup.rb +19 -0
  31. data/lib/nitro/compiler/shaders.rb +206 -0
  32. data/lib/nitro/compiler/squeeze.rb +20 -0
  33. data/lib/nitro/compiler/xslt.rb +61 -0
  34. data/lib/nitro/context.rb +87 -88
  35. data/lib/nitro/controller.rb +151 -158
  36. data/lib/nitro/cookie.rb +34 -34
  37. data/lib/nitro/dispatcher.rb +195 -186
  38. data/lib/nitro/element.rb +132 -126
  39. data/lib/nitro/element/java_script.rb +6 -6
  40. data/lib/nitro/flash.rb +66 -66
  41. data/lib/nitro/mail.rb +192 -192
  42. data/lib/nitro/mixin/buffer.rb +66 -0
  43. data/lib/nitro/mixin/debug.rb +16 -16
  44. data/lib/nitro/mixin/form.rb +88 -0
  45. data/lib/nitro/mixin/helper.rb +2 -2
  46. data/lib/nitro/mixin/javascript.rb +108 -108
  47. data/lib/nitro/mixin/markup.rb +144 -0
  48. data/lib/nitro/mixin/pager.rb +202 -202
  49. data/lib/nitro/mixin/rss.rb +67 -0
  50. data/lib/nitro/mixin/table.rb +63 -0
  51. data/lib/nitro/mixin/xhtml.rb +75 -0
  52. data/lib/nitro/mixin/xml.rb +124 -0
  53. data/lib/nitro/render.rb +183 -359
  54. data/lib/nitro/request.rb +140 -140
  55. data/lib/nitro/response.rb +27 -27
  56. data/lib/nitro/routing.rb +21 -21
  57. data/lib/nitro/scaffold.rb +124 -118
  58. data/lib/nitro/server.rb +117 -80
  59. data/lib/nitro/server/runner.rb +341 -0
  60. data/lib/nitro/service.rb +12 -12
  61. data/lib/nitro/service/xmlrpc.rb +22 -22
  62. data/lib/nitro/session.rb +122 -120
  63. data/lib/nitro/session/drb.rb +9 -9
  64. data/lib/nitro/session/drbserver.rb +34 -34
  65. data/lib/nitro/template.rb +171 -155
  66. data/lib/nitro/testing/assertions.rb +90 -90
  67. data/lib/nitro/testing/context.rb +16 -16
  68. data/lib/nitro/testing/testcase.rb +34 -34
  69. data/proto/conf/lhttpd.conf +9 -9
  70. data/proto/public/error.xhtml +75 -75
  71. data/proto/public/index.xhtml +18 -18
  72. data/proto/public/js/behaviour.js +65 -65
  73. data/proto/public/js/controls.js +1 -1
  74. data/proto/public/js/prototype.js +3 -3
  75. data/proto/public/settings.xhtml +61 -61
  76. data/proto/run.rb +1 -5
  77. data/test/nitro/adapter/raw_post1.bin +0 -0
  78. data/test/nitro/adapter/tc_cgi.rb +57 -57
  79. data/test/nitro/adapter/tc_webrick.rb +4 -4
  80. data/test/nitro/mixin/tc_pager.rb +25 -25
  81. data/test/nitro/mixin/tc_rss.rb +24 -0
  82. data/test/nitro/mixin/tc_table.rb +31 -0
  83. data/test/nitro/mixin/tc_xhtml.rb +13 -0
  84. data/test/nitro/tc_caching.rb +10 -10
  85. data/test/nitro/tc_context.rb +8 -8
  86. data/test/nitro/tc_controller.rb +48 -48
  87. data/test/nitro/tc_cookie.rb +6 -6
  88. data/test/nitro/tc_dispatcher.rb +64 -64
  89. data/test/nitro/tc_element.rb +27 -27
  90. data/test/nitro/tc_flash.rb +31 -31
  91. data/test/nitro/tc_mail.rb +63 -63
  92. data/test/nitro/tc_server.rb +26 -26
  93. data/test/nitro/tc_session.rb +9 -9
  94. data/test/nitro/tc_template.rb +19 -19
  95. data/test/public/blog/list.xhtml +1 -1
  96. metadata +31 -37
  97. data/lib/nitro/buffering.rb +0 -45
  98. data/lib/nitro/builder/form.rb +0 -104
  99. data/lib/nitro/builder/rss.rb +0 -104
  100. data/lib/nitro/builder/table.rb +0 -80
  101. data/lib/nitro/builder/xhtml.rb +0 -132
  102. data/lib/nitro/builder/xml.rb +0 -131
  103. data/lib/nitro/conf.rb +0 -36
  104. data/lib/nitro/environment.rb +0 -21
  105. data/lib/nitro/errors.rb +0 -69
  106. data/lib/nitro/localization.rb +0 -153
  107. data/lib/nitro/markup.rb +0 -147
  108. data/lib/nitro/output.rb +0 -24
  109. data/lib/nitro/runner.rb +0 -348
  110. data/lib/nitro/shaders.rb +0 -206
  111. data/test/nitro/builder/tc_rss.rb +0 -23
  112. data/test/nitro/builder/tc_table.rb +0 -30
  113. data/test/nitro/builder/tc_xhtml.rb +0 -39
  114. data/test/nitro/builder/tc_xml.rb +0 -56
  115. data/test/nitro/tc_localization.rb +0 -49
@@ -1,4 +1,5 @@
1
1
  require 'glue/flexob'
2
+ require 'glue/configuration'
2
3
 
3
4
  module Nitro
4
5
 
@@ -9,131 +10,131 @@ module Nitro
9
10
 
10
11
  module TemplateMixin
11
12
 
12
- # Convert a template to actual Ruby code, ready to be
13
- # evaluated.
14
- #
15
- # [+template+]
16
- # The template as a String.
17
- #
18
- # [+buffer+]
19
- # The variable to act as a buffer where the ruby code
20
- # for this template will be generated. Passed as a|
21
- # String.
22
- #
23
- # [+base_dir+]
24
- # The base directory where the templates reside.
25
-
26
- def compile_template(template, buffer = '@out', base_dir = Dir.pwd)
27
- text = template.dup
28
-
29
- # Strip the xml header! (interracts with the following gsub!)
30
- text.gsub!(/<\?xml.*\?>/, "")
31
-
32
- # Statically include sub-template files.
33
- # The target file is included at compile time.
34
- #
35
- # gmosx: must be xformed before the <?r pi.
36
- #
37
- # Example:
38
- # <?include href="root/myfile.sx" ?>
39
-
40
- text.gsub!(/<\?include href=["|'](.*?)["|'](.*)\?>/) do |match|
41
- text = File.read("#{base_dir}/#$1")
42
- text.gsub!(/<\?xml.*\?>/, '')
43
- text.gsub!(/<\/?root(.*?)>/m, ' ');
44
- text
45
- end
46
-
47
- # Transform include instructions <include href="xxx" />
48
- # must be transformed before the processinc instructions.
49
- # Useful to include fragments cached on disk
50
- #
51
- # gmosx, FIXME: NOT TESTED! test and add caching.
52
- # add load_statically_included fixes.
53
-
54
- text.gsub!(/<include href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
55
- "<?r File.read( '\#\{@dispatcher.root\}/#$1' ?>"
56
- end
57
-
58
- # xform render/inject instructions <render href="xxx" />
59
- # must be transformed before the processinc instructions.
60
-
61
- text.gsub!(/<inject href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
62
- "<?r render '/#$1' ?>"
63
- end
64
-
65
- text.gsub!(/<render href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
66
- "<?r render '/#$1' ?>"
67
- end
68
-
69
- # Remove <root> elements. typically removed by xslt but lets
70
- # play it safe. The <root> element is typically added to
71
- # template files to make them XHTML valid.
72
-
73
- text.gsub!(/<(\/)?root>/, '')
74
-
75
- # Transform the processing instructions, use <?r as
76
- # a marker.
77
-
78
- text.gsub!(/\?>/, "; #{buffer} << %^")
79
- text.gsub!(/<\?r(\s?)/, "^; ")
80
-
81
- # Transform alternative code tags.
82
- # (very useful in xsl stylesheets)
83
-
84
- text.gsub!(/<\/ruby>/, "; #{buffer} << %^")
85
- text.gsub!(/<ruby>/, "^; ")
86
-
87
- # Also handle erb/asp/jsp style tags. Those tags
88
- # *cannot* be used with an xslt stylesheet.
89
-
90
- text.gsub!(/%>/, "; #{buffer} << %^")
91
- text.gsub!(/<%/, "^; ")
92
-
93
- # Alterative versions of interpolation.
94
- # (very useful in xsl stylesheets)
95
- # Example: #(my_val)
96
-
97
- text.gsub!(/\#\((.*?)\)/, '#{\1}')
98
-
99
- # Alternative for entities.
100
- # (useful in xsl stylesheets)
101
- # Examples: %nbsp;, %rquo;
102
-
103
- text.gsub!(/%(\S*?);/, '&\1;')
104
-
105
- # Compile time ruby code. This code is evaluated when
106
- # compiling the template and the result injected directly
107
- # into the result. Usefull for example to prevaluate
108
- # localization. Just use the #[] marker instead of #{}.
109
-
110
- text.gsub!(/\#\[(.*?)\]/) do |match|
111
- eval($1)
112
- end
113
-
114
- text = "#{buffer} << %^" + text + "^"
115
-
116
- return text
117
- end
118
-
119
- # Render the template.
120
- #
121
- # [+ruby+]
122
- # A String containing the compiled template
123
- # code.
124
- #
125
- # [+binding+]
126
- # The evaluation binding for the rendering.
127
-
128
- def render_template(ruby, the_binding = nil)
129
- eval(ruby, the_binding)
130
- end
131
-
132
- # Compile and render the template.
133
-
134
- def process_template(template, buffer = '@out', the_binding = nil)
135
- render_template(compile_template(template, buffer), the_binding)
136
- end
13
+ # Convert a template to actual Ruby code, ready to be
14
+ # evaluated.
15
+ #
16
+ # [+template+]
17
+ # The template as a String.
18
+ #
19
+ # [+buffer+]
20
+ # The variable to act as a buffer where the ruby code
21
+ # for this template will be generated. Passed as a|
22
+ # String.
23
+ #
24
+ # [+base_dir+]
25
+ # The base directory where the templates reside.
26
+
27
+ def compile_template(template, buffer = '@out', base_dir = Dir.pwd)
28
+ text = template.dup
29
+
30
+ # Strip the xml header! (interracts with the following gsub!)
31
+ text.gsub!(/<\?xml.*\?>/, "")
32
+
33
+ # Statically include sub-template files.
34
+ # The target file is included at compile time.
35
+ #
36
+ # gmosx: must be xformed before the <?r pi.
37
+ #
38
+ # Example:
39
+ # <?include href="root/myfile.sx" ?>
40
+
41
+ text.gsub!(/<\?include href=["|'](.*?)["|'](.*)\?>/) do |match|
42
+ text = File.read("#{base_dir}/#$1")
43
+ text.gsub!(/<\?xml.*\?>/, '')
44
+ text.gsub!(/<\/?root(.*?)>/m, ' ');
45
+ text
46
+ end
47
+
48
+ # Transform include instructions <include href="xxx" />
49
+ # must be transformed before the processinc instructions.
50
+ # Useful to include fragments cached on disk
51
+ #
52
+ # gmosx, FIXME: NOT TESTED! test and add caching.
53
+ # add load_statically_included fixes.
54
+
55
+ text.gsub!(/<include href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
56
+ "<?r File.read( '\#\{@dispatcher.root\}/#$1' ?>"
57
+ end
58
+
59
+ # xform render/inject instructions <render href="xxx" />
60
+ # must be transformed before the processinc instructions.
61
+
62
+ text.gsub!(/<inject href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
63
+ "<?r render '/#$1' ?>"
64
+ end
65
+
66
+ text.gsub!(/<render href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
67
+ "<?r render '/#$1' ?>"
68
+ end
69
+
70
+ # Remove <root> elements. typically removed by xslt but lets
71
+ # play it safe. The <root> element is typically added to
72
+ # template files to make them XHTML valid.
73
+
74
+ text.gsub!(/<(\/)?root>/, '')
75
+
76
+ # Transform the processing instructions, use <?r as
77
+ # a marker.
78
+
79
+ text.gsub!(/\?>/, "; #{buffer} << %^")
80
+ text.gsub!(/<\?r(\s?)/, "^; ")
81
+
82
+ # Transform alternative code tags.
83
+ # (very useful in xsl stylesheets)
84
+
85
+ text.gsub!(/<\/ruby>/, "; #{buffer} << %^")
86
+ text.gsub!(/<ruby>/, "^; ")
87
+
88
+ # Also handle erb/asp/jsp style tags. Those tags
89
+ # *cannot* be used with an xslt stylesheet.
90
+
91
+ text.gsub!(/%>/, "; #{buffer} << %^")
92
+ text.gsub!(/<%/, "^; ")
93
+
94
+ # Alterative versions of interpolation.
95
+ # (very useful in xsl stylesheets)
96
+ # Example: #\my_val\
97
+
98
+ text.gsub!(/\#\\(.*?)\\/, '#{\1}')
99
+
100
+ # Alternative for entities.
101
+ # (useful in xsl stylesheets)
102
+ # Examples: %nbsp;, %rquo;
103
+
104
+ text.gsub!(/%(\S*?);/, '&\1;')
105
+
106
+ # Compile time ruby code. This code is evaluated when
107
+ # compiling the template and the result injected directly
108
+ # into the result. Usefull for example to prevaluate
109
+ # localization. Just use the #[] marker instead of #{}.
110
+
111
+ text.gsub!(/\#\[(.*?)\]/) do |match|
112
+ eval($1)
113
+ end
114
+
115
+ text = "#{buffer} << %^" + text + "^"
116
+
117
+ return text
118
+ end
119
+
120
+ # Render the template.
121
+ #
122
+ # [+ruby+]
123
+ # A String containing the compiled template
124
+ # code.
125
+ #
126
+ # [+binding+]
127
+ # The evaluation binding for the rendering.
128
+
129
+ def render_template(ruby, the_binding = nil)
130
+ eval(ruby, the_binding)
131
+ end
132
+
133
+ # Compile and render the template.
134
+
135
+ def process_template(template, buffer = '@out', the_binding = nil)
136
+ render_template(compile_template(template, buffer), the_binding)
137
+ end
137
138
 
138
139
  end
139
140
 
@@ -141,12 +142,27 @@ end
141
142
  # as singleton methods.
142
143
 
143
144
  class Template
144
- class << self
145
- include TemplateMixin
146
- alias_method :compile, :compile_template
147
- alias_method :render, :render_template
148
- alias_method :process, :process_template
149
- end
145
+
146
+ # The default root directory where template files reside.
147
+
148
+ setting :root, :default => 'public', :doc => 'The default root directory where template files reside'
149
+
150
+ # The default template name.
151
+
152
+ setting :default, :default => 'index', :doc => 'The default template name'
153
+
154
+ # The default template file extension.
155
+
156
+ setting :extension, :default => 'xhtml', :doc => 'The default template file extension'
157
+
158
+ class << self
159
+ include TemplateMixin
160
+ alias_method :compile, :compile_template
161
+ alias_method :transform, :compile_template
162
+ alias_method :render, :render_template
163
+ alias_method :process, :process_template
164
+ end
165
+
150
166
  end
151
167
 
152
168
  # A Template that reads from files and also
@@ -155,30 +171,30 @@ end
155
171
  # expansion environment.
156
172
 
157
173
  class FileTemplate < Flexob
158
- include TemplateMixin
159
-
160
- @@compiled_template_cache = {}
161
-
162
- attr_accessor :template_filename
163
-
164
- def initialize(filename = nil)
165
- super
166
- @template_filename = filename
167
- end
168
-
169
- def process
170
- __out__ = ''
171
-
172
- unless compiled = @@compiled_template_cache[@template_filename]
173
- template = File.read(@template_filename)
174
- compiled = compile_template(template, '__out__')
175
- @@compiled_template_cache[@template_filename] = compiled
176
- end
177
-
178
- render_template(compiled, binding)
179
-
180
- return __out__
181
- end
174
+ include TemplateMixin
175
+
176
+ @@compiled_template_cache = {}
177
+
178
+ attr_accessor :template_filename
179
+
180
+ def initialize(filename = nil)
181
+ super
182
+ @template_filename = filename
183
+ end
184
+
185
+ def process
186
+ __out__ = ''
187
+
188
+ unless compiled = @@compiled_template_cache[@template_filename]
189
+ template = File.read(@template_filename)
190
+ compiled = compile_template(template, '__out__')
191
+ @@compiled_template_cache[@template_filename] = compiled
192
+ end
193
+
194
+ render_template(compiled, binding)
195
+
196
+ return __out__
197
+ end
182
198
  end
183
199
 
184
200
  end
@@ -4,96 +4,96 @@ require 'rexml/document'
4
4
 
5
5
  module Test::Unit::Assertions
6
6
 
7
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8
- # :section: General assertions.
9
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10
-
11
- def assert_status_ok(msg = nil)
12
- msg = format_msg("Status not ok", msg)
13
- assert_block(msg) { @context.status_ok? }
14
- end
15
-
16
- def assert_output_match(re, msg = nil)
17
- msg = format_msg("Rendered output does not match '#{re}'", msg)
18
- assert_block(msg) { @context.out =~ Regexp.new(re) }
19
- end
20
- alias_method :assert_output_contains, :assert_output_match
21
-
22
- def assert_output_no_match(re, msg = nil)
23
- msg = format_msg("Rendered output matches '#{re}'", msg)
24
- assert_block(msg) { @context.out =~ Regexp.new(re) }
25
- end
26
- alias_method :assert_output_contains_no, :assert_output_no_match
27
-
28
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29
- # :section: Session related assertions.
30
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31
-
32
- def assert_session_has(key, msg = nil)
33
- msg = format_msg("Object '#{key}' not found in session", msg)
34
- assert_block(msg) { @context.session[key] }
35
- end
36
-
37
- def assert_session_has_no(key, msg = nil)
38
- msg = format_msg("Unexpected object '#{key}' found in session", msg)
39
- assert_block(msg) { !@context.session[key] }
40
- end
41
- alias_method :assert_session_has_not, :assert_session_has_no
42
-
43
- def assert_session_equal(key, value, msg = nil)
44
- msg = format_msg("The value of session object '#{key}' is '#{@context.session[key]}' but was expected '#{value}'", msg)
45
- assert_block(msg) { @context.session[key] == value }
46
- end
47
-
48
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49
- # :section: Cookies related assertions.
50
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
-
52
- def assert_has_cookie(name, msg = nil)
53
- msg = format_msg("Cookie '#{name}' not found", msg)
54
- assert_block(msg) { @context.response_cookie(name) }
55
- end
56
-
57
- def assert_has_no_cookie(name, msg = nil)
58
- msg = format_msg("Unexpected cookie '#{name}' found", msg)
59
- assert_block(msg) { !@context.response_cookie(name) }
60
- end
61
-
62
- def assert_cookie_equal(name, value, msg = nil)
63
- unless cookie = @context.response_cookie(name)
64
- msg = format_msg("Cookie '#{name}' not found", msg)
65
- assert_block(msg) { false }
66
- end
67
- msg = format_msg("The value of cookie '#{name}' is '#{cookie.value}' but was expected '#{value}'", msg)
68
- assert_block(msg) { cookie.value == value }
69
- end
70
-
71
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
- # :section: Template related assertions.
73
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74
-
75
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76
- # :section: Redirection assertions.
77
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78
-
79
- def assert_redirect(msg = nil)
80
- msg = format_msg("No redirection (status = #{@context.status})", msg)
81
- assert_block(msg) { @context.redirect? }
82
- end
83
-
84
- def assert_no_redirect(msg = nil)
85
- msg = format_msg("Unexpected redirection (location = '#{@context.response_headers['location']}')", msg)
86
- assert_block(msg) { !@context.redirect? }
87
- end
88
-
89
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90
- # :section: Utility methods
91
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92
-
93
- def format_msg(message, extra) # :nodoc:
94
- extra += ', ' if extra
95
- return "#{extra}#{message}"
96
- end
7
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8
+ # :section: General assertions.
9
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10
+
11
+ def assert_status_ok(msg = nil)
12
+ msg = format_msg("Status not ok", msg)
13
+ assert_block(msg) { @context.status_ok? }
14
+ end
15
+
16
+ def assert_output_match(re, msg = nil)
17
+ msg = format_msg("Rendered output does not match '#{re}'", msg)
18
+ assert_block(msg) { @context.out =~ Regexp.new(re) }
19
+ end
20
+ alias_method :assert_output_contains, :assert_output_match
21
+
22
+ def assert_output_no_match(re, msg = nil)
23
+ msg = format_msg("Rendered output matches '#{re}'", msg)
24
+ assert_block(msg) { @context.out =~ Regexp.new(re) }
25
+ end
26
+ alias_method :assert_output_contains_no, :assert_output_no_match
27
+
28
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29
+ # :section: Session related assertions.
30
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31
+
32
+ def assert_session_has(key, msg = nil)
33
+ msg = format_msg("Object '#{key}' not found in session", msg)
34
+ assert_block(msg) { @context.session[key] }
35
+ end
36
+
37
+ def assert_session_has_no(key, msg = nil)
38
+ msg = format_msg("Unexpected object '#{key}' found in session", msg)
39
+ assert_block(msg) { !@context.session[key] }
40
+ end
41
+ alias_method :assert_session_has_not, :assert_session_has_no
42
+
43
+ def assert_session_equal(key, value, msg = nil)
44
+ msg = format_msg("The value of session object '#{key}' is '#{@context.session[key]}' but was expected '#{value}'", msg)
45
+ assert_block(msg) { @context.session[key] == value }
46
+ end
47
+
48
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49
+ # :section: Cookies related assertions.
50
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
+
52
+ def assert_has_cookie(name, msg = nil)
53
+ msg = format_msg("Cookie '#{name}' not found", msg)
54
+ assert_block(msg) { @context.response_cookie(name) }
55
+ end
56
+
57
+ def assert_has_no_cookie(name, msg = nil)
58
+ msg = format_msg("Unexpected cookie '#{name}' found", msg)
59
+ assert_block(msg) { !@context.response_cookie(name) }
60
+ end
61
+
62
+ def assert_cookie_equal(name, value, msg = nil)
63
+ unless cookie = @context.response_cookie(name)
64
+ msg = format_msg("Cookie '#{name}' not found", msg)
65
+ assert_block(msg) { false }
66
+ end
67
+ msg = format_msg("The value of cookie '#{name}' is '#{cookie.value}' but was expected '#{value}'", msg)
68
+ assert_block(msg) { cookie.value == value }
69
+ end
70
+
71
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
+ # :section: Template related assertions.
73
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74
+
75
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76
+ # :section: Redirection assertions.
77
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78
+
79
+ def assert_redirect(msg = nil)
80
+ msg = format_msg("No redirection (status = #{@context.status})", msg)
81
+ assert_block(msg) { @context.redirect? }
82
+ end
83
+
84
+ def assert_no_redirect(msg = nil)
85
+ msg = format_msg("Unexpected redirection (location = '#{@context.response_headers['location']}')", msg)
86
+ assert_block(msg) { !@context.redirect? }
87
+ end
88
+
89
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90
+ # :section: Utility methods
91
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92
+
93
+ def format_msg(message, extra) # :nodoc:
94
+ extra += ', ' if extra
95
+ return "#{extra}#{message}"
96
+ end
97
97
 
98
98
  end
99
99