markaby 0.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.rdoc +79 -0
  3. data/Markaby.gemspec +103 -0
  4. data/{README → README.rdoc} +14 -6
  5. data/Rakefile +71 -14
  6. data/VERSION +1 -0
  7. data/garlic.rb +29 -0
  8. data/init.rb +6 -0
  9. data/lib/markaby.rb +4 -9
  10. data/lib/markaby/builder.rb +156 -143
  11. data/lib/markaby/builder_tags.rb +64 -0
  12. data/lib/markaby/cssproxy.rb +36 -34
  13. data/lib/markaby/kernel_method.rb +7 -0
  14. data/lib/markaby/rails.rb +64 -39
  15. data/lib/markaby/rails/current.rb +46 -0
  16. data/lib/markaby/rails/deprecated.rb +124 -0
  17. data/lib/markaby/rails/rails_builder.rb +50 -0
  18. data/lib/markaby/tags.rb +158 -130
  19. data/lib/markaby/tilt.rb +21 -0
  20. data/spec/markaby/builder_spec.rb +118 -0
  21. data/spec/markaby/css_proxy_spec.rb +47 -0
  22. data/spec/markaby/fragment_spec.rb +10 -0
  23. data/spec/markaby/markaby_other_static.mab +1 -0
  24. data/spec/markaby/markaby_spec.rb +232 -0
  25. data/spec/markaby/rails/spec_helper.rb +21 -0
  26. data/spec/markaby/rails/views/markaby/_a_partial.mab +3 -0
  27. data/spec/markaby/rails/views/markaby/_partial_child_with_locals.mab +1 -0
  28. data/spec/markaby/rails/views/markaby/access_to_helpers.mab +1 -0
  29. data/spec/markaby/rails/views/markaby/broken.mab +7 -0
  30. data/spec/markaby/rails/views/markaby/correct_template_values.mab +5 -0
  31. data/spec/markaby/rails/views/markaby/form_for.mab +2 -0
  32. data/spec/markaby/rails/views/markaby/form_for_with_fields.mab +3 -0
  33. data/spec/markaby/rails/views/markaby/form_for_with_multiple_fields.mab +4 -0
  34. data/spec/markaby/rails/views/markaby/no_values_passed.mab +3 -0
  35. data/spec/markaby/rails/views/markaby/partial_parent.mab +1 -0
  36. data/spec/markaby/rails/views/markaby/partial_parent_with_locals.mab +7 -0
  37. data/spec/markaby/rails/views/markaby/render_erb_without_explicit_render_call.erb +1 -0
  38. data/spec/markaby/rails/views/markaby/render_explicit_but_empty_markaby_layout.mab +0 -0
  39. data/spec/markaby/rails/views/markaby/render_mab_without_explicit_render_call.mab +3 -0
  40. data/spec/markaby/rails/views/markaby/render_with_ivar.mab +3 -0
  41. data/spec/markaby/rails/views/markaby/renders_erb.rhtml +1 -0
  42. data/spec/markaby/rails_spec.rb +249 -0
  43. data/spec/markaby/rails_version_spec.rb +37 -0
  44. data/spec/markaby/tilt/erb.erb +1 -0
  45. data/spec/markaby/tilt/locals.mab +1 -0
  46. data/spec/markaby/tilt/markaby.mab +1 -0
  47. data/spec/markaby/tilt/markaby_other_static.mab +1 -0
  48. data/spec/markaby/tilt/render_twice.mab +1 -0
  49. data/spec/markaby/tilt/scope.mab +1 -0
  50. data/spec/markaby/tilt/yielding.mab +2 -0
  51. data/spec/markaby/tilt_spec.rb +86 -0
  52. data/spec/spec.opts +2 -0
  53. data/spec/spec_helper.rb +39 -0
  54. metadata +132 -52
  55. data/lib/markaby/metaid.rb +0 -16
  56. data/lib/markaby/template.rb +0 -12
  57. data/setup.rb +0 -1551
  58. data/test/test_markaby.rb +0 -109
  59. data/tools/rakehelp.rb +0 -106
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ class CssProxyTest < Test::Unit::TestCase
4
+ it "should have method_missing as private" do
5
+ methods = Markaby::CssProxy.private_instance_methods.dup
6
+ methods.map! { |m| m.to_sym }
7
+
8
+ methods.should include(:method_missing)
9
+ end
10
+
11
+ def mock_builder
12
+ mock_builder = Class.new do
13
+ def tag!(*args); end
14
+ end.new
15
+ end
16
+
17
+ def test_responds_to_everything
18
+ proxy = Markaby::CssProxy.new(mock_builder, 'stream', :sym)
19
+
20
+ assert proxy.respond_to?(:any_method)
21
+ assert proxy.respond_to?(:foobarbazasdfasdfadfs)
22
+ end
23
+
24
+ def test_does_not_respond_to_method_missing
25
+ proxy = Markaby::CssProxy.new(mock_builder, 'stream', :sym)
26
+
27
+ assert !proxy.respond_to?(:method_missing)
28
+ end
29
+
30
+ def test_does_respond_to_private_instance_methods_with_private_flag_set_to_true
31
+ proxy = Markaby::CssProxy.new(mock_builder, 'stream', :sym)
32
+
33
+ assert proxy.respond_to?(:method_missing, true)
34
+ end
35
+
36
+ def test_does_not_respond_to_private_instance_methods_with_private_flag_set_to_false
37
+ proxy = Markaby::CssProxy.new(mock_builder, 'stream', :sym)
38
+
39
+ assert !proxy.respond_to?(:method_missing, false)
40
+ end
41
+
42
+ def test_respond_to_should_always_return_boolean
43
+ proxy = Markaby::CssProxy.new(mock_builder, 'stream', :sym)
44
+
45
+ assert_equal proxy.respond_to?(:method_missing, :a_value), true
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ class FragmentTest < Test::Unit::TestCase
4
+ it "should have method_missing as a private instance method" do
5
+ private_methods = Markaby::Fragment.private_instance_methods.dup
6
+ private_methods.map! { |m| m.to_sym }
7
+
8
+ private_methods.should include(:method_missing)
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ text "_why?"
@@ -0,0 +1,232 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ class MarkabyTest < Test::Unit::TestCase
4
+ def teardown
5
+ Markaby::Builder.restore_defaults!
6
+ end
7
+
8
+ def test_simple
9
+ assert_equal "<hr/>", mab { hr }
10
+ assert_equal "<hr/><br/>", mab { hr; br }
11
+ assert_equal "<p>foo</p>", mab { p 'foo' }
12
+ assert_equal "<p>foo</p>", mab { p { 'foo' } }
13
+ end
14
+
15
+ def test_classes_and_ids
16
+ assert_equal %{<div class="one"></div>}, mab { div.one '' }
17
+ assert_equal %{<div class="one two"></div>}, mab { div.one.two '' }
18
+ assert_equal %{<div id="three"></div>}, mab { div.three! '' }
19
+ assert_equal %{<hr class="hidden"/>}, mab { hr.hidden }
20
+
21
+ out = mab { input.foo :id => 'bar' }
22
+ out.should match("<input.*class=\"foo\".*/>")
23
+ out.should match("<input.*name=\"bar\".*/>")
24
+ end
25
+
26
+ def test_escaping
27
+ assert_equal "<h1>Apples &amp; Oranges</h1>", mab { h1 'Apples & Oranges' }
28
+ assert_equal "<h1>Apples & Oranges</h1>", mab { h1 { 'Apples & Oranges' } }
29
+ assert_equal "<h1 class=\"fruits&amp;floots\">Apples</h1>", mab { h1 'Apples', :class => 'fruits&floots' }
30
+ end
31
+
32
+ def test_capture
33
+ builder = Markaby::Builder.new
34
+ assert builder.to_s.empty?
35
+ assert_equal "<h1>TEST</h1>", builder.capture { h1 'TEST' }
36
+ assert builder.to_s.empty?
37
+ assert mab { capture { h1 'hello world' }; nil }.empty?
38
+ assert_equal mab { div { h1 'TEST' } }, mab { div { capture { h1 'TEST' } } }
39
+ end
40
+
41
+ def test_ivars
42
+ html = "<div><h1>Steve</h1><div><h2>Gerald</h2></div><h3>Gerald</h3></div>"
43
+ assert_equal html, mab { div { @name = 'Steve'; h1 @name; div { @name = 'Gerald'; h2 @name }; h3 @name } }
44
+ assert_equal html, mab { div { @name = 'Steve'; h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
45
+ assert_equal html, mab(:name => 'Steve') { div { h1 @name; self << capture { div { @name = 'Gerald'; h2 @name } }; h3 @name } }
46
+ end
47
+
48
+ def test_ivars_without_at_symbol
49
+ assert_equal "<h1>Hello World</h1>", mab { @message = 'Hello World'; h1 message }
50
+ end
51
+
52
+ def spec_helpers
53
+ Markaby::Builder.ignored_helpers.clear
54
+ assert_equal %{squirrels}, mab({}, MarkabyTestHelpers) { pluralize('squirrel') }
55
+ assert_equal %{<a href="">edit</a>}, mab({}, MarkabyTestHelpers) { link_to('edit') }
56
+ assert mab({}, MarkabyTestHelpers) { @output_helpers = false; link_to('edit'); nil }.empty?
57
+ Markaby::Builder.ignore_helpers :pluralize
58
+ assert_exception(NoMethodError, "undefined method `pluralize'", {}, MarkabyTestHelpers) { pluralize('squirrel') }
59
+ end
60
+
61
+ def test_uses_helper_instance_variable
62
+ helper = Module.new do
63
+ @some_ivar = :ivar_value
64
+ end
65
+
66
+ builder = Markaby::Builder.new({}, helper)
67
+ assert_equal :ivar_value, builder.some_ivar
68
+ end
69
+
70
+ it "can assign helpers after instantiation" do
71
+ helper = mock 'helper', :foo => :bar
72
+
73
+ builder = Markaby::Builder.new
74
+ builder.helper = helper
75
+ assert_equal :bar, builder.foo
76
+ end
77
+
78
+ it "should be able to set a local" do
79
+ builder = Markaby::Builder.new
80
+ builder.locals = { :foo => "bar" }
81
+ builder.foo.should == "bar"
82
+ end
83
+
84
+ it "should be able to set a different local value" do
85
+ builder = Markaby::Builder.new
86
+ builder.locals = { :foo => "baz" }
87
+ builder.foo.should == "baz"
88
+ end
89
+
90
+ it "should assign the correct key" do
91
+ builder = Markaby::Builder.new
92
+ builder.locals = { :key => :value }
93
+ builder.key.should == :value
94
+ end
95
+
96
+ it "should be able to assign multiple locals" do
97
+ builder = Markaby::Builder.new
98
+
99
+ builder.locals = { :one => "two", :three => "four" }
100
+
101
+ builder.one.should == "two"
102
+ builder.three.should == "four"
103
+ end
104
+
105
+ def test_builder_bang_methods
106
+ assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", mab { instruct! }
107
+ end
108
+
109
+ it "should be able to produce the correct html from a fragment" do
110
+ str = ""
111
+ str += "<div>"
112
+ str += "<h1>Monkeys</h1>"
113
+ str += "<h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2>"
114
+ str += "<h3>Donkeys</h3>"
115
+ str += "<h4>Parakeet <b><i>Innocent IV</i></b> in Classic Chartreuse</h4>"
116
+ str += "</div>"
117
+
118
+ generated = mab {
119
+ div {
120
+ h1 "Monkeys"
121
+ h2 {
122
+ "Giraffes #{small('Miniature')} and #{strong 'Large'}"
123
+ }
124
+ h3 "Donkeys"
125
+ h4 { "Parakeet #{b { i 'Innocent IV' }} in Classic Chartreuse" }
126
+ }
127
+ }
128
+
129
+ generated.should == str
130
+ end
131
+
132
+ def test_fragments
133
+ assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <strong>Miniature</strong></h2><h3>Donkeys</h3></div>},
134
+ mab { div { h1 "Monkeys"; h2 { "Giraffes #{strong 'Miniature' }" }; h3 "Donkeys" } }
135
+
136
+ assert_equal %{<div><h1>Monkeys</h1><h2>Giraffes <small>Miniature</small> and <strong>Large</strong></h2><h3>Donkeys</h3><h4>Parakeet <strong>Large</strong> as well...</h4></div>},
137
+ mab { div { @a = small 'Miniature'; @b = strong 'Large'; h1 "Monkeys"; h2 { "Giraffes #{@a} and #{@b}" }; h3 "Donkeys"; h4 { "Parakeet #{@b} as well..." } } }
138
+ end
139
+
140
+ def test_invalid_xhtml
141
+ assert_exception(NoMethodError, "undefined method `dav'") { dav {} }
142
+ assert_exception(Markaby::InvalidXhtmlError, "no attribute `styl' on div elements") { div(:styl => 'ok') {} }
143
+ assert_exception(Markaby::InvalidXhtmlError, "no attribute `class' on tbody elements") { tbody.okay {} }
144
+ end
145
+
146
+ def test_full_doc_transitional
147
+ doc = mab { xhtml_transitional { head { title 'OKay' } } }
148
+ assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
149
+ assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">})
150
+ assert doc.include?(%{<title>OKay</title>})
151
+ end
152
+
153
+ def test_full_doc_strict
154
+ doc = mab { xhtml_strict { head { title 'OKay' } } }
155
+ assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
156
+ assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
157
+ assert doc.include?(%{<title>OKay</title>})
158
+ end
159
+
160
+ def test_full_doc_frameset
161
+ doc = mab { xhtml_frameset { head { title 'OKay' } } }
162
+ assert doc =~ /^<\?xml version="1.0" encoding="UTF-8"\?>/
163
+ assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">})
164
+ assert doc.include?(%{<title>OKay</title>})
165
+ end
166
+
167
+ def test_root_attributes_can_be_changed
168
+ doc = mab { xhtml_strict(:lang => 'fr') { head { title { 'Salut!' } } } }
169
+ assert doc.include?(%{"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">})
170
+ assert doc.include?(%{<title>Salut!</title>})
171
+ assert doc.include?(%{ lang="fr"})
172
+ end
173
+
174
+ def version_file
175
+ File.expand_path(File.dirname(__FILE__) + "/../../VERSION")
176
+ end
177
+
178
+ def test_markaby_should_have_correct_version
179
+ assert_equal Markaby::VERSION, File.read(version_file).strip
180
+ end
181
+
182
+ def test_duplicate_usage_of_same_id
183
+ assert_raises Markaby::InvalidXhtmlError do
184
+ mab do
185
+ p.one!
186
+ p.one!
187
+ end
188
+ end
189
+ end
190
+
191
+ # auto validation
192
+
193
+ def test_tagging_with_invalid_tag_should_raise_error
194
+ assert_raises Markaby::InvalidXhtmlError do
195
+ mab do
196
+ tag! :an_invalid_tag
197
+ end
198
+ end
199
+ end
200
+
201
+ def test_self_closing_html_tag_with_block_throws_errors
202
+ assert_raises Markaby::InvalidXhtmlError do
203
+ mab do
204
+ html_tag :img do
205
+ end
206
+ end
207
+ end
208
+ end
209
+
210
+ def test_local_assigning
211
+ builder = Markaby::Builder.new(:variable => :a_value)
212
+
213
+ assert_equal :a_value, builder.variable
214
+ end
215
+
216
+ def test_local_assignment_with_strings
217
+ builder = Markaby::Builder.new("variable" => :a_value)
218
+ assert_equal :a_value, builder.variable
219
+ end
220
+
221
+ def test_local_assignment_prefers_symbols_to_strings
222
+ builder = Markaby::Builder.new("variable" => "string_value", :variable => :symbol_value)
223
+ assert_equal :symbol_value, builder.variable
224
+ end
225
+
226
+ def test_method_missing_should_call_tag_if_no_tagset_present
227
+ Markaby::Builder.set(:tagset, nil)
228
+
229
+ builder = Markaby::Builder.new
230
+ builder.something.should == "<something/>"
231
+ end
232
+ end
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+
3
+ unless defined?(RUNNING_RAILS)
4
+ MARKABY_ROOT = File.join(File.dirname(__FILE__), "..", "..", "..")
5
+ rails_root = File.join(MARKABY_ROOT, "..", "..", "..")
6
+ RAILS_BOOT_FILE = File.join(rails_root, "config", "boot.rb")
7
+
8
+ RUNNING_RAILS = File.exists?(RAILS_BOOT_FILE) ? true : false
9
+ end
10
+
11
+ if RUNNING_RAILS
12
+ ENV["RAILS_ENV"] ||= "test"
13
+ require RAILS_BOOT_FILE
14
+ Rails::Initializer.run
15
+ require 'action_controller/test_process'
16
+
17
+ $:.unshift MARKABY_ROOT
18
+ require 'init'
19
+ else
20
+ warn "Skipping rails specific tests"
21
+ end
@@ -0,0 +1,3 @@
1
+ ul do
2
+ li "smtlaissezfaire"
3
+ end
@@ -0,0 +1 @@
1
+ link_to "bar", "/foo"
@@ -0,0 +1,7 @@
1
+ div {
2
+ ul {
3
+ li 'one'
4
+ li 'two'
5
+ li supercalifragilisticexpialidocious
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ ul do
2
+ li "smt"
3
+ li "joho"
4
+ li "spox"
5
+ end
@@ -0,0 +1,2 @@
1
+ form_for :obj do
2
+ end
@@ -0,0 +1,3 @@
1
+ form_for :foo do |f|
2
+ f.text_field :foo
3
+ end
@@ -0,0 +1,4 @@
1
+ form_for :foo do |f|
2
+ f.text_field :foo
3
+ f.text_field :baz
4
+ end
@@ -0,0 +1,3 @@
1
+ ul do
2
+ li "Scott"
3
+ end
@@ -0,0 +1 @@
1
+ render :partial => "a_partial"
@@ -0,0 +1,7 @@
1
+ ul do
2
+ authors = ["smtlaissezfaire"]
3
+
4
+ authors.each do |author|
5
+ render :partial => "partial_child_with_locals", :locals => {:author => author}
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ ul do
2
+ li @user
3
+ end
@@ -0,0 +1 @@
1
+ Hello, from erb!
@@ -0,0 +1,249 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'spec_helper')
2
+
3
+ if RUNNING_RAILS
4
+ class NonSpecificTestController < ActionController::Base
5
+ VIEW_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'rails', 'views'))
6
+
7
+ around_filter :catch_exceptions
8
+
9
+ attr_reader :last_exception
10
+
11
+ def catch_exceptions
12
+ yield
13
+ rescue Exception => @last_exception
14
+ raise @last_exception
15
+ end
16
+ end
17
+
18
+ if Markaby::Rails.deprecated_rails_version?
19
+ class ActionController::TestCase < Test::Unit::TestCase; end
20
+
21
+ class TestController < NonSpecificTestController
22
+ self.template_root = VIEW_PATH
23
+ end
24
+ else
25
+ class TestController < NonSpecificTestController
26
+ append_view_path(VIEW_PATH)
27
+ end
28
+ end
29
+
30
+ class MarkabyController < TestController
31
+ def renders_nothing
32
+ render :text => ""
33
+ end
34
+
35
+ def renders_erb_with_explicit_template
36
+ render :template => "markaby/renders_erb"
37
+ end
38
+
39
+ def render_inline_content
40
+ mab_content = mab do
41
+ ul do
42
+ li "Scott"
43
+ end
44
+ end
45
+
46
+ render :inline => mab_content
47
+ end
48
+
49
+ def render_explicit_but_empty_markaby_layout
50
+ render :template => "markaby/render_explicit_but_empty_markaby_layout.mab"
51
+ end
52
+
53
+ def no_values_passed
54
+ render :template => "markaby/no_values_passed"
55
+ end
56
+
57
+ def correct_template_values
58
+ render :template => "markaby/correct_template_values"
59
+ end
60
+
61
+ def render_erb_without_explicit_render_call
62
+ end
63
+
64
+ def render_mab_without_explicit_render_call
65
+ end
66
+
67
+ def render_with_ivar
68
+ @user = "smtlaissezfaire"
69
+ render :template => "markaby/render_with_ivar"
70
+ end
71
+
72
+ def access_to_helpers
73
+ render :template => "markaby/access_to_helpers"
74
+ end
75
+
76
+ def renders_partial
77
+ render :template => "markaby/partial_parent"
78
+ end
79
+
80
+ def renders_partial_with_locals
81
+ render :template => "markaby/partial_parent_with_locals"
82
+ end
83
+
84
+ def render_which_raises_error
85
+ render :template => "markaby/broken"
86
+ end
87
+
88
+ def renders_form_for
89
+ @obj = Object.new
90
+ render :template => "markaby/form_for"
91
+ end
92
+
93
+ def render_form_for_with_fields
94
+ @obj = Object.new
95
+ def @obj.foo
96
+ "bar"
97
+ end
98
+
99
+ render :template => "markaby/form_for_with_fields"
100
+ end
101
+
102
+ def render_form_for_with_multiple_fields
103
+ @obj = Object.new
104
+
105
+ def @obj.foo
106
+ "bar"
107
+ end
108
+
109
+ def @obj.baz
110
+ "quxx"
111
+ end
112
+
113
+ render :template => "markaby/form_for_with_multiple_fields"
114
+ end
115
+ end
116
+
117
+ class MarkabyOnRailsTest < ActionController::TestCase
118
+ def setup
119
+ Markaby::Builder.restore_defaults!
120
+
121
+ @request = ActionController::TestRequest.new
122
+ @response = ActionController::TestResponse.new
123
+ @controller = MarkabyController.new
124
+ end
125
+
126
+ def test_renders_nothing
127
+ get :renders_nothing
128
+ assert_response :success
129
+ end
130
+
131
+ def test_renders_erb_with_explicit_template
132
+ get :renders_erb_with_explicit_template
133
+ assert_response :success
134
+ # TODO: - fix this test environment issue so that assert_template works
135
+ # correctly in these tests
136
+ # assert_template "renders_erb.erb"
137
+ end
138
+
139
+ def test_renders_explicit_but_empty_markaby_layout
140
+ get :render_explicit_but_empty_markaby_layout
141
+ assert_response :success
142
+
143
+ assert_equal "", @response.body
144
+ # TODO:
145
+ # assert_template "markaby/render_explicit_but_empty_markaby_layout"
146
+ end
147
+
148
+ def test_renders_inline_markaby_content
149
+ get :render_inline_content
150
+ assert_response :success
151
+ assert_equal "<ul><li>Scott</li></ul>", @response.body
152
+ end
153
+
154
+ def test_renders_mab_template_with_no_values_passed
155
+ get :no_values_passed
156
+ assert_response :success
157
+ assert_equal "<ul><li>Scott</li></ul>", @response.body
158
+ end
159
+
160
+ def test_renders_mab_template_with_correct_values
161
+ get :correct_template_values
162
+ assert_response :success
163
+
164
+ assert_equal "<ul><li>smt</li><li>joho</li><li>spox</li></ul>", @response.body
165
+ end
166
+
167
+ def test_renders_without_explicit_render_call
168
+ get :render_mab_without_explicit_render_call
169
+ assert_response :success
170
+
171
+ assert_equal @response.body, "<ul><li>smtlaissezfaire</li></ul>"
172
+ end
173
+
174
+ def test_renders_with_ivar
175
+ get :render_with_ivar
176
+ assert_response :success
177
+
178
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
179
+ end
180
+
181
+ def test_access_to_helpers
182
+ get :access_to_helpers
183
+ assert_response :success
184
+
185
+ assert_equal '<a href="/foo">bar</a>', @response.body
186
+ end
187
+
188
+ def test_renders_partial_from_template
189
+ get :renders_partial
190
+ assert_response :success
191
+
192
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
193
+ end
194
+
195
+ def test_renders_partial_with_locals
196
+ get :renders_partial_with_locals
197
+ assert_response :success
198
+
199
+ assert_equal "<ul><li>smtlaissezfaire</li></ul>", @response.body
200
+ end
201
+
202
+ def test_raises_error_when_template_raises_error
203
+ get :render_which_raises_error
204
+
205
+ assert_response :error
206
+
207
+ assert_equal ActionView::TemplateError, @controller.last_exception.class
208
+ assert %r(undefined local variable or method `supercalifragilisticexpialidocious' for #<Markaby::.*Builder.*) =~
209
+ @controller.last_exception.message.to_s
210
+ end
211
+
212
+ def test_renders_form_for_properly
213
+ get :renders_form_for
214
+
215
+ assert_response :success
216
+
217
+ assert %r(<form.*></form>) =~ @response.body
218
+ end
219
+
220
+ def test_renders_form_for_with_fields_for
221
+ get :render_form_for_with_fields
222
+
223
+ assert_response :success
224
+
225
+ assert_equal "<form action=\"/markaby/render_form_for_with_fields\" method=\"post\"><input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" /></form>",
226
+ @response.body
227
+ end
228
+
229
+ def test_renders_form_for_with_multiple_fields
230
+ get :render_form_for_with_multiple_fields
231
+
232
+ assert_response :success
233
+
234
+ expected_output = "<form action=\"/markaby/render_form_for_with_multiple_fields\" method=\"post\">"
235
+ expected_output << "<input id=\"foo_foo\" name=\"foo[foo]\" size=\"30\" type=\"text\" />"
236
+ expected_output << "<input id=\"foo_baz\" name=\"foo[baz]\" size=\"30\" type=\"text\" />"
237
+ expected_output << "</form>"
238
+
239
+ assert_equal expected_output,
240
+ @response.body
241
+ end
242
+ end
243
+
244
+ describe "rails version" do
245
+ it "should support the current rails version" do
246
+ Markaby::Rails::SUPPORTED_RAILS_VERSIONS.should include(::Rails::VERSION::STRING)
247
+ end
248
+ end
249
+ end